[infinispan-dev] HotRod?? [ISPN-29 and a "custom protocol"]

Alex Kluge java_kluge at yahoo.com
Thu Dec 10 14:19:40 EST 2009


>>> Yeah, u can get the cas id via gets command.
>>>
>>>>
>>>>> In the txt protocol, I implemented the cas id using System.nanoTime().
>>>>
>>>> Is this cas id meant to be unique?  If so, System.nanoTime() may not be ...
>>>
>>> Not over time. You want to be unique from the minute you retrieved it
>>> until you use it and for operations on that particular key.
>>>
>>> The cas Id is simply used for comparison, to check whether someone else
>>> has changed the entry since you retrieved it. System.nanoTime() gives
>>> you precisely that, anyone that modifies that entry in that machine will
>>> definitely have a different nano time. Also, since nano time is based
>>> off an arbitrary time, the chances that a different machine will produce
>>> the same nano time when modifying that very same key are almost very
>>> very small.
>>
>> Improbable but certainly not impossible, even in 1 machine.
>>
>> Why not just use what we use for 'versioning' internally - object references?  System.identityHashCode(), for example?
>
> Remember that you have to deal with eviction/expiration too. You could
> get a case like this:
> - get a cas based on identity hash code
> - the entry is expired
> - a new entry is put, with diff values, which happens to have the same
> identify hash code.
> - doing a cas will succeed when it shouldn't.
>
> I don't think this can happen with System.nanoTime().
>
> When looking into this, I checked java.util.UUID but it didn't work, for
> at least for the memcached txt protocol, where a 64bit value is required
> and UUID is 128bits. Maybe we could try to compress it somehow?

> Actually, according to the memcached-txt protocol definition, this is a
> 64-bit integer, so no real chance of compacting that. You need to
> provide a long of some sort:
>
> http://github.com/memcached/memcached/blob/master/doc/protocol.txt

 Is there any expected use of this value where it will be used outside of
the context of a specific key? If not, then it does not have to be
globally unique, and indeed, can simply be a modification count.
Easily computed, and easily fit within 64 bits even over a long lifetime
of a server.

 For now though the real question is can we fit a quantity that will
fulfil the requirements for the field into the space alloted. I think
we can.


                                       Alex




      



More information about the infinispan-dev mailing list