Optimistic locking in action

Now it's time to implement actual optimistic locking. When we initially display the profile to the two happycorp employees for editing, we'll keep track of the version that we displayed. Then, when the first employee goes to save their update, we'll perform a conditional update to make sure that we're updating the same version that the user thinks we are:

UPDATE "users" SET "location" = 'New York, NY', "version" = NOW() WHERE "username" = 'happycorp' IF "version" = ec0c1fb7-321f-11e4-8eeb-5f98e903bf02; 

The IF clause at the end of the query makes this a conditional update, another type of lightweight transaction. You'll notice that, just like conditional inserts, conditional updates give us feedback on whether ...

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.