Successfully reported this slideshow.
Your SlideShare is downloading. ×

Database isolation levels

Ad

Database Isolation
Levels
Hieu Nguyen

Ad

ACID

Ad

ACID

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Upcoming SlideShare
Introduction to fuzzing
Introduction to fuzzing
Loading in …3
×

Check these out next

1 of 32 Ad
1 of 32 Ad

More Related Content

Database isolation levels

  1. 1. Database Isolation Levels Hieu Nguyen
  2. 2. ACID
  3. 3. ACID
  4. 4. ACID - ATOMIC
  5. 5. ACID - ATOMIC - CONSISTENT
  6. 6. ACID - ATOMIC - CONSISTENT - ISOLATED
  7. 7. ACID - ATOMIC - CONSISTENT - ISOLATED - DURABLE
  8. 8. ACID - ATOMIC - CONSISTENT - ISOLATED - DURABLE
  9. 9. IS THE BELOW CODE CORRECT?
  10. 10. ANOTHER QUERY
  11. 11. IT DEPENDS!!!
  12. 12. Dirty read
  13. 13. Prevent dirty read with lock
  14. 14. Prevent dirty read with committed/uncommitted flag
  15. 15. Prevent dirty read with committed/uncommitted flag READ COMMITTED LEVEL!!!
  16. 16. Non-repeatable read
  17. 17. MVCC to prevent non-repeatable read
  18. 18. 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
  19. 19. Lost update?
  20. 20. Raise error about inconsistency?
  21. 21. MVCC to prevent non-repeatable read REPEATABLE READ !!!
  22. 22. Phantom read
  23. 23. Pessimistic Locking SERIALIZABLE
  24. 24. Optimistic Locking SERIALIZABLE
  25. 25. Other solutions?
  26. 26. Other solutions?
  27. 27. 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
  28. 28. 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
  29. 29. THANK YOU FOR LISTENING

Editor's Notes

  • 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

×