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

index concurrency control
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Database Systems 15-445/15-645 Fall 2018 Andy Pavlo Computer Science Carnegie Mellon Univ.

AP AP

Lecture # 09

Index Concurrency Control

slide-2
SLIDE 2

CMU 15-445/645 (Fall 2018)

ADM IN ISTRIVIA

Project #1 is due TODAY! Homework #2 is due Friday Sept 28th @ 11:59pm Project #2 first checkpoint is due Monday Oct 8th.

2

slide-3
SLIDE 3

CMU 15-445/645 (Fall 2018)

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.

3

slide-4
SLIDE 4

CMU 15-445/645 (Fall 2018)

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.

3

slide-5
SLIDE 5

CMU 15-445/645 (Fall 2018)

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?

4

slide-6
SLIDE 6

CMU 15-445/645 (Fall 2018)

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?

4

slide-7
SLIDE 7

CMU 15-445/645 (Fall 2018)

TO DAY'S AGEN DA

Latch Modes Index Crabbing/Coupling Leaf Scans Delayed Parent Updates

5

slide-8
SLIDE 8

CMU 15-445/645 (Fall 2018)

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.

6

slide-9
SLIDE 9

CMU 15-445/645 (Fall 2018)

LO CKS VS. LATCH ES

7

Locks Latches

User transactions Threads Database Contents In-Memory Data Structures Entire Transactions Critical Sections Shared, Exclusive, Update, Intention Read, Write Deadlock Detection & Resolution Avoidance Waits-for, Timeout, Aborts Coding Discipline Kept Lock Manager Protected Data Structure

Source: Goetz Graefe

slide-10
SLIDE 10

CMU 15-445/645 (Fall 2018)

LO CKS VS. LATCH ES

7

Locks Latches

User transactions Threads Database Contents In-Memory Data Structures Entire Transactions Critical Sections Shared, Exclusive, Update, Intention Read, Write Deadlock Detection & Resolution Avoidance Waits-for, Timeout, Aborts Coding Discipline Kept Lock Manager Protected Data Structure

Source: Goetz Graefe

slide-11
SLIDE 11

CMU 15-445/645 (Fall 2018)

LO CKS VS. LATCH ES

7

Locks Latches

User transactions Threads Database Contents In-Memory Data Structures Entire Transactions Critical Sections Shared, Exclusive, Update, Intention Read, Write Deadlock Detection & Resolution Avoidance Waits-for, Timeout, Aborts Coding Discipline Kept Lock Manager Protected Data Structure

Source: Goetz Graefe

slide-12
SLIDE 12

CMU 15-445/645 (Fall 2018)

LATCH M O DES

Read Mode

→ Multiple threads are allowed to read the same item at the same time. → A thread can acquire the read latch if another thread has it in read mode.

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.

8

Read Write Read

X

Write

X X

Compatibility Matrix

slide-13
SLIDE 13

CMU 15-445/645 (Fall 2018)

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.

9

slide-14
SLIDE 14

CMU 15-445/645 (Fall 2018)

38

B+ TREE M ULTI- TH READED EXAM PLE

10

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

T1: Delete 44

41

slide-15
SLIDE 15

CMU 15-445/645 (Fall 2018)

38

B+ TREE M ULTI- TH READED EXAM PLE

10

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

T1: Delete 44

41

slide-16
SLIDE 16

CMU 15-445/645 (Fall 2018)

38

B+ TREE M ULTI- TH READED EXAM PLE

10

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

T1: Delete 44

41

Rebalance!

slide-17
SLIDE 17

CMU 15-445/645 (Fall 2018)

38

B+ TREE M ULTI- TH READED EXAM PLE

10

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

T1: Delete 44 T2: Find 41

41

Rebalance!

slide-18
SLIDE 18

CMU 15-445/645 (Fall 2018)

38

B+ TREE M ULTI- TH READED EXAM PLE

10

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

T1: Delete 44 T2: Find 41

41

Rebalance!

slide-19
SLIDE 19

CMU 15-445/645 (Fall 2018)

38

B+ TREE M ULTI- TH READED EXAM PLE

10

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

T1: Delete 44 T2: Find 41

41

Rebalance!

41

slide-20
SLIDE 20

CMU 15-445/645 (Fall 2018)

38

