20. MVCC - Multiversion Concurrency
Control
● When a record is created (using INSERT), it has created_id as the current
transaction_id and deleted_id as nil.
● When a record is updated, a new row is created with created_id as the
current transaction_id and deleted_id as nil. The old row is updated with
deleted_id as the current transaction_id.
● When a record is deleted, deleted_id of the row is updated with current
transaction_id.
● When reading, we filter all versions of the row using 2 criterias:
○ row must have created_id <= current transaction id
○ row must have deleted_id > current transaction id or nil
30. Summary
Isolation Level Attributes
Read Uncommitted - Fast
- A lot of consistency issues
Read Committed - Good performance
- Non-repeatable read & Phantom read
Repeatable Read - Ok performance
- Phantom read
Serializable - Slow
- Almost no consistency issues
31. Why do I need to know?
- ACID applies for all storage system, not just databases
- Understand limitation and consistency attributes of the
tools help:
- Design better system: make good trade-off
- Design better test: Jepsen test
Many databases claim that they supports ACID, like Postgres, MySQL, MongoDB and others
However, do they always support it?
What is ACID, by the way?
We won’t talk about other attributes today, as we’ll focus only in “ISOLATED” attribute
Assume that the syntax is correct, the records are created with correct schema and all libraries are loaded
This query is in another thread, which run concurrently with the thread that run the first query
Depend on what?
Multithread or not
Isolation level of database
Go back to locking solution?
MVCC is Multiversion Concurrency Control
This happen in MySQL InnoDB
Postgres does this
MVCC is Multiversion Concurrency Control
This should be a range lock. MySQL InnoDB implements this. MyISAM uses table locks
Greater concurrency in most cases, but much worse throughput in worst case. Use together with MVCC. Postgres 9.5 or higher supports this.
Redis uses single thread to write, which eliminates all possibility of conflict with an extremely simple design. Redis cluster doesn’t guarantee any serializable because of this design