database system implementation
play

DATABASE SYSTEM IMPLEMENTATION GT 4420/6422 // SPRING 2019 // - PowerPoint PPT Presentation

DATABASE SYSTEM IMPLEMENTATION GT 4420/6422 // SPRING 2019 // @JOY_ARULRAJ LECTURE #18: OPTIMISTIC CONCURRENCY CONTROL LOGISTICS Reminder: Project Updates due on next Tuesday (Apr 2). Grading Scheme: No Final Exam. 50% Project 30%


  1. 51 TIMESTAMP ORDERING 10001 Txn #1 COMMIT BEGIN • • • • • • • READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10001 10000 B 10000 10001

  2. 52 TIMESTAMP ORDERING 10001 Txn #1 COMMIT BEGIN • • • • • • • READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10001 10005 B 10000 10001

  3. 53 TIMESTAMP ORDERING 10001 Txn #1 COMMIT BEGIN • • • • • • • READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10001 10005 B 10000 10001

  4. 54 TIMESTAMP ORDERING 10001 Txn #1 COMMIT BEGIN • • • • • • • READ(A) WRITE(B) WRITE(A) Read Write Record Timestamp Timestamp A 10001 10005 B 10000 10001

  5. 55 TIMESTAMP ORDERING 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.

  6. 56 OPTIMISTIC CONCURRENCY CONTROL 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 CONTROL ACM Transactions on Database Systems 1981

  7. 57 OPTIMISTIC CONCURRENCY CONTROL Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B)

  8. 58 OPTIMISTIC CONCURRENCY CONTROL Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Write Record Value Timestamp A 123 10000 B 456 10000

  9. 59 OPTIMISTIC CONCURRENCY CONTROL Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Write Record Value Timestamp A 123 10000 B 456 10000

  10. 60 OPTIMISTIC CONCURRENCY CONTROL Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Read Phase Write Record Value Timestamp A 123 10000 B 456 10000

  11. 61 OPTIMISTIC CONCURRENCY CONTROL Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Write Record Value Timestamp A 123 10000 B 456 10000

  12. 62 OPTIMISTIC CONCURRENCY CONTROL Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Write Record Value Timestamp A 123 10000 B 456 10000

  13. 63 OPTIMISTIC CONCURRENCY CONTROL Txn #1 COMMIT BEGIN READ(A) WRITE(A) WRITE(B) Workspace Write Write Record Value Record Value Timestamp Timestamp A 123 10000 B 456 10000

  14. 64 OPTIMISTIC CONCURRENCY CONTROL 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

  15. 65 OPTIMISTIC CONCURRENCY CONTROL 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

  16. 66 OPTIMISTIC CONCURRENCY CONTROL 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

  17. 67 OPTIMISTIC CONCURRENCY CONTROL 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

  18. 68 OPTIMISTIC CONCURRENCY CONTROL 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

  19. 69 OPTIMISTIC CONCURRENCY CONTROL 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

  20. 70 OPTIMISTIC CONCURRENCY CONTROL 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 999 10000 B 456 10000

  21. 71 OPTIMISTIC CONCURRENCY CONTROL 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 999 10000 B 456 10000

  22. 72 OPTIMISTIC CONCURRENCY CONTROL 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 ∞ B 456 999 10000 B 456 10000

  23. 73 OPTIMISTIC CONCURRENCY CONTROL 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 ∞ B 456 999 10000 B 456 10000

  24. 74 OPTIMISTIC CONCURRENCY CONTROL 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 ∞ B 456 999 10000 B 456 10000

  25. 75 OPTIMISTIC CONCURRENCY CONTROL 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 ∞ B 456 999 10000 B 456 10000

  26. 76 OPTIMISTIC CONCURRENCY CONTROL 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 10001 B 456 999 10000 B 456 10000

  27. 77 OPTIMISTIC CONCURRENCY CONTROL 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

  28. 78 READ PHASE Track the read/write sets of txns and store their writes in a private workspace. The DBMS copies every tuple that the txn accesses from the shared database to its workspace ensure repeatable reads.

  29. 79 VALIDATION PHASE When the txn invokes COMMIT , the DBMS checks if it conflicts with other txns. Two methods for this phase: → Backward Validation → Forward Validation

  30. 80 BACKWARD VALIDATION Check whether the committing txn intersects its read/write sets with those of any txns that have already committed. Txn #1 COMMIT Txn #2 COMMIT Txn #3 COMMIT TIME

  31. 81 BACKWARD VALIDATION Check whether the committing txn intersects its read/write sets with those of any txns that have already committed. Txn #1 COMMIT Txn #2 COMMIT Txn #3 COMMIT TIME

  32. 82 BACKWARD VALIDATION Check whether the committing txn intersects its read/write sets with those of any txns that have already committed. Txn #1 COMMIT Txn #2 COMMIT Txn #3 COMMIT TIME

  33. 83 BACKWARD VALIDATION Check whether the committing txn intersects its read/write sets with those of any txns that have already committed. Txn #1 COMMIT Txn #2 COMMIT Txn #3 COMMIT TIME

  34. 84 BACKWARD VALIDATION Check whether the committing txn intersects its read/write sets with those of any txns that have already committed. Validation Scope Txn #1 COMMIT Txn #2 COMMIT Txn #3 COMMIT TIME

  35. 85 FORWARD VALIDATION Check whether the committing txn intersects its read/write sets with any active txns that have not yet committed. Txn #1 COMMIT Txn #2 COMMIT Txn #3 COMMIT TIME

  36. 86 FORWARD VALIDATION Check whether the committing txn intersects its read/write sets with any active txns that have not yet committed. Txn #1 COMMIT Txn #2 COMMIT Txn #3 COMMIT TIME

  37. 87 FORWARD VALIDATION Check whether the committing txn intersects its read/write sets with any active txns that have not yet committed. Txn #1 COMMIT Validation Scope Txn #2 COMMIT Txn #3 COMMIT TIME

  38. 88 VALIDATION PHASE Original OCC uses serial validation. Parallel validation means that each txn must check the read/write sets of other txns that are trying to validate at the same time. → Each txn has to acquire locks for its write set records in some global order . → The txn does not need locks for read set records.

  39. 89 WRITE PHASE The DBMS propagates the changes in the txn’s write set to the database and makes them visible to other txns. As each record is updated, the txn releases the lock acquired during the Validation Phase.

  40. 90 TIMESTAMP ALLOCATION Mutex → Worst option. Mutexes are the "Hitler of Concurrency". Atomic Addition → Requires cache invalidation on write. Batched Atomic Addition → Needs a back-off mechanism to prevent fast burn. Hardware Clock → Not sure if it will exist in future CPUs. Hardware Counter → Not implemented in existing CPUs.

  41. 91 TIMESTAMP ALLOCATION STARING INTO THE ABYSS: AN EVALUATION OF CONCURRENCY CONTROL WITH ONE THOUSAND CORES VLDB 2014

  42. 92 MODERN OCC Harvard/MIT Silo MIT/CMU TicToc

  43. 93 SILO Single-node, in-memory OLTP DBMS. → Serializable OCC with parallel backward validation. → Stored procedure-only API. No writes to shared-memory for read txns. Batched timestamp allocation using epochs . Pure awesomeness from Eddie Kohler. SPEEDY TRANSACTIONS IN MULTICORE IN-MEMORY DATABASES SOSP 2013

  44. 94 SILO Single-node, in-memory OLTP DBMS. → Serializable OCC with parallel backward validation. → Stored procedure-only API. No writes to shared-memory for read txns. Batched timestamp allocation using epochs . Pure awesomeness from Eddie Kohler. SPEEDY TRANSACTIONS IN MULTICORE IN-MEMORY DATABASES SOSP 2013

  45. 95 SILO Single-node, in-memory OLTP DBMS. → Serializable OCC with parallel backward validation. → Stored procedure-only API. No writes to shared-memory for read txns. Batched timestamp allocation using epochs . Pure awesomeness from Eddie Kohler. SPEEDY TRANSACTIONS IN MULTICORE IN-MEMORY DATABASES SOSP 2013

  46. 96 SILO: EPOCHS Time is sliced into fixed-length epochs (40ms). All txns that start in the same epoch will be committed together at the end of the epoch. → Txns that span an epoch have to refresh themselves to be carried over into the next epoch. Worker threads only need to synchronize at the beginning of each epoch.

  47. 97 SILO: TRANSACTION IDS Each worker thread generates a unique txn id based on the current epoch number and the next value in its assigned batch. Worker Worker Epoch Thread Worker Worker

  48. 98 SILO: TRANSACTION IDS Each worker thread generates a unique txn id based on the current epoch number and the next value in its assigned batch. Epoch=100 Worker Worker Epoch Thread Worker Worker

  49. 99 SILO: TRANSACTION IDS Each worker thread generates a unique txn id based on the current epoch number and the next value in its assigned batch. [0,10] [21,30] Epoch=100 Worker Worker Epoch Thread Worker Worker [11,20] [31,40]

  50. 100 SILO: TRANSACTION IDS Each worker thread generates a unique txn id based on the current epoch number and the next value in its assigned batch. [0,10] [21,30] Epoch=200 Worker Worker Epoch Thread Worker Worker [11,20] [31,40]

Recommend


More recommend