B+ TREE M ULTI- TH READED EXAM PLE

10

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

T1: Delete 44 T2: Find 41

41

Rebalance!

41

???

slide-21
SLIDE 21

CMU 15-445/645 (Fall 2018)

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)

11

slide-22
SLIDE 22

CMU 15-445/645 (Fall 2018)

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,

  • btaining W latches as needed. Once child is

latched, check if it is safe:

→ If child is safe, release all latches on ancestors.

12

slide-23
SLIDE 23

CMU 15-445/645 (Fall 2018)

EXAM PLE # 1 SEARCH 38

13

3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 20 6 12 23 38 44

A B C D E F G H I

35 10

R

slide-24
SLIDE 24

CMU 15-445/645 (Fall 2018)

EXAM PLE # 1 SEARCH 38

13

3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 20 6 12 23 38 44

A B C D E F G H I

35 10

R R It’s safe to release the latch on A.

slide-25
SLIDE 25

CMU 15-445/645 (Fall 2018)

EXAM PLE # 1 SEARCH 38

13

3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 20 6 12 23 38 44

A B C D E F G H I

35 10

R

slide-26
SLIDE 26

CMU 15-445/645 (Fall 2018)

EXAM PLE # 1 SEARCH 38

13

3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 20 6 12 23 38 44

A B C D E F G H I

35 10

R

slide-27
SLIDE 27

CMU 15-445/645 (Fall 2018)

EXAM PLE # 1 SEARCH 38

13

3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 20 6 12 23 38 44

A B C D E F G H I

35 10

R

slide-28
SLIDE 28

CMU 15-445/645 (Fall 2018)

EXAM PLE # 1 SEARCH 38

13

3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44 20 6 12 23 38 44

A B C D E F G H I

35 10

slide-29
SLIDE 29

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

14

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

W

slide-30
SLIDE 30

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

14

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

W W We may need to coalesce B, so we can’t release the latch on A.

slide-31
SLIDE 31

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

14

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

W W W We know that D will not need to merge with C, so it’s safe to release latches on A and B.

slide-32
SLIDE 32

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

14

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

W We know that D will not need to merge with C, so it’s safe to release latches on A and B.

slide-33
SLIDE 33

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

14

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

W

slide-34
SLIDE 34

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

14

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

W

slide-35
SLIDE 35

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

14

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

slide-36
SLIDE 36

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 3 IN SERT 4 5

15

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 45 20 6 12 23 38 44

A B C D E F G H I

35 10

W W

slide-37
SLIDE 37

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 3 IN SERT 4 5

15

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 45 20 6 12 23 38 44

A B C D E F G H I

35 10

W W

slide-38
SLIDE 38

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 3 IN SERT 4 5

15

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 45 20 6 12 23 38 44

A B C D E F G H I

35 10

W W

slide-39
SLIDE 39

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 3 IN SERT 4 5

15

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 45 20 6 12 23 38 44

A B C D E F G H I

35 10

W W W I has room so it won’t split, so we can release B+D.

slide-40
SLIDE 40

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 3 IN SERT 4 5

15

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 45 20 6 12 23 38 44

A B C D E F G H I

35 10

W I has room so it won’t split, so we can release B+D.

slide-41
SLIDE 41

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

16

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W W

slide-42
SLIDE 42

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

16

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W

slide-43
SLIDE 43

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

16

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W W

slide-44
SLIDE 44

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

16

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W

slide-45
SLIDE 45

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

16

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W W We need to split F so we need to keep the latch on its parent node.

slide-46
SLIDE 46

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

16

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W W

25

We need to split F so we need to keep the latch on its parent node.

slide-47
SLIDE 47

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

16

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W W

25 31

We need to split F so we need to keep the latch on its parent node.

slide-48
SLIDE 48

CMU 15-445/645 (Fall 2018)

O BSERVATIO N

What was the first step that all of the update examples did on the B+Tree?

17

20

A W

Delete 38

20

A W

Insert 45

20

A W

Insert 25

slide-49
SLIDE 49

CMU 15-445/645 (Fall 2018)

O BSERVATIO N

What was the first step that all of the update examples did on the B+Tree? Taking a write latch on the root every time becomes a bottleneck with higher concurrency. Can we do better?

18

slide-50
SLIDE 50

CMU 15-445/645 (Fall 2018)

