advanced database systems
play

ADVANCED DATABASE SYSTEMS Transaction Models & Concurrency - PowerPoint PPT Presentation

Lect ure # 02 ADVANCED DATABASE SYSTEMS Transaction Models & Concurrency Control @ Andy_Pavlo // 15- 721 // Spring 2019 CMU 15-721 (Spring 2019) 2 Background Transaction Models Concurrency Control Protocols Isolation Levels CMU


  1. CMU 15-721 (Spring 2019) 17 N ESTED TRAN SACTIO NS Txn #1 BEGIN Sub-Txn #1.1 WRITE(A) BEGIN BEGIN Sub-Txn #1.1.1 WRITE(B) BEGIN BEGIN WRITE(C) COMMIT WRITE(D) ROLLBACK COMMIT

  2. CMU 15-721 (Spring 2019) 17 N ESTED TRAN SACTIO NS Txn #1 BEGIN Sub-Txn #1.1 WRITE(A) BEGIN BEGIN Sub-Txn #1.1.1 X WRITE(B) BEGIN BEGIN X WRITE(C) COMMIT X WRITE(D) ROLLBACK COMMIT

  3. CMU 15-721 (Spring 2019) 17 N ESTED TRAN SACTIO NS Txn #1 BEGIN Sub-Txn #1.1 ✓ WRITE(A) BEGIN BEGIN Sub-Txn #1.1.1 X WRITE(B) BEGIN BEGIN X WRITE(C) COMMIT X WRITE(D) ROLLBACK COMMIT

  4. CMU 15-721 (Spring 2019) 18 TRAN SACTIO N CH AIN S Multiple txns executed one after another. Combined COMMIT / BEGIN operation is atomic. → No other txn can change the state of the database as seen by the second txn from the time that the first txn commits and the second txn begins. Differences with savepoints: → COMMIT allows the DBMS to free locks. → Cannot rollback previous txns in chain.

  5. CMU 15-721 (Spring 2019) 19 TRAN SACTIO N CH AIN S Txn #1 BEGIN WRITE(A) Txn #2 COMMIT BEGIN READ(A) WRITE(B) Txn #3 COMMIT BEGIN WRITE(C) ROLLBACK

  6. CMU 15-721 (Spring 2019) 19 TRAN SACTIO N CH AIN S Txn #1 BEGIN WRITE(A) Txn #2 COMMIT BEGIN READ(A) WRITE(B) Txn #3 COMMIT BEGIN A WRITE(C) ROLLBACK

  7. CMU 15-721 (Spring 2019) 19 TRAN SACTIO N CH AIN S Txn #1 BEGIN WRITE(A) Txn #2 COMMIT BEGIN READ(A) WRITE(B) Txn #3 COMMIT BEGIN A WRITE(C) ROLLBACK

  8. CMU 15-721 (Spring 2019) 19 TRAN SACTIO N CH AIN S Txn #1 BEGIN WRITE(A) Txn #2 COMMIT BEGIN READ(A) WRITE(B) Txn #3 COMMIT BEGIN A B WRITE(C) ROLLBACK

  9. CMU 15-721 (Spring 2019) 19 TRAN SACTIO N CH AIN S Txn #1 BEGIN WRITE(A) Txn #2 COMMIT BEGIN READ(A) WRITE(B) Txn #3 COMMIT BEGIN A B WRITE(C) ROLLBACK

  10. CMU 15-721 (Spring 2019) 19 TRAN SACTIO N CH AIN S Txn #1 BEGIN WRITE(A) Txn #2 COMMIT BEGIN READ(A) WRITE(B) Txn #3 ✓ ✓ COMMIT X BEGIN A B C WRITE(C) ROLLBACK

  11. CMU 15-721 (Spring 2019) 20 BULK UPDATE PRO BLEM These other txn models are nice, but they still do not solve our bulk update problem. Chained txns seems like the right idea but they require the application to handle failures and maintain its own state. → Has to be able to reverse changes when things fail.

  12. CMU 15-721 (Spring 2019) 21 CO M PEN SATIN G TRAN SACTIO N S A special type of txn that is designed to semantically reverse the effects of another already committed txn. Reversal has to be logical instead of physical. → Example: Decrement a counter by one instead of reverting to the original value.

  13. CMU 15-721 (Spring 2019) 22 SAGA TRAN SACTIO N S A sequence of chained txns T 1 – T n and compensating txns C 1 – C n-1 where one of the following is guaranteed: → The txns will commit in the order T 1 … T j ,C j …C 1 (where j < n) This allows the DBMS to support long-running, multi-step txns without application-managed logic SAGAS SIGMOD 1987

  14. CMU 15-721 (Spring 2019) 23 SAGA TRAN SACTIO N S Txn #1 Txn #2 Txn #3 BEGIN BEGIN BEGIN WRITE(A+1) WRITE(B+1) WRITE(C+1) COMMIT COMMIT

  15. CMU 15-721 (Spring 2019) 23 SAGA TRAN SACTIO N S Txn #1 Txn #2 Txn #3 BEGIN BEGIN BEGIN WRITE(A+1) WRITE(B+1) WRITE(C+1) COMMIT COMMIT

  16. CMU 15-721 (Spring 2019) 23 SAGA TRAN SACTIO N S Txn #1 Txn #2 Txn #3 BEGIN BEGIN BEGIN WRITE(A+1) WRITE(B+1) WRITE(C+1) COMMIT COMMIT Comp Txn #2 BEGIN WRITE(B-1) COMMIT

  17. CMU 15-721 (Spring 2019) 23 SAGA TRAN SACTIO N S Txn #1 Txn #2 Txn #3 BEGIN BEGIN BEGIN WRITE(A+1) WRITE(B+1) WRITE(C+1) COMMIT COMMIT Comp Txn #1 Comp Txn #2 BEGIN BEGIN WRITE(A-1) WRITE(B-1) COMMIT COMMIT

  18. CMU 15-721 (Spring 2019) 24 CO N CURREN CY CO N TRO L The protocol to allow txns to access a database in a multi-programmed fashion while preserving the illusion that each of them is executing alone on a dedicated system. → The goal is to have the effect of a group of txns on the database’s state is equivalent to any serial execution of all txns. Provides A tomicity + I solation in ACID

  19. CMU 15-721 (Spring 2019) 25 TXN IN TERN AL STATE Status → The current execution state of the txn. Undo Log Entries → Stored in an in-memory data structure. → Dropped on commit. Redo Log Entries → Append to the in-memory tail of WAL. → Flushed to disk on commit. Read/Write Set → Depends on the concurrency control scheme.

  20. CMU 15-721 (Spring 2019) 26 CO N CURREN CY CO N TRO L SCH EM ES Two-Phase Locking (2PL) → Assume txns will conflict so they must acquire locks on database objects before they are allowed to access them. Timestamp Ordering (T/O) → Assume that conflicts are rare so txns do not need to first acquire locks on database objects and instead check for conflicts at commit time.

  21. CMU 15-721 (Spring 2019) 27 TWO - PH ASE LO CKIN G Txn #1 COMMIT BEGIN LOCK(A ) LOCK(A) READ(A) LOCK(B) LOCK(B) WRITE(B) UNLOCK(A) UNLOCK(B) Growing Phase Shrinking Phase

  22. CMU 15-721 (Spring 2019) 27 TWO - PH ASE LO CKIN G Txn #1 COMMIT BEGIN LOCK(A ) LOCK(A) READ(A) LOCK(B) LOCK(B) WRITE(B) UNLOCK(A) UNLOCK(B) Txn #2 COMMIT BEGIN LOCK(B) WRITE(B) LOCK(A) WRITE(A) UNLOCK(A) UNLOCK(B)

  23. CMU 15-721 (Spring 2019) 27 TWO - PH ASE LO CKIN G Txn #1 COMMIT BEGIN LOCK(A ) LOCK(A) READ(A) LOCK(B) LOCK(B) WRITE(B) UNLOCK(A) UNLOCK(B) Txn #2 COMMIT BEGIN LOCK(B) WRITE(B) LOCK(A) WRITE(A) UNLOCK(A) UNLOCK(B)

  24. CMU 15-721 (Spring 2019) 27 TWO - PH ASE LO CKIN G Txn #1 COMMIT BEGIN LOCK(A ) LOCK(A) READ(A) LOCK(B) LOCK(B) WRITE(B) UNLOCK(A) UNLOCK(B) Txn #2 COMMIT BEGIN LOCK(B) WRITE(B) LOCK(A) WRITE(A) UNLOCK(A) UNLOCK(B)

  25. CMU 15-721 (Spring 2019) 27 TWO - PH ASE LO CKIN G Txn #1 COMMIT BEGIN LOCK(A ) LOCK(A) READ(A) LOCK(B) LOCK(B) WRITE(B) UNLOCK(A) UNLOCK(B) Txn #2 COMMIT BEGIN LOCK(B) WRITE(B) LOCK(A) WRITE(A) UNLOCK(A) UNLOCK(B)

  26. CMU 15-721 (Spring 2019) 27 TWO - PH ASE LO CKIN G Txn #1 COMMIT BEGIN LOCK(A ) LOCK(A) READ(A) LOCK(B) LOCK(B) WRITE(B) UNLOCK(A) UNLOCK(B) Txn #2 COMMIT BEGIN LOCK(B) WRITE(B) LOCK(A) WRITE(A) UNLOCK(A) UNLOCK(B)

  27. CMU 15-721 (Spring 2019) 27 TWO - PH ASE LO CKIN G Txn #1 COMMIT BEGIN LOCK(A ) LOCK(A) READ(A) LOCK(B) LOCK(B) WRITE(B) UNLOCK(A) UNLOCK(B) Txn #2 COMMIT BEGIN LOCK(B) WRITE(B) LOCK(A) WRITE(A) UNLOCK(A) UNLOCK(B)

  28. CMU 15-721 (Spring 2019) 28 TWO - PH ASE LO CKIN G Deadlock Detection → Each txn maintains a queue of the txns that hold the locks that it waiting for. → A separate thread checks these queues for deadlocks. → If deadlock found, use a heuristic to decide what txn to kill in order to break deadlock. Deadlock Prevention → Check whether another txn already holds a lock when another txn requests it. → If lock is not available, the txn will either (1) wait, (2) commit suicide, or (3) kill the other txn.

  29. CMU 15-721 (Spring 2019) 29 TIM ESTAM P O RDERIN G Basic T/O → Check for conflicts on each read/write. → Copy tuples on each access to ensure repeatable reads. Optimistic Currency Control (OCC) → Store all changes in private workspace. → Check for conflicts at commit time and then merge.

  30. CMU 15-721 (Spring 2019) 30 BASIC T/ O Txn #1 COMMIT BEGIN READ(A) WRITE(B) WRITE(A)

  31. CMU 15-721 (Spring 2019) 30 BASIC T/ O 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(B) WRITE(A)

  32. CMU 15-721 (Spring 2019) 30 BASIC T/ O 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10000 10000 B 10000 10000

  33. CMU 15-721 (Spring 2019) 30 BASIC T/ O 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10000 10000 B 10000 10000

  34. CMU 15-721 (Spring 2019) 30 BASIC T/ O 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10001 10000 B 10000 10000

  35. CMU 15-721 (Spring 2019) 30 BASIC T/ O 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10001 10000 B 10000 10000

  36. CMU 15-721 (Spring 2019) 30 BASIC T/ O 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10001 10000 B 10000 10001

  37. CMU 15-721 (Spring 2019) 30 BASIC T/ O 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10001 10005 B 10000 10001

  38. CMU 15-721 (Spring 2019) 30 BASIC T/ O 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10001 10005 B 10000 10001

  39. CMU 15-721 (Spring 2019) 31 O PTIM ISTIC CO N CURREN CY CO N TRO L Timestamp-ordering scheme where txns copy data read/write into a private workspace that is not visible to other active txns. When a txn commits, the DBMS verifies that there are no conflicts. First proposed in 1981 at CMU by H.T. Kung. ON OPTIMISTIC METHODS FOR CONCURRENCY C CONTROL ACM T TRANSACTIONS ON DATABASE S SYSTEMS 1981

  40. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Write Record Value Timestamp A 123 10000 B 456 10000

  41. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Read Phase Write Record Value Timestamp A 123 10000 B 456 10000

  42. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Write Record Value Timestamp A 123 10000 B 456 10000

  43. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Workspace Write Write Record Value Record Value Timestamp Timestamp A 123 10000 A 123 10000 B 456 10000

  44. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Workspace Write Write Record Value Record Value Timestamp Timestamp A 123 10000 A 123 10000 B 456 10000

  45. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Workspace Write Write Record Value Record Value Timestamp Timestamp ∞ A 123 888 10000 A 123 10000 B 456 10000

  46. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Workspace Write Write Record Value Record Value Timestamp Timestamp ∞ A 888 123 10000 A 123 10000 B 456 10000 B 456 10000

  47. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Workspace Write Write Record Value Record Value Timestamp Timestamp ∞ A 123 888 10000 A 123 10000 ∞ 999 B 456 10000 B 456 10000

  48. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) VALIDATE PHASE WRITE PHASE Workspace Write Write Record Value Record Value Timestamp Timestamp ∞ A 888 123 10000 A 123 10000 ∞ 999 B 456 10000 B 456 10000

  49. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) VALIDATE PHASE WRITE PHASE Workspace Write Write Record Value Record Value Timestamp Timestamp ∞ A 888 123 10000 A 123 10000 ∞ 999 B 456 10000 B 456 10000

  50. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) VALIDATE PHASE WRITE PHASE Workspace Write Write Record Value Record Value Timestamp Timestamp ∞ A 888 123 10000 A 123 10000 ∞ 999 B 456 10000 B 456 10000

  51. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) VALIDATE PHASE WRITE PHASE Workspace Write Write Record Value Record Value Timestamp Timestamp ∞ A 888 123 10000 A 123 888 10000 10001 ∞ 999 999 10001 B 456 10000 B 456 10000

  52. CMU 15-721 (Spring 2019) 32 O PTIM ISTIC CO N CURREN CY CO N TRO L 10001 Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) VALIDATE PHASE WRITE PHASE Write Record Value Timestamp A 123 888 10000 10001 999 10001 B 456 10000

  53. CMU 15-721 (Spring 2019) 33 O BSERVATIO N When there is low contention, optimistic protocols perform better because the DBMS spends less time checking for conflicts. At high contention, the both classes of protocols degenerate to essentially the same serial execution.

  54. CMU 15-721 (Spring 2019) 34 CO N CURREN CY CO N TRO L EVALUATIO N Compare in-memory concurrency control protocols at high levels of parallelism. → Single test-bed system. → Evaluate protocols using core counts beyond what is available on today's CPUs. Running in extreme environments exposes what are the main bottlenecks in the DBMS. STARING INTO THE ABYSS: AN EVALUATION OF CONCURRENCY CONTROL W WITH ONE THOUSAND CORES VLDB 2014

  55. CMU 15-721 (Spring 2019) 35 10 0 0 - CO RE CPU SIM ULATO R DBx1000 Database System → In-memory DBMS with pluggable lock manager. → No network access, logging, or concurrent indexes MIT Graphite CPU Simulator → Single-socket, tile-based CPU. → Shared L2 cache for groups of cores. → Tiles communicate over 2D-mesh network.

  56. CMU 15-721 (Spring 2019) 36 TARGET WO RKLOAD Yahoo! Cloud Serving Benchmark (YCSB) → 20 million tuples → Each tuple is 1KB (total database is ~20GB) Each transactions reads/modifies 16 tuples. Varying skew in transaction access patterns. Serializable isolation level.

Recommend


More recommend