0% found this document useful (0 votes)
4 views

B+Tree-indexconcurrency

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

B+Tree-indexconcurrency

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 95

Index Concurrency

Control

Lecture #09 Database Systems Andy Pavlo


15-445/15-645
Fall 2018
AP Computer Science
Carnegie Mellon Univ.
2

ADMINISTRIVIA

Project #1 is due TODAY!

Homework #2 is due Friday Sept 28th @ 11:59pm

Project #2 first checkpoint is due Monday Oct 8th.

CMU 15-445/645 (Fall 2018)


3

O B S E R VAT I O 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)


3

O B S E R VAT I O 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

CONCURRENCY CONTROL

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)


4

CONCURRENCY CONTROL

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)


5

T O D AY ' S A G E N D A

Latch Modes
Index Crabbing/Coupling
Leaf Scans
Delayed Parent Updates

CMU 15-445/645 (Fall 2018)


6

L O C K S V S . L AT C H E S

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)


7

L O C K S V S . L AT C H E S
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)
7

L O C K S V S . L AT C H E S
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)
7

L O C K S V S . L AT C H E S
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)
8

L AT C H M O D E S

Read Mode Compatibility Matrix


→ Multiple threads are allowed to read the
Read Write
same item at the same time.
→ 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)


9

B+TREE CONCURRENCY CONTROL

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)


10

B + T R E E M U LT I -T H R E A D E D E X A M P L E

20 A T1: Delete 44

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)
10

B + T R E E M U LT I -T H R E A D E D E X A M P L E

20 A T1: Delete 44

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)
10

B + T R E E M U LT I -T H R E A D E D E X A M P L E

20 A T1: Delete 44

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)
10

B + T R E E M U LT I -T H R E A D E D E X A M P L E

20 A T1: Delete 44
T2: 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)
10

B + T R E E M U LT I -T H R E A D E D E X A M P L E

20 A T1: Delete 44
T2: 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)
10

B + T R E E M U LT I -T H R E A D E D E X A M P L E

20 A T1: Delete 44
T2: 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 44
41
E F G H I
CMU 15-445/645 (Fall 2018)
10

B + T R E E M U LT I -T H R E A D E D E X A M P L E

20 A T1: Delete 44
T2: 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 44
41
E F G H I
???
CMU 15-445/645 (Fall 2018)
11

L AT C H C R A B B I N G / C O U P L I N 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)
12

L AT C H C R A B B I N G / C O U P L I N 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)


13

EXAMPLE #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)
13

EXAMPLE #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)
13

EXAMPLE #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)
13

EXAMPLE #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)
13

EXAMPLE #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)
13

EXAMPLE #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)
14

EXAMPLE #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)
14

EXAMPLE #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)
14

EXAMPLE #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 20latches
release 22 23on31A and35 B.36 38 41 44
E F G H I
CMU 15-445/645 (Fall 2018)
14

EXAMPLE #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 20latches
release 22 23on31A and35 B.36 38 41 44
E F G H I
CMU 15-445/645 (Fall 2018)
14

EXAMPLE #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)
14

EXAMPLE #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)
14

EXAMPLE #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)
15

EXAMPLE #3 INSERT 45
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)
15

EXAMPLE #3 INSERT 45
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)
15

EXAMPLE #3 INSERT 45

20 A

W
10 35 B

W
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)
15

EXAMPLE #3 INSERT 45

20 A

W
10 35 B

W
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 45
EI has room
F so it won’t
G split,
H I
so we can release B+D.
CMU 15-445/645 (Fall 2018)
15

EXAMPLE #3 INSERT 45

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 45
EI has room
F so it won’t
G split,
H I
so we can release B+D.
CMU 15-445/645 (Fall 2018)
16

EXAMPLE #4 INSERT 25
W
20 A

W
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

EXAMPLE #4 INSERT 25

20 A

W
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

EXAMPLE #4 INSERT 25

20 A

W
10 35 B

W
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

EXAMPLE #4 INSERT 25

20 A

10 35 B

W
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

EXAMPLE #4 INSERT 25

20 A

10 35 B

W
6 12 23 31 C 38 44 D

W
3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44
We need to split F so we need toE F G H I
keep the latch on its parent node.
CMU 15-445/645 (Fall 2018)
16

EXAMPLE #4 INSERT 25

20 A

10 35 B

W
6 12 23 31 C 38 44 D

W
3 4 6 9 10 11 12 13 20 22 23 31
25 35 36 38 41 44
We need to split F so we need toE F G H I
keep the latch on its parent node.
CMU 15-445/645 (Fall 2018)
16

EXAMPLE #4 INSERT 25

20 A

10 35 B

W
6 12 23 31 C 38 44 D

W
3 4 6 9 10 11 12 13 20 22 23 31
25 35 36 38 41 44
We need to split F so we need toE F G H I
keep the latch on its parent node.
31
CMU 15-445/645 (Fall 2018)
17

O B S E R VAT I O N

What was the first step that all of the update


examples did on the B+Tree?

Delete 38 Insert 45 Insert 25

W W W
20 A 20 A 20 A

CMU 15-445/645 (Fall 2018)


18

O B S E R VAT I O 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?

CMU 15-445/645 (Fall 2018)


19

B E T T E R L AT C H I N G A L G O R I T H 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.

CMU 15-445/645 (Fall 2018)


20

EXAMPLE #2 DELETE 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)
20

EXAMPLE #2 DELETE 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)
20

EXAMPLE #2 DELETE 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)
20

EXAMPLE #2 DELETE 38

20 A

10 35 B

R
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)
20

EXAMPLE #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
HE
will not F G
need to coalesce,Hso I
we’re safe!
CMU 15-445/645 (Fall 2018)
20

EXAMPLE #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
HE
will not F G
need to coalesce,Hso I
we’re safe!
CMU 15-445/645 (Fall 2018)
20

EXAMPLE #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
HE
will not F G
need to coalesce,Hso I
we’re safe!
CMU 15-445/645 (Fall 2018)
21

EXAMPLE #4 INSERT 25

20 A

10 35 B

6 12 23 31 C 38 44 D

W
3 4 6 We
9 need
10 11 12 13
to split 20 22 23 31
F so we 25 35 36 38 41 44
have to restart and re- E F G H I
execute like before.
CMU 15-445/645 (Fall 2018)
22

B E T T E R L AT C H I N G A L G O R I T H 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.

CMU 15-445/645 (Fall 2018)


23

O B S E R VAT I O 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?

CMU 15-445/645 (Fall 2018)


24

LEAF NODE SCAN EXAMPLE #1


T1: Find Keys < 4
R
3 A

1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


24

LEAF NODE SCAN EXAMPLE #1


T1: Find Keys < 4
3 A

R
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


24

LEAF NODE SCAN EXAMPLE #1


T1: Find Keys < 4
3 Do notArelease latch on C
until thread has latch on B
R
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


24

LEAF NODE SCAN EXAMPLE #1


T1: Find Keys < 4
3 Do notArelease latch on C
until thread has latch on B
R R
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


24

LEAF NODE SCAN EXAMPLE #1


T1: Find Keys < 4
3 A

R
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


25

LEAF NODE SCAN EXAMPLE #2


T1: Find Keys < 4
R
T2: Find Keys > 1
3 A

1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


25

LEAF NODE SCAN EXAMPLE #2


T1: Find Keys < 4
R
T2: Find Keys > 1
3 A

R R
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


25

LEAF NODE SCAN EXAMPLE #2


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

R R
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


25

LEAF NODE SCAN EXAMPLE #2


T1: Find Keys < 4
T2: Find Keys > 1
Both T1 and T2 now hold 3Both T1 and
AT2 now hold
this read latch. this read latch.

R R
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


25

LEAF NODE SCAN EXAMPLE #2


T1: Find Keys < 4
T2: Find Keys > 1
Only T1 holds 3 Only TA2 holds
this read latch. this read latch.

R R
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


26

LEAF NODE SCAN EXAMPLE #3


T1: Delete 4
R
T2: Find Keys > 1
3 A

1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


26

LEAF NODE SCAN EXAMPLE #3


T1: Delete 4
T2: Find Keys > 1
3 A

R W
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


26

LEAF NODE SCAN EXAMPLE #3