BETTER LATCH IN G ALGO RITH M

Assume that the leaf node is safe. Use read latches and crabbing to reach it, and verify that it is safe. If leaf is not safe, then do previous algorithm using write latches.

19

slide-51
SLIDE 51

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

20

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

R

slide-52
SLIDE 52

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

20

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

R

slide-53
SLIDE 53

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

20

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

R

slide-54
SLIDE 54

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

20

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

R W

slide-55
SLIDE 55

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

20

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

W H will not need to coalesce, so we’re safe!

slide-56
SLIDE 56

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

20

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

W H will not need to coalesce, so we’re safe!

slide-57
SLIDE 57

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 2 DELETE 38

20

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 38 44

A B C D E F G H I

35 10

H will not need to coalesce, so we’re safe!

slide-58
SLIDE 58

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

21

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W

25

We need to split F so we have to restart and re- execute like before.

slide-59
SLIDE 59

CMU 15-445/645 (Fall 2018)

BETTER LATCH IN G ALGO RITH M

Search: Same as before. Insert/Delete:

→ Set latches as if for search, get to leaf, and set W latch on leaf. → If leaf is not safe, release all latches, and restart thread using previous insert/delete protocol with write latches.

This approach optimistically assumes that only leaf node will be modified; if not, R latches set on the first pass to leaf are wasteful.

22

slide-60
SLIDE 60

CMU 15-445/645 (Fall 2018)

O BSERVATIO N

The threads in all of the examples so far have acquired latches in a "top-down" manner.

→ A thread can only acquire a latch from a node that is below its current node. → If the desired latch is unavailable, the thread must wait until it becomes available.

But what if we want to move from one leaf node to another leaf node?

23

slide-61
SLIDE 61

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 1

24

A B

3 1 2 3 4

C

T1: Find Keys < 4

R

slide-62
SLIDE 62

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 1

24

A B

3 1 2 3 4

C

T1: Find Keys < 4

R

slide-63
SLIDE 63

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 1

24

A B

3 1 2 3 4

C

T1: Find Keys < 4

R Do not release latch on C until thread has latch on B

slide-64
SLIDE 64

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 1

24

A B

3 1 2 3 4

C

T1: Find Keys < 4

R R Do not release latch on C until thread has latch on B

slide-65
SLIDE 65

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 1

24

A B

3 1 2 3 4

C

T1: Find Keys < 4

R

slide-66
SLIDE 66

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 2

25

A B

3 1 2 3 4

C

T1: Find Keys < 4 T2: Find Keys > 1

R

slide-67
SLIDE 67

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 2

25

A B

3 1 2 3 4

C

T1: Find Keys < 4 T2: Find Keys > 1

R R R

slide-68
SLIDE 68

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 2

25

A B

3 1 2 3 4

C

T1: Find Keys < 4 T2: Find Keys > 1

R R

slide-69
SLIDE 69

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 2

25

A B

3 1 2 3 4

C

T1: Find Keys < 4 T2: Find Keys > 1

R R Both T1 and T2 now hold this read latch. Both T1 and T2 now hold this read latch.

slide-70
SLIDE 70

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 2

25

A B

3 1 2 3 4

C

T1: Find Keys < 4 T2: Find Keys > 1

R R Only T1 holds this read latch. Only T2 holds this read latch.

slide-71
SLIDE 71

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 3

26

A B

3 1 2 3 4

C

T1: Delete 4 T2: Find Keys > 1

R

slide-72
SLIDE 72

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 3

26

A B

3 1 2 3 4

C

T1: Delete 4 T2: Find Keys > 1

R W

slide-73
SLIDE 73

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 3

26

A B

3 1 2 3 4

C

T1: Delete 4 T2: Find Keys > 1

R W T2 cannot acquire the read latch on C

slide-74
SLIDE 74

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 3

26

A B

3 1 2 3 4

C

T1: Delete 4 T2: Find Keys > 1

R W T2 does not know what T1 is doing… T2 cannot acquire the read latch on C

slide-75
SLIDE 75

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN EXAM PLE # 3

26

A B

3 1 2 3 4

C

T1: Delete 4 T2: Find Keys > 1

R W T2 does not know what T1 is doing… T2 cannot acquire the read latch on C

slide-76
SLIDE 76

