简体   繁体   中英

Sequentially consistent but not linearizable execution

I'm trying to understand the difference between linearizability and sequential consistency. More specifically, I would like to have an example of an execution which is sequentially consistent but not linearizable. My professor gave me the following example of such execution:

Alice and bob write checks to each other.
Alice’s Statement:
-10  Check Alice -> Bob
0  Check Bob -> Alice

Bob’s Statement
-10  Check Bob -> Alice
0  Check Alice -> Bob

Both overdraft.
It is sequential: each client sees a consistent order
It is not linearizable: no globally linear story 

But I didn't get it. Line

n Check A -> B

is supposed to be interpreted as "A writes a check to B and its account after the operation is n". I don't understand why the operation shouldn't be linearisable: both Alice and Bob end up with 0 in the end which is a consistent value, so maybe I didn't get the definition of 'linearisability' properly.

First off, what your professor gave you is not the history/execution explicitly, but the projection of the history on both of its threads.

A history H is linearizable if by leaving away pending invocations and/or adding responses to pending invocations (that you didn't leave away) you can get a history that is equivalent to a sequential history S that doesn't contradict any precedences implied by H.

In other words, the reason your example is not linearizable is because the operations (financial transactions) can't be assigned a single point in time. First money is deducted, and then later added, and this behaviour is observed by the threads/individual bank statements.

If the bank statements were

Alice’s Statement:
-10  Check Alice -> Bob
0  Check Bob -> Alice

Bob’s Statement
10  Check Alice -> Bob
0  Check Bob -> Alice

then we would have a history S as follows:

Alice: Send Bob 10
Alice: Send completed
Bob:   Send Alice 10
Bob:   Send completed

But in your example the history could be

Alice: Send Bob 10 (i.e. money is gone)
Bob:   Send Alice 10 (i.e. money is gone)
Bob:   Send completed (i.e. money arrived)
Alice: Send completed (i.e. money arrived)

(or any combination of lines 1/2 switched and 3/4 switched) and you can't reorder that sequentially (ie pairs of started/completed together) without changing the account balance observed by each thread in between.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM