Professional Documents
Culture Documents
16 Multi Version Concurrency Control
16 Multi Version Concurrency Control
1 / 66
Multi-Version Concurrency Control Recap
Recap
2 / 66
Multi-Version Concurrency Control Recap
3 / 66
Multi-Version Concurrency Control Recap
OCC Phases
• Phase 1 – Read:
▶ Track the read/write sets of txns and store their writes in a private workspace.
• Phase 2 – Validation:
▶ When a txn commits, check whether it conflicts with other txns.
• Phase 3 – Write:
▶ If validation succeeds, apply private changes to database. Otherwise abort and restart the
txn.
4 / 66
Multi-Version Concurrency Control Recap
Today’s Agenda
5 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
6 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
• The DBMS maintains multiple physical versions of a single logical object in the
database:
▶ When a txn writes to an object, the DBMS creates a new version of that object (instead of
private workspace in OCC)
▶ When a txn reads an object, it reads the newest version that existed when the txn started.
7 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC HISTORY
8 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
9 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 1
10 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 1
11 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 1
12 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 1
13 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 1
14 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 2
15 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 2
16 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 2
17 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 2
18 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 2
19 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 2
20 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
MVCC – Example 2
21 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
22 / 66
Multi-Version Concurrency Control Multi-Version Concurrency Control
23 / 66
Multi-Version Concurrency Control Concurrency Control Protocol
24 / 66
Multi-Version Concurrency Control Concurrency Control Protocol
25 / 66
Multi-Version Concurrency Control Version Storage
Version Storage
26 / 66
Multi-Version Concurrency Control Version Storage
Version Storage
• The DBMS uses the tuples’ pointer field to create a version chain per logical tuple.
▶ This allows the DBMS to find the version that is visible to a particular txn at runtime.
▶ Indexes always point to the head of the chain.
• Different storage schemes determine where/what to store for each version.
27 / 66
Multi-Version Concurrency Control Version Storage
Version Storage
28 / 66
Multi-Version Concurrency Control Version Storage
Append-Only Storage
• All of the physical versions of a logical tuple are stored in the same table space. The
versions are mixed together.
• On every update, append a new version of the tuple into an empty space in the table.
29 / 66
Multi-Version Concurrency Control Version Storage
Append-Only Storage
• All of the physical versions of a logical tuple are stored in the same table space. The
versions are mixed together.
• On every update, append a new version of the tuple into an empty space in the table.
30 / 66
Multi-Version Concurrency Control Version Storage
Append-Only Storage
• All of the physical versions of a logical tuple are stored in the same table space. The
versions are mixed together.
• On every update, append a new version of the tuple into an empty space in the table.
31 / 66
Multi-Version Concurrency Control Version Storage
32 / 66
Multi-Version Concurrency Control Version Storage
Time-Travel Storage
• On every update, copy the current version to the time-travel table. Update pointers.
• Overwrite master version in the main table. Update pointers.
33 / 66
Multi-Version Concurrency Control Version Storage
Time-Travel Storage
• On every update, copy the current version to the time-travel table. Update pointers.
• Overwrite master version in the main table. Update pointers.
34 / 66
Multi-Version Concurrency Control Version Storage
Time-Travel Storage
• On every update, copy the current version to the time-travel table. Update pointers.
• Overwrite master version in the main table. Update pointers.
35 / 66
Multi-Version Concurrency Control Version Storage
Time-Travel Storage
• On every update, copy the current version to the time-travel table. Update pointers.
• Overwrite master version in the main table. Update pointers.
36 / 66
Multi-Version Concurrency Control Version Storage
Delta Storage
• On every update, copy only the values that were modified to the delta storage and
overwrite the master version.
• Txns can recreate old versions by applying the delta in reverse order.
37 / 66
Multi-Version Concurrency Control Version Storage
Delta Storage
• On every update, copy only the values that were modified to the delta storage and
overwrite the master version.
• Txns can recreate old versions by applying the delta in reverse order.
38 / 66
Multi-Version Concurrency Control Version Storage
Delta Storage
• On every update, copy only the values that were modified to the delta storage and
overwrite the master version.
• Txns can recreate old versions by applying the delta in reverse order.
39 / 66
Multi-Version Concurrency Control Version Storage
Delta Storage
• On every update, copy only the values that were modified to the delta storage and
overwrite the master version.
• Txns can recreate old versions by applying the delta in reverse order.
40 / 66
Multi-Version Concurrency Control Garbage Collection
Garbage Collection
41 / 66
Multi-Version Concurrency Control Garbage Collection
Garbage Collection
• The DBMS needs to remove reclaimable physical versions from the database over
time.
▶ No active txn in the DBMS can see that version (SI).
▶ The version was created by an aborted txn.
• Two additional design decisions:
▶ How to look for expired versions?
▶ How to decide when it is safe to reclaim memory?
42 / 66
Multi-Version Concurrency Control Garbage Collection
Garbage Collection
• Approach 1: Tuple-level
▶ Find old versions by examining tuples directly.
▶ Background Vacuuming vs. Cooperative Cleaning
• Approach 2: Transaction-level
▶ Txns keep track of their old versions so the DBMS does not have to scan tuples to
determine visibility.
43 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
• Background Vacuuming:
• Separate thread(s) periodically scan the table and look for reclaimable versions.
• Works with any storage.
44 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
45 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
46 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
47 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
48 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
• Cooperative Cleaning:
• Worker threads identify reclaimable versions as they traverse version chain.
• Only works with O2N.
49 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
50 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
51 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
52 / 66
Multi-Version Concurrency Control Garbage Collection
Tuple-level GC
53 / 66
Multi-Version Concurrency Control Garbage Collection
Transaction-level GC
54 / 66
Multi-Version Concurrency Control Index Management
Index Management
55 / 66
Multi-Version Concurrency Control Index Management
Index Management
56 / 66
Multi-Version Concurrency Control Index Management
Secondary Indexes
57 / 66
Multi-Version Concurrency Control Index Management
Physical Pointers
58 / 66
Multi-Version Concurrency Control Index Management
Physical Pointers
59 / 66
Multi-Version Concurrency Control Index Management
Physical Pointers
60 / 66
Multi-Version Concurrency Control Index Management
Physical Pointers
61 / 66
Multi-Version Concurrency Control Index Management
Logical Pointers
62 / 66
Multi-Version Concurrency Control Index Management
Logical Pointers
63 / 66
Multi-Version Concurrency Control Index Management
MVCC Implementations
64 / 66
Multi-Version Concurrency Control Index Management
Conclusion
65 / 66
Multi-Version Concurrency Control Index Management
Next Class
66 / 66