index concurrency control
play

Index Concurrency Control Lecture # 09 Database Systems Andy - PowerPoint PPT Presentation

Index Concurrency Control Lecture # 09 Database Systems Andy Pavlo AP AP Computer Science 15-445/15-645 Carnegie Mellon Univ. Fall 2018 2 ADM IN ISTRIVIA Project #1 is due TODAY! Homework #2 is due Friday Sept 28 th @ 11:59pm Project #2


  1. Index Concurrency Control Lecture # 09 Database Systems Andy Pavlo AP AP Computer Science 15-445/15-645 Carnegie Mellon Univ. Fall 2018

  2. 2 ADM IN ISTRIVIA Project #1 is due TODAY! Homework #2 is due Friday Sept 28 th @ 11:59pm Project #2 first checkpoint is due Monday Oct 8 th . CMU 15-445/645 (Fall 2018)

  3. 3 O BSERVATIO N We assumed that all of the data structures that we have discussed so far are single-threaded. But we need to allow multiple threads to safely access our data structures to take advantage of additional CPU cores. CMU 15-445/645 (Fall 2018)

  4. 3 O BSERVATIO N We assumed that all of the data structures that we have discussed so far are single-threaded. But we need to allow multiple threads to safely access our data structures to take advantage of additional CPU cores. CMU 15-445/645 (Fall 2018)

  5. 4 CO N CURREN CY CO N TRO L A concurrency control protocol is the method that the DBMS uses to ensure "correct" results for concurrent operations on a shared object. A protocol's correctness criteria can vary: → Logical Correctness: Can I see the data that I am supposed to see? → Physical Correctness: Is the internal representation of the object sound? CMU 15-445/645 (Fall 2018)

  6. 4 CO N CURREN CY CO N TRO L A concurrency control protocol is the method that the DBMS uses to ensure "correct" results for concurrent operations on a shared object. A protocol's correctness criteria can vary: → Logical Correctness: Can I see the data that I am supposed to see? → Physical Correctness: Is the internal representation of the object sound? CMU 15-445/645 (Fall 2018)

  7. 5 TO DAY'S AGEN DA Latch Modes Index Crabbing/Coupling Leaf Scans Delayed Parent Updates CMU 15-445/645 (Fall 2018)

  8. 6 LO CKS VS. LATCH ES Locks → Protects the index’s logical contents from other txns. → Held for txn duration. → Need to be able to rollback changes. Latches → Protects the critical sections of the index’s internal data structure from other threads. → Held for operation duration. → Do not need to be able to rollback changes. CMU 15-445/645 (Fall 2018)

  9. 7 LO CKS VS. LATCH ES Locks Latches User transactions Threads Database Contents In-Memory Data Structures Entire Transactions Critical Sections Shared, Exclusive, Update, Read, Write Intention Deadlock Detection & Resolution Avoidance Waits-for, Timeout, Aborts Coding Discipline Kept Lock Manager Protected Data Structure Source: Goetz Graefe CMU 15-445/645 (Fall 2018)

  10. 7 LO CKS VS. LATCH ES Locks Latches User transactions Threads Database Contents In-Memory Data Structures Entire Transactions Critical Sections Shared, Exclusive, Update, Read, Write Intention Deadlock Detection & Resolution Avoidance Waits-for, Timeout, Aborts Coding Discipline Kept Lock Manager Protected Data Structure Source: Goetz Graefe CMU 15-445/645 (Fall 2018)

  11. 7 LO CKS VS. LATCH ES Locks Latches User transactions Threads Database Contents In-Memory Data Structures Entire Transactions Critical Sections Shared, Exclusive, Update, Read, Write Intention Deadlock Detection & Resolution Avoidance Waits-for, Timeout, Aborts Coding Discipline Kept Lock Manager Protected Data Structure Source: Goetz Graefe CMU 15-445/645 (Fall 2018)

  12. 8 LATCH M O DES Read Mode Compatibility Matrix → Multiple threads are allowed to read the same item at the same time. Read Write → A thread can acquire the read latch if Read ✔ X another thread has it in read mode. Write X X Write Mode → Only one thread is allowed to access the item. → A thread cannot acquire a write latch if another thread holds the latch in any mode. CMU 15-445/645 (Fall 2018)

  13. 9 B+ TREE CO N CURREN CY CO N TRO L We want to allow multiple threads to read and update a B+tree index at the same time. We need to protect from two types of problems: → Threads trying to modify the contents of a node at the same time. → One thread traversing the tree while another thread splits/merges nodes. CMU 15-445/645 (Fall 2018)

  14. 10 B+ TREE M ULTI- TH READED EXAM PLE T 1 : Delete 44 20 A 10 35 B 6 12 23 31 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  15. 10 B+ TREE M ULTI- TH READED EXAM PLE T 1 : Delete 44 20 A 10 35 B 6 12 23 31 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  16. 10 B+ TREE M ULTI- TH READED EXAM PLE T 1 : Delete 44 20 A 10 35 B 6 12 23 31 C 38 44 D Rebalance! 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  17. 10 B+ TREE M ULTI- TH READED EXAM PLE T 1 : Delete 44 20 A T 2 : Find 41 10 35 B 6 12 23 31 C 38 44 D Rebalance! 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  18. 10 B+ TREE M ULTI- TH READED EXAM PLE T 1 : Delete 44 20 A T 2 : Find 41 10 35 B 6 12 23 31 C 38 44 D Rebalance! 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  19. 10 B+ TREE M ULTI- TH READED EXAM PLE T 1 : Delete 44 20 A T 2 : Find 41 10 35 B 6 12 23 31 C 38 44 41 D Rebalance! 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 44 41 E F G H I CMU 15-445/645 (Fall 2018)

  20. 10 B+ TREE M ULTI- TH READED EXAM PLE T 1 : Delete 44 20 A T 2 : Find 41 10 35 B 6 12 23 31 C 38 41 44 D Rebalance! 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I ??? CMU 15-445/645 (Fall 2018)

  21. 11 LATCH CRABBIN G/ CO UPLIN G Protocol to allow multiple threads to access/modify B+Tree at the same time. Basic Idea: → Get latch for parent. → Get latch for child → Release latch for parent if “safe”. A safe node is one that will not split or merge when updated. → Not full (on insertion) → More than half-full (on deletion) CMU 15-445/645 (Fall 2018)

  22. 12 LATCH CRABBIN G/ CO UPLIN G Search : Start at root and go down; repeatedly, → Acquire R latch on child → Then unlatch parent Insert/Delete : Start at root and go down, obtaining W latches as needed. Once child is latched, check if it is safe: → If child is safe, release all latches on ancestors. CMU 15-445/645 (Fall 2018)

  23. 13 EXAM PLE # 1 SEARCH 38 R 20 A 10 35 B 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  24. 13 EXAM PLE # 1 SEARCH 38 R 20 A R 10 35 B It’s safe to release the latch on A. 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  25. 13 EXAM PLE # 1 SEARCH 38 20 A R 10 35 B 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  26. 13 EXAM PLE # 1 SEARCH 38 20 A 10 35 B R 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  27. 13 EXAM PLE # 1 SEARCH 38 20 A 10 35 B 6 12 23 C 38 44 D R 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  28. 13 EXAM PLE # 1 SEARCH 38 20 A 10 35 B 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  29. 14 EXAM PLE # 2 DELETE 38 W 20 A 10 35 B 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  30. 14 EXAM PLE # 2 DELETE 38 W 20 A W 10 35 B We may need to coalesce B, so we can’t release the latch on A. 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  31. 14 EXAM PLE # 2 DELETE 38 W 20 A W 10 35 B W 6 12 23 C 38 44 D We know that D will not need to merge with C, so it’s safe to 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 release latches on A and B. E F G H I CMU 15-445/645 (Fall 2018)

  32. 14 EXAM PLE # 2 DELETE 38 20 A 10 35 B W 6 12 23 C 38 44 D We know that D will not need to merge with C, so it’s safe to 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 release latches on A and B. E F G H I CMU 15-445/645 (Fall 2018)

  33. 14 EXAM PLE # 2 DELETE 38 20 A 10 35 B 6 12 23 C 38 44 D W 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  34. 14 EXAM PLE # 2 DELETE 38 20 A 10 35 B 6 12 23 C 38 44 D W 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  35. 14 EXAM PLE # 2 DELETE 38 20 A 10 35 B 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 E F G H I CMU 15-445/645 (Fall 2018)

  36. 15 EXAM PLE # 3 IN SERT 4 5 W 20 A W 10 35 B 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 45 E F G H I CMU 15-445/645 (Fall 2018)

  37. 15 EXAM PLE # 3 IN SERT 4 5 W 20 A W 10 35 B 6 12 23 C 38 44 D 3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 45 E F G H I CMU 15-445/645 (Fall 2018)

Recommend


More recommend