What is the difference between linearizability and serializability?

后端 未结 5 695
别跟我提以往
别跟我提以往 2021-01-29 19:26

What is the difference between linearizability and serializability (in the context of Java)? Can you please explain the difference between these with an example or provide a goo

5条回答
  •  深忆病人
    2021-01-29 19:46

    A good way to understand this is to look at this problem from a database standpoint. (I know you ask for a context of java, sorry)

    Assuming, you are a database. You accepts multiple transactions operating on the same object concurrently but you only have one single disk arm.

    When you received multiple transactions at the same time, you will have to re-order those operations within transactions in some way so you poor disk arm can handle them one-by-one.

    Serializable

    you have the ability re-arrange those transactions to make it looks like they happens sequentially (one by one). As you can imagine, it's not always possible if you accept arbitrary transactions (e.g. one bad transaction last 10 years). So naturally, you enforce some restrictions or conflict prevention mechanisms then you can say "I'm serializable! :)" .

    Linearizable

    Not only do you need to do what serialization needs you to do. You also take a good look at those transactions. And try very hard to re-arrange those transactions in a sequential fashion without breaking the semantic order of transactions. As you might have noticed, semantic order is the key. Basically, in order to claim that you are linearizable, you will have to assume/find a linearization point for every transactions and then order them according to the linearization point.

    Therefore, it's uncommon for a versatile RDMS database to say Hey I'm linearizable!. But, it's not uncommon if you are a Key-Value database.

    e.g. As a KV database, you can say "I am linearizable!" if you can ensure a read will always get the latest possible write. (assuming the moment of sending response for the read operation is the linearization point) This sounds trivial, but will be a major challenge if you are a distributed KV database. Also note that serializability doesn't require you to give the same guarantee.

提交回复
热议问题