Optimistic locking and accidental updates

Our optimistic locking strategy also solves another problem: That of accidentally creating or recreating rows when we think we're updating existing rows. By only allowing the update to happen if the version column matches what we expect it to, we also implicitly ensure that the row exists. For instance, let's see what happens if we try to modify a nonexistent row with a conditional update:

UPDATE "users" SET "location" = 'Denver, CO', "version" = NOW() WHERE "username" = 'ivan' IF "version" = ec0c1fb7-321f-11e4-8eeb-5f98e903bf02; 

Fortunately, the update is not applied, so we don't unwillingly create a new row for the ivan character:

Since there's no row to take a version value, Cassandra omits ...

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.