









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Notes on database concurrency control and recovery, focusing on locking and transactions. It covers topics such as write locks, read locks, commit protocols, and the difference between local and distributed commit. The document also discusses the importance of serializability and the potential problem of lost transactions.
Typology: Slides
1 / 16
This page cannot be seen from the preview
Don't miss anything!
CS 347 Notes07 7
X1 X2 X
lock lock lock
write (^) write (^) write
CS 347 Notes07 8
X1 X2 X
down!
CS 347 Notes07 9
Basic Solution — Improvement
reader has lock (^) writer will conflict!
CS 347 Notes07 10
Reminder
CS 347 Notes07 11
Variation on Basic: Primary copy
reader
lock write writer
CS 347 Notes07 12
Commit Options for Primary Site Scheme
X1 * X2 X
propagate update
lock, write, commit writer
CS 347 Notes07 13
Commit Options for Primary Site Scheme
X1 * X2 X
propagate update
lock, write, commit writer
Write(X):
•Commit at primary; get sequence number
•Perform X2, X3 updates in sequence number order
...
...
CS 347 Notes07 14
Example t = 0
CS 347 Notes07 15
Example t = 1
CS 347 Notes07 16
Example t = 2
CS 347 Notes07 17
Example t = 3
CS 347 Notes07 18
What good is RPWP-LC?
primary backup backup
updates can’t read!
CS 347 Notes07 25
Comparison
N = number of nodes with copies P = probability that a node is operational
Probability can read
Probability can write P N P N
CS 347 Notes07 26
Comparison
N = 5 = number of nodes with copies P = 0.99 = probability that a node is operational
CS 347 Notes07 27
Comparison
N = 100 = number of nodes with copies P = 0.99 = probability that a node is operational
CS 347 Notes07 28
Comparison
N = 5 = number of nodes with copies P = 0.90 = probability that a node is operational
CS 347 Notes07 29
Outline
CS 347 Notes07 30
Mobile Primary (with RPWP)
primary backup backup
CS 347 Notes07 31
(1) Elections
CS 347 Notes07 32
(1) Elections: One scheme
CS 347 Notes07 33
(1) Elections: Epoch Number
CS 347 Notes07 34
(2) Ensure new primary has
previously committed transactions
primary new primary backup
committed: T1, T
need to get and apply: T1, T
CS 347 Notes07 35
(3) Resolve pending transactions
primary new primary backup
T3? T3 in “W” state
T3 in “W” state
CS 347 Notes07 36
Failed Nodes: Example
-down- -down- -down-
P1 P2 P
P1 P2 P
P1 P2 P -down-
commits T 1
commit T 2 (unaware of T1!)
CS 347 Notes07 43
Guarantee
primary backup 1 backup 2
primary next primary backup 2
now:
T1, T2, T
T1, T2, T3, T
later:
CS 347 Notes07 44
Performance Hit
CS 347 Notes07 45
Alternative: 1-safe (RPWP:LC)
primary backup 1 backup 2
(1) T end work (2) T commit (3) send data (4) purge data
time
CS 347 Notes07 46
Problem: Lost Transactions
primary backup 1 backup 2
primary next primary backup 2
now:
T1, T2, T
T1, T4, T
later:
T1 T
T1, T
CS 347 Notes07 47
Claim
CS 347 Notes07 48
Primary Recovery with 1-safe
primary backup 2
backup 3 next primary^ backup 2
now:
T1, T2, T
T1, T4, T
later:
T1, T4, T5 T1, T
T1, T4, T
next primary
T1, T2, T3, T3-1, T2-1, T4, T compensation
CS 347 Notes07 49
Log Shipping
primary log backup
CS 347 Notes07 50
So Far in Data Replication
CS 347 Notes07 51
Outline
CS 347 Notes07 52
PC-lock available copies
primary down
CS 347 Notes07 53
Update Transaction
Primary
Backup
Backup
Trans T 3 , U={C 0 , C 1 }
updates, 2PC
CS 347 Notes07 54
A potential problem - example
Primary
Backup
Backup
I am recovering
CS 347 Notes07 61
Node Recovery (no primary)
CS 347 Notes07 62
recovering node
remembered? By whom?
Committed: A,B,C,D,E,F
Pending: G
Committed: A,C,B,E,D
Pending: F,G,H
Committed: A,B
Example
CS 347 Notes07 63
Correctness with replicated data
CS 347 Notes07 64
One idea: Require transactions to update all copies S 1 : r 1 [X 1 ] r 2 [X 2 ] w 1 [X 1 ] w 2 [X 2 ] w 1 [X 2 ] w 2 [X 1 ]
CS 347 Notes07 65
One idea: Require transactions to update all copies S 1 : r 1 [X 1 ] r 2 [X 2 ] w 1 [X 1 ] w 2 [X 2 ] w 1 [X 2 ] w 2 [X 1 ] (not a good idea for high-availability algorithms)
Another idea: Build in copy-semantics into notion of serializability
CS 347 Notes07 66
One copy serializable (1SR)
CS 347 Notes07 67
To check 1SR
CS 347 Notes07 68
Example
CS 347 Notes07 69
Second example
CS 347 Notes07 70
Second example
CS 347 Notes07 71
Question: Is this a “good” schedule?
CS 347 Notes07 72
Question: Is this a “good” schedule?
to be valid schedule, need precedence edge between w1(X) and w2(X)
CS 347 Notes07 79
Outline
CS 347 Notes07 80
Multiple fragments
Fragment 1
Fragment 2
Node 1 Node 2 Node 3 Node 4
CS 347 Notes07 81
F
T T
C F
C
C3 C
Read lock F1 at C1 (^) Read lock F2 at C
CS 347 Notes07 82
F
T
T
C
F
C
C3 C
Writes F1 at C Commits F1 at C2 (^) Writes F2 at C Commits F2 at C
CS 347 Notes07 83
CS 347 Notes07 84
F
T
T
C
F
C
C3 C
Writes F1 at C Commits F1 at C2 (^) Writes F2 at C Commits F2 at C cannot commit at F because U= {C1} is out of date...
CS 347 Notes07 85
Read-Only Transactions
0 0
0 0
C1: primary C2: backup
CS 347 Notes07 86
Later on:
0 3 0 5
0 3 0
C1: primary C2: backup
R1 read transaction sees current sate
R2 read transaction at backup sees “old” but “valid” state
CS 347 Notes07 87
States Are Equivalent
CS 347 Notes07 88
States Are Equivalent
at this point in time, backup may be behind...
CS 347 Notes07 89
Schedule is Serializable
CS 347 Notes07 90
Example 2
0 0
0 0
primary B: B: primary
Paxos
CS 347 Notes07 97
Paxos with 2 Phases
CS 347 Notes07 98
Paxos with 2 Phases
CS 347 Notes07 99
primary (leader)
3 phase commit!