valchkou / cassandra-driver-mapping

JPA addon for DataStax Java Driver for Cassandra
57 stars 24 forks source link

Optimistic Concurrency using versioning #53

Closed nitinpadalia closed 9 years ago

nitinpadalia commented 9 years ago

Hi, I was wondering how mapping driver is ensuring read operation of Version column is race issue fee?

-Nitin

valchkou commented 9 years ago

Sorry, I am not clear of your question. There is no race condition or blocking for version column on read. Version column is read the same way as any other columns. The only difference is on write: if what you write has ver different from what is in DB the write will not succeed. I hope this helps

nitinpadalia commented 9 years ago

I mean during write operation does't driver first need to read what's the current version in db to compare it with the version being written so that err could be thrown if the version being written is old? If we're reading for comparison before finally writing then how that read is concurrency issue free? On Mar 28, 2015 4:26 AM, "Eugene" notifications@github.com wrote:

Sorry, I am not clear of your question. There is no race condition or blocking on version column on read. Version column is read the same way as any other columns. The only difference is on write: if what you write has ver different from what is in DB the write will not succeed. I hope this helps

— Reply to this email directly or view it on GitHub https://github.com/valchkou/cassandra-driver-mapping/issues/53#issuecomment-87114392 .

valchkou commented 9 years ago

There is no read operation before write. please read this link to understand the concept http://www.datastax.com/documentation/cassandra/2.0/cassandra/dml/dml_ltwt_transaction_c.html

Mapper uses Lightweight transactions feature provided by Cassandra. Update statement contains IF condition to compare version (IF version=object.version) Cassandra guaranties that update happens only when condition is met.

Lightweight transactions comes with performance cost. This is Cassandra limitation but not my mapper or datastax driver.

nitinpadalia commented 9 years ago

Ok so it being ensured by LWT, got it thanks!