CMU 15-445/645 (Fall 2018)

LEAF N O DE SCAN S

Latches do not support deadlock detection or

  • avoidance. The only way we can deal with this

problem is through coding discipline. The leaf node sibling latch acquisition protocol must support a "no-wait" mode. B+tree code must cope with failed latch acquisitions.

27

slide-77
SLIDE 77

CMU 15-445/645 (Fall 2018)

DELAYED PAREN T UPDATES

Every time a leaf node overflows, we have to update at least three nodes.

→ The leaf node being split. → The new leaf node being created. → The parent node.

Blink-Tree Optimization: When a leaf node

  • verflows, delay updating its parent node.

28

slide-78
SLIDE 78

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

R R

slide-79
SLIDE 79

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

R R

slide-80
SLIDE 80

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

R

slide-81
SLIDE 81

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W Add the new leaf node as a sibling to F, but do not update C

slide-82
SLIDE 82

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

W

25 31

Add the new leaf node as a sibling to F, but do not update C

slide-83
SLIDE 83

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10 25 31

Add the new leaf node as a sibling to F, but do not update C

slide-84
SLIDE 84

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10 25 31

Update C the next time that a thread takes a write latch on it.

slide-85
SLIDE 85

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

R

25 31

Update C the next time that a thread takes a write latch on it.

slide-86
SLIDE 86

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

R

25 31

Update C the next time that a thread takes a write latch on it.

slide-87
SLIDE 87

CMU 15-445/645 (Fall 2018)

38 41

EXAM PLE # 4 IN SERT 25

29

3 4 6 9 10 11 12 13 20 22 23 31 35 36 44 20 6 12 23 31 38 44

A B C D E F G H I

35 10

R

25 31

Update C the next time that a thread takes a write latch on it. W

slide-88
SLIDE 88

CMU 15-445/645 (Fall 2018)

CO N CLUSIO N

Making a data structure thread-safe seems easy to understand but it is notoriously difficult in practice. We focused on B+Trees here but the same high- level techniques are applicable to other data structures.

30

slide-89
SLIDE 89

CMU 15-445/645 (Fall 2018)

PRO J ECT # 2

You will build a thread-safe B+tree.

→ Page Layout → Data Structure → STL Iterator → Latch Crabbing

We define the API for you. You need to provide the method implementations.

31

https://15445.courses.cs.cmu.edu/fall2018/project2/

+

slide-90
SLIDE 90

CMU 15-445/645 (Fall 2018)

CH ECKPO IN T # 1

Due Date: October 8th @ 11:59pm Total Project Grade: 40% Page Layouts

→ How each node will store its key/values in a page. → You only need to support unique keys.

Data Structure (Find + Insert)

→ Support point queries (single key). → Support inserts with node splitting. → Does not need to be thread-safe.

32

slide-91
SLIDE 91

CMU 15-445/645 (Fall 2018)

CH ECKPO IN T # 2

Due Date: October 19th @ 11:59pm Total Project Grade: 60% Data Structure (Deletion)

→ Support removal of keys with sibling stealing + merging.

Index Iterator

→ Create a STL iterator for range scans.

Concurrent Index

→ Implement latch crabbing/coupling.

33

slide-92
SLIDE 92

CMU 15-445/645 (Fall 2018)

DEVELO PM EN T H IN TS

Follow the textbook semantics and algorithms.

→ See Chapter 15.10

Set the page size to be small (e.g., 512B) when you first start so that you can see more splits/merges. Make sure that you protect the internal B+Tree root_page_id member.

34

slide-93
SLIDE 93

CMU 15-445/645 (Fall 2018)

TH IN GS TO N OTE

Do not change any file other than the ten that you have to hand it. We will provide an updated source tarball. You will need to copy over your files from Project #1. Post your questions on Piazza or come to TA

  • ffice hours.

35

slide-94
SLIDE 94

CMU 15-445/645 (Fall 2018)

PLAGIARISM WARN IN G

Your project implementation must be your own work.

→ You may not copy source code from other groups or the web. → Do not publish your implementation on Github.

Plagiarism will not be tolerated. See CMU's Policy on Academic Integrity for additional information.

36

slide-95
SLIDE 95

CMU 15-445/645 (Fall 2018)

N EXT CLASS

We are finally going to discuss how to execute some damn queries…

37