Uing CAS issues when key not exist yet, xmemcached

16 views
Skip to first unread message

alex....@cortica.com

unread,
Jan 2, 2013, 6:05:43 PM1/2/13
to xmemc...@googlegroups.com
Hi,
I use CAS to synchronize between number of agents which may write simultaneously different values to one key.
All works fine, except following case:
Two agents reads with gets(key). The key not exists yet, GetsResponse is null, so I define the initial cas(hash) as 0 for both agents,
but in this case both agents may write using cas(key, 0, newValue, cas) and one agent overwrites the record of another !!!

I'm working with strings and didn't find better solution, then in case of new key I'm writing empty string with set() and in the next operation
reading the cas-value of.
It looks rather stupid solution and there is no warranty, that when slow agent A detects that key not exist and planning to write empty string to,
any quick agent B will not write any value to this key, and as result the Agent A will overwrite the record of engine B with empty string.

May be somebody knows some way to enjoy from CAS mechanism with first records ( when the key not exist yet) , written to the same key from multiple agents?
Reply all
Reply to author
Forward
0 new messages