T1: Delete 4
T2: Find Keys > 1
3 A acquire
T2 cannot
the read latch on C
R W
1 2 3 4
B C

CMU 15-445/645 (Fall 2018)


26

LEAF NODE SCAN EXAMPLE #3


T1: Delete 4
T2: Find Keys > 1
3 A acquire
T2 cannot
the read latch on C
R W
1 2 3 4
B C

T2 does not know


what T1 is doing…

CMU 15-445/645 (Fall 2018)


26

LEAF NODE SCAN EXAMPLE #3


T1: Delete 4
T2: Find Keys > 1
3 A acquire
T2 cannot
the read latch on C
R W
1 2 3 4
B C

T2 does not know


what T1 is doing…

CMU 15-445/645 (Fall 2018)


27

LEAF NODE SCANS

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.

CMU 15-445/645 (Fall 2018)


28

D E L AY E D PA R E N T U P D AT E S

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


overflows, delay updating its parent node.

CMU 15-445/645 (Fall 2018)


29

EXAMPLE #4 INSERT 25
R
20 A

R
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)
29

EXAMPLE #4 INSERT 25

20 A

R
10 35 B

R
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)
29

EXAMPLE #4 INSERT 25

20 A

10 35 B

R
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)
29

EXAMPLE #4 INSERT 25

20 A

10 35 B

6 12 23 31 C 38 44 D

W
3 4 6 9 10 11 12 13 20 22 23 31 35 36 38 41 44
Add the new leaf node as a E F G H I
sibling to F, but do not update C
CMU 15-445/645 (Fall 2018)
29

EXAMPLE #4 INSERT 25

20 A

10 35 B

6 12 23 31 C 38 44 D

W
3 4 6 9 10 11 12 13 20 22 23 31
25 35 36 38 41 44
Add the new leaf node as a E F G H I
sibling to F, but do not update C
31
CMU 15-445/645 (Fall 2018)
29

EXAMPLE #4 INSERT 25

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
25 35 36 38 41 44
Add the new leaf node as a E F G H I
sibling to F, but do not update C
31
CMU 15-445/645 (Fall 2018)
29

EXAMPLE #4 INSERT 25

20 A

10 35 B
Update C the next time that a
thread takes a write latch on it.
6 12 23 31 C 38 44 D

3 4 6 9 10 11 12 13 20 22 23 31
25 35 36 38 41 44
E F G H I
31
CMU 15-445/645 (Fall 2018)
29

EXAMPLE #4 INSERT 25
R
20 A

10 35 B
Update C the next time that a
thread takes a write latch on it.
6 12 23 31 C 38 44 D

3 4 6 9 10 11 12 13 20 22 23 31
25 35 36 38 41 44
E F G H I
31
CMU 15-445/645 (Fall 2018)
29

EXAMPLE #4 INSERT 25

20 A

R
10 35 B
Update C the next time that a
thread takes a write latch on it.
6 12 23 31 C 38 44 D

3 4 6 9 10 11 12 13 20 22 23 31
25 35 36 38 41 44
E F G H I
31
CMU 15-445/645 (Fall 2018)
29

EXAMPLE #4 INSERT 25

20 A

R
10 35 B
Update C the next time that a
thread takes a write latch on it.
W
6 12 23 31 C 38 44 D

3 4 6 9 10 11 12 13 20 22 23 31
25 35 36 38 41 44
E F G H I
31
CMU 15-445/645 (Fall 2018)
30

CONCLUSION

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.

CMU 15-445/645 (Fall 2018)


31

PROJECT #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.

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

CMU 15-445/645 (Fall 2018)


32

CHECKPOINT #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.
CMU 15-445/645 (Fall 2018)
33

CHECKPOINT #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.
CMU 15-445/645 (Fall 2018)
34

DEVELOPMENT HINTS

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.

CMU 15-445/645 (Fall 2018)


35

THINGS TO NOTE

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


office hours.

CMU 15-445/645 (Fall 2018)


36

P L A G I A R I S M WA R N I N 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.

CMU 15-445/645 (Fall 2018)


37

NEXT CLASS

We are finally going to discuss how to execute


some damn queries…

CMU 15-445/645 (Fall 2018)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy