Java client key existence

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Java client key existence

Ukyo Virgden
Hi, 

Just installed riak and trying to get adjusted. Having looked at the java client, I could not tell if there' a way to check key exixtence. What I need to do is to check if a key exists and put it if it doesn't.  In HTTP request from curl, a HEAD request instead of a GET gives the result I need. 

How can I check the existence of a key from java client without making a full fetch?

Thanks.

_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Java client key existence

Parnell Springmeyer
The client might not support that, I don't know. I know the Python client (at least the version I'm using) also does a full GET of the object.

Here's the kicker though, I'm using LevelDB for the backend and LevelDB is notorious for having poor read performance when you're trying to GET a key that doesn't exist (checking for existence). So, don't do it if you're using LevelDB.

Bitcask is another story though, since all the keys are in memory so that lookup is constant time (I believe, unless your key space is going into swap, but that shouldn't happen).

On Jul 28, 2012, at 11:44 AM, Ukyo Virgden wrote:

> Hi,
>
> Just installed riak and trying to get adjusted. Having looked at the java client, I could not tell if there' a way to check key exixtence. What I need to do is to check if a key exists and put it if it doesn't.  In HTTP request from curl, a HEAD request instead of a GET gives the result I need.
>
> How can I check the existence of a key from java client without making a full fetch?
>
> Thanks.
> _______________________________________________
> riak-users mailing list
> [hidden email]
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Java client key existence

Mark Phillips-4


Mark


On Jul 28, 2012, at 10:55, Parnell Springmeyer <[hidden email]> wrote:

> The client might not support that, I don't know. I know the Python client (at least the version I'm using) also does a full GET of the object.
>
> Here's the kicker though, I'm using LevelDB for the backend and LevelDB is notorious for having poor read performance when you're trying to GET a key that doesn't exist (checking for existence). So, don't do it if you're using LevelDB.
>

It's worth noting that the version of LevelDB in 1.2 (which will be official Very Soon Now) will have much more efficient not-found look ups thanks to the addition of bloom filters [1].

I don't have the actual performance data handy but we should be posting some info on that other improvements on the blog before too long.

Don't give up on Level just yet :)

Mark

[1] https://github.com/basho/riak/blob/1.2/RELEASE-NOTES.md


> Bitcask is another story though, since all the keys are in memory so that lookup is constant time (I believe, unless your key space is going into swap, but that shouldn't happen).
>
> On Jul 28, 2012, at 11:44 AM, Ukyo Virgden wrote:
>
>> Hi,
>>
>> Just installed riak and trying to get adjusted. Having looked at the java client, I could not tell if there' a way to check key exixtence. What I need to do is to check if a key exists and put it if it doesn't.  In HTTP request from curl, a HEAD request instead of a GET gives the result I need.
>>
>> How can I check the existence of a key from java client without making a full fetch?
>>
>> Thanks.
>> _______________________________________________
>> riak-users mailing list
>> [hidden email]
>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>
> _______________________________________________
> riak-users mailing list
> [hidden email]
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Reply | Threaded
Open this post in threaded view
|

Re: Java client key existence

Brian Roach-2
In reply to this post by Ukyo Virgden
Hi Ukyo,

The Java client is … sort of complicated at the moment :) It's got a high level interface (IRiakClient) built on a "translation" level interface (RawClient) that then has the two separate, original clients under it (HTTP and Protocol buffers).

At the highest level (IRiakClient)  … there isn't support for it. I suspect the reason for this is because Protocol Buffers doesn't support it, therefore we didn't want people to get unexpected results.

At the RawClient level, however, it is supported and if you're using HTTP it will only do a HEAD and return the metadata (the headers) … unless there are siblings. If there are siblings (HEAD returns a 300 response) the client will then do a full fetch and return them.

You can use the RawClient interface directly by instantiating and using a HTTPClientAdapter[1] rather than getting an IRiakClient instance from the RiakFactory. If you absolutely want this functionality that's the way to go.

Thanks,
Brian Roach

[1] http://basho.github.com/riak-java-client/1.0.5/com/basho/riak/client/raw/http/HTTPClientAdapter.html


On Jul 28, 2012, at 10:44 AM, Ukyo Virgden wrote:

> Hi,
>
> Just installed riak and trying to get adjusted. Having looked at the java client, I could not tell if there' a way to check key exixtence. What I need to do is to check if a key exists and put it if it doesn't.  In HTTP request from curl, a HEAD request instead of a GET gives the result I need.
>
> How can I check the existence of a key from java client without making a full fetch?
>
> Thanks.
> _______________________________________________
> riak-users mailing list
> [hidden email]
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


_______________________________________________
riak-users mailing list
[hidden email]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com