Optimistic lock, when do transaction, read the version I’d and timestamp. Dismiss when version is or timestamp changed. Good for a lot of read scenario
Pessimistic lock, when do transaction, lock the record
3 types of read anomaly:
Dirty read
Non repeatable read
Phantom read
4 Isolation levels
Uncommitted read
read an uncommitted data. After read the, data change is committed. There might be dirty read.
Committed read
Make sure the data to read is committed. But when read the data 2nd time, might be different
Non-repeatable read
In same transaction, when reading a record for several times. Need to make sure it reads same value.
Snapshot isolation(MVCC)
It is same as repeatable read. It solves non repeatable read problem. Can do read, write at same time, no need lock. Compared with lock way.
Serializable
Pingback: Linearizability vs Serializability | allenlipeng47()