Lecture 5
Lecture 5
2/6/2024 5-1
Chapter 5: Multiversion
Concurrency Control
“A book is a version of the world. If you do not like it, ignore it;
or offer your own version in return.” (Salmon Rushdie)
2/6/2024 5-2
Motivation
Example 5.1:
s = r1(x) w1(x) r2(x) w2(y) r1(y) w1(z) c1 c2 CSR
Approach:
• each w step creates a new version
• each r step can choose which version it wants/needs to read
• versions are transparent to application and
transient (i.e., subject to garbage collection)
2/6/2024 5-3
Multiversion Schedules
Definition 5.1 (Version Function):
Let s be a history with initial transaction t0 and final transaction t.
A version function for s is a function h which associates with each read step of s
a previous write step on the same data item, and the identity for writes.
2/6/2024 5-5
Multiversion View Serializability
Definition 5.4 (Reads-from Relation):
For mv schedule m the reads-from relation of m is
RF(m) = {(ti, x, tj) | rj(xi) op(m)}.
Example 5.5:
m = w0(x0) w0(y0) c0 r1(x0) r1(y0) w1(x1) w1(y1) c1 r2(x0) r2(y1) c2 MVSR
Example 5.6:
m = w0(x0) w0(y0) c0 w1(x1) c1 r2(x1) r3(x0) w3(x3) c3 w2(y2) c2 v t0 t3 t1 t2
2/6/2024 5-6
Properties of MVSR
Theorem 5.1: VSR MVSR
Example: s = r1(x) w1(x) r2(x) w2(y) r1(y) w1(z) c1 c2
Theorem 5.3:
The conflict graph of an mv schedule m is a directed graph G(m) with
transactions as nodes and an edge from ti to tj if rj(xi) op(m).
For all mv schedules m, m‘: m v m‘ G(m) = G(m‘).
Example:
m = w1(x1) r2(x0) w1(y1) r2(y1) c1 c2 G(m) = G(m‘),
m‘ = w1(x1) w1(y1) c1 r2(x1) r2(y0) c2 but not m v m‘
2/6/2024 5-7
Testing MVSR
Theorem 5.4:
m is in MVSR iff there exists a version order << s.t. MVSG(m, <<) is acyclic.
2/6/2024 5-8
MVSG Example
MVSG(m, <<): t1
t0 t3 t4
t2
Theorem:
m is in MCSR m is multiversion reducible m‘s mv conflict graph is acyclic
Theorem 5.6:
MCSR MVSR
Example:
m = w0(x0) w0(y0) w0(z0) c0 r2(y0) r3(z0) w3(x3) c3 r1(x3) w1(y1) c1 w2(x2) c2
r(x2) r(y1) r(z0) c
MCSR
t0 t2 MVSR
m v t0 t3 t2 t1 t
t1 t3 t
2/6/2024 5-11
Chapter 5: Multiversion
Concurrency Control
2/6/2024 5-12
MVTO Protocol
2/6/2024 5-13
MVTO Example
r1(x0) r1(y0)
t1 interleaving
impossible w/o
r2(x0) w2(x2) r2(y0) w2(y2) multiple versions
t2
2/6/2024 5-14
Multiversion 2PL (MV2PL) Protocol
General approach:
• use write locking to ensure that
at each time there is at most one uncommitted version
• for ti that is not yet issuing its final step:
• ri(x) is mapped to “current version” (i.e., the most recent committed
version)
or an uncommitted version
• wi(x) is executed only if x is not write-locked, otherwise it is blocked
• ti‘s final step is delayed until after the commit of:
• all tj that have read from a current version of a data item that ti has written
• all tj from which ti has read
Example 5.9:
for input schedule
s = r1(x) w1(x) r2(x) w2(y) r1(y) w2(x) c2 w1(y) c1
MV2PL produces the output schedule
r1(x0) w1(x1) r2(x1) w2(y2) r1(y0) w1(y1) c1 w2(x2) c2
2/6/2024 5-15
Specialization: 2V2PL Protocol
2-Version (before/after image) 2PL:
• request write lock wli(x) for writing a new uncommitted version
and ensuring that at most one such version exists at any time
• request read lock rli(x) for reading the current version
(i.e., most recent committed version)
• request certify lock cli(x) for final step of ti
on all data items in ti‘s write set
rlj(x) wlj(x)clj(x) lock requestor
rli(x) _
lock + +
holder wl (x)
i + _ _
cli(x) _ _ _
2/6/2024 5-17
Multiversion Serialization Graph Testing
(MVSGT)
Idea:
build version order and MVSG simultaneously (and incrementally)
Protocol rules:
• ri(x) is mapped to ri(xj) such that
• there is no path tj ... tk ... ti with previous wk(xk)
(eliminate “too old” transactions)
• there is no path ti ... tj
(eliminate “too young” transactions)
abort ti if no such tj exists
• upon wi(xi)
add edges tj ti for all tj with previous rj(xk)
abort ti when detecting cycle
• upon ri(xj)
add edge tj ti and
edges tk tj or ti tk for all tk with previous wk(xk)
2/6/2024 5-18
ROMV Protocol
2/6/2024 5-19
ROMV Example
r1(x0) r1(y0)
t1
r3(x2) w3(x3)
t3
r4(z0) r4(x0)
t4
r5(z0) r5(x2)
t5
2/6/2024 5-20
Chapter 5: Multiversion
Concurrency Control
2/6/2024 5-21
Lessons Learned
2/6/2024 5-22
Summary
2/6/2024 5-23