Reputation: 11
I'm looking into the optimistic offline lock pattern. i.e., https://martinfowler.com/eaaCatalog/optimisticOfflineLock.html
I've seen many references suggesting that this pattern can be achieved without concurrency issues using an RDBMS that provides serializable isolation (or some suggest repeatable read is enough). No mention of requiring linearizability of transactions. For example, Postgres does not offer linearizability: Reference: https://martin.kleppmann.com/2015/05/11/please-stop-calling-databases-cp-or-ap.html
Moreover, databases with snapshot isolation/MVCC are intentionally non-linearizable, because enforcing linearizability would reduce the level of concurrency that the database can offer. For example, PostgreSQL’s SSI provides serializability but not linearizability, and Oracle provides neither. Just because a database is branded “ACID” doesn’t mean it meets the CAP theorem’s definition of consistency.
So my confusion is, isn't linearizability also required because an optimistic offline lock is basically a compare and swap/update?
Reference: https://en.wikipedia.org/wiki/Linearizability#Compare-and-swap
Since the compare-and-swap occurs (or appears to occur) instantaneously, if another process updates the location while we are in-progress, the compare-and-swap is guaranteed to fail.
References:
https://martinfowler.com/eaaCatalog/optimisticOfflineLock.html
https://aphyr.com/posts/313-strong-consistency-models#serializable-consistency
https://martin.kleppmann.com/2015/05/11/please-stop-calling-databases-cp-or-ap.html
https://en.wikipedia.org/wiki/Linearizability#Compare-and-swap
Upvotes: 1
Views: 224
Reputation: 4109
Linearizability is all about common "global" time that yields a total ordering of all the events ever happened within the database (in which case "events" are transactions, of course, and their reads & writes). So, it's all about how physical time flows in the real world, and it has to be common for all the participants (which we know does not hold in general due to specific and general relativity theories born in the theoretical physics in the past century).
So simple answer to your question: no, linearizability is not required and theoretically impossible in general: there is no notion of common global time that is perfectly accurate. If you'd like to find out more, read about Google Spanner and their True Time mechanism, it is a piece of outspokenly brilliant engineering.
What a typical CAS operation provides is known as "sequential consistency". Which explicitly denies global timing and says something "there exists at least one order of events such that the happens-before relation is preserved for every read & write in that order" and "happens-before" understood not by a physical moment when it actually happened, but rather logically - as its position (index) in the sequence (such that every i
th read must see the latest change done by some preceding j
th write, j < i
, otherwise the "happens before" is violated).
At least, that is how I understand the problem.
Upvotes: 1