On Dec 16, 2009, at 22:31, gabriele renzi wrote: > On Wed, Dec 16, 2009 at 12:34 AM, Brandon Williams <dri...@gmail.com> wrote: >> On Tue, Dec 15, 2009 at 5:19 PM, Brian Burruss <bburr...@real.com> wrote: >>> >>> can the cassandra client (java specifically) specify that a particular >>> "put" should be "create only, do not update"? If the value already exists >>> in the database, i want the put to fail. for instance, two users want the >>> exact same username, so they both do a "get" to determine if the username >>> already exists, it doesn't, so they create. the last one to create wins, >>> correct? >> >> Correct. You would need to implement a locking mechanism such as Zookeeper >> in your application to get around this. > > sorry for my usual stupid question, but I'm still trying to wrap my > head around cassandra... > is there a fundamental reason for not being able to provide a > putIfAbsent-like abstraction in cassandra? > > If I understand correctly this can't be done in the case of network > partitioning but it could work while the network is not split with an > operation requiring ConsistencyLevel.ALL. But this seems like it would > be still the case with any other system. > So, for unique login ids in the case of partition there would be a > temporary impossibility to register but in the (normal?) non > partitioned case Brian would still be able to let users register via > cassandra.
Using decrementing timestamps you could get "first insert wins" behavior. Then you'd have to check after insert if it really wrote any data using ConsistencyLevel.ALL. This is a really bad use case for Cassandra and you really should use some external locking mechanism. -Ville