Professional Documents
Culture Documents
Concurrency Control With Timestamps Concurrency Control With Timestamps
Concurrency Control With Timestamps Concurrency Control With Timestamps
U i
University
it off Cyprus
C
EPL446 – Advanced Database Systems
Lecture 16
Concurrency Control with Timestamps
Chapter 18.2
18.2-18.4
18.4 (except 18.3.2): Elmasri & Navathe, 5ED
Chapter 17.6: Ramakrishnan & Gehrke, 3ED
Demetris Zeinalipour
http://www cs ucy ac cy/~dzeina/courses/epl446
http://www.cs.ucy.ac.cy/ dzeina/courses/epl446
16-1
EPL446: Advanced Database Systems - Demetris Zeinalipour (University of Cyprus)
Concurrency Control in DBMSs
(Έλ
(Έλεγχος Τ
Ταυτοχρονίας
ί σε Σ∆Β∆)
• In the previous lecture we explained how a real DBMS
enforces (επιβάλει) Serializability and Recoverability (Strict
2PL) in its transaction schedules using Locking
• We will now see another class of protocols based on
Timestamps (though not widely utilized in real DBMSs, they
have a theoretical interest)
interest).
• Concurrency Control with Timestamps (without Locking)
– Timestamp Ordering (Έλεγχος Ταυτοχρονισμού με ∆ιάταξη
Χρονόσηµων): Ensure serializability using the ordering of timestamps
generated by the DBMS.
– Multiversion CC (Έλεγχος Ταυτοχρονισμού Με Πολλαπλές
Εκδόσεις): Use multiple version of items to enforce serializability.
– Optimistic CC (Αισιόδοξος (Οπτιμιστικός) Έλεγχος
Ταυτοχρονισμού): No checking done during execution of a Transaction
but post-execution validation (επικύρωση) enforces serializability. 16-2
EPL446: Advanced Database Systems - Demetris Zeinalipour (University of Cyprus)
Timestamp based CC: Definitions
(Έλ
(Έλεγχος Τ
Ταυτοχρονίας
ί με Χ
Χρονόσημα:
ό Ο
Ορισμοί)
ί)
• Timestamp
p ((Χρονόσημο)
ρ ημ )
– A monotonically increasing variable (integer)
indicating the age of an operation or a transaction.
• A larger timestamp indicates a more recent transaction
– Timestamps are assigned in our context during Xact creation.
– Using date timestamps (e.g., a long integer which represents
the number of seconds that have passed from 1/1/1970)
• TS1: 1237917600 (2009
(2009-03-24
03 24 18:00:00)
• TS2: 1237917610 (2009-03-24 18:00:10)
– Using a counter timestamp (e.g., using a counter stored inside
th O
the Operating
ti S System
t kernel
k l as a semaphore)
h )
10 sec Now
16-7
EPL446: Advanced Database Systems - Demetris Zeinalipour (University of Cyprus)
Basic TO Algorithm Example
(Π άδ
(Παράδειγμα Βασικός
Β ό Αλγόριθμος
Αλ ό θ ∆ιάταξης
∆ ά ξ Χρονοσήμων)
Χ ή )
1. A1 = Read(X) RTS(X) : 20
WTS(X) : 20
2 A1 = A1*
2. A1 1.01
1 01 RTS(Y) : 0
3. Write(X, A1) WTS(Y) : 0
RTS(X) : 20 4. A2 = Read(Y) WTS(X) TS(T): Write(X)
WTS(X) : 20
5 A2 = A2 + k
5.
RTS(Y) : 10 Time
WTS(Y) : 10 6. Write(Y, A2)
4. A2 = Read(Y) RTS(X) : 20
Yes! The schedule is serializable! 5. A2 = A2 * 1.01 WTS(X) : 20
RTS(Y) : 20
This can be confirmed by the 6. Write(Y, A2) WTS(Y) : 20
precedence graph which is acyclic 16-8
EPL446: Advanced Database Systems - Demetris Zeinalipour (University of Cyprus)
Basic TO Algorithm Example
(Π άδ
(Παράδειγμα Βασικός
Β ό Αλγόριθμος
Αλ ό θ ∆ιάταξης
∆ ά ξ Χρονοσήμων)
Χ ή )
3. Write(X, A1)
Time
4
4. A2 = R
Read(Y)
d(Y)
RTS(X) : 20
5. A2 = A2 * 1.01 WTS(X) : 20
6. Write(Y, A2) RTS(Y) : 20
4. A2 = Read(Y)
4 WTS(Y) : 20
5. A2 = A2 + k TS(T1)=10
WTS(Y)=
20
Reject T1 (TO rule violated)
6. Write(Y, A2) (Restart with new TS)
Time
X
NO! The schedule is NOT serializable
16-9
• this is confirmed
EPL446: with the
Advanced Database precedence
Systems - Demetrisgraph which
Zeinalipour is cyclic
(University of Cyprus)
Advantages/Disadvantages of Basic TO
(Πλεονεκ /Μειονεκ του Βασικού Αλγ.
(Πλεονεκ./Μειονεκ. Αλγ ∆ιατ.
∆ιατ Χρον.)
Χρον )
• Basic TO Remark
– Note that there is no notion of RR-conflict
If TS(T) < RTS(X), then execute read(X) of T and update RTS(X).
• Advantages
Ad t off Basic
B i TO Algorithm
Al ith
– Schedules are serializable (like 2PL protocols)
– No
N waiting
iti ffor ttransaction,
ti thus,
th no deadlocks!
d dl k !
• Disadvantages
– Schedule
S h d l may nott b
be recoverable
bl
• Solution: Utilize Strict TO Algorithm (see next)
– Starvation is possible (if the same transaction is
continually aborted and restarted) 16-10
• Solution:
EPL446: AssignSystems
Advanced Database new timestamp for aborted
- Demetris Zeinalipour transaction
(University of Cyprus)
Strict Timestamp Ordering
(
(Αυστηρός Αλγόριθμος
θ ∆ιάταξης
ξ Χρονοσήμων))
• The Basic T.O. algorithm guarantees serializability but not
recoverability (επαναφερσιμότητα)
• The Strict T.O. algorithms introduces recoverability.
– (Revision) Strict Schedule: A transaction can neither read or write
an uncommitted data item X.
• Strict T
T.O.
O Main Idea: Extend the Accept cases of the
Basic T.O. algorithm by adding the requirement that a
commit occu
co occurs
s be
before
oeTpproceeds
oceeds with its
s ope
operation.
a o i.e.,
e,
WTS(X) TS(T): Read(X)
Accept T (TO ok)
Time
commit
• Disadvantage:
– Significantly more storage (RAM and Disk) is required
to maintain multiple versions.
– To
T check
h k unlimited
li it d growth
th off versions,
i a garbage
b
collection is run periodically. 16-14
EPL446: Advanced Database Systems - Demetris Zeinalipour (University of Cyprus)
Multiversion Concurrency Control
(Έλεγχος Ταυτοχρονισμού Με Πολλαπλές Εκδόσεις)
• Notation Time
commit
– RTS(Xi): The read timestamp of Xi is the largest of all the
timestamps of transactions that have successfully read version Xi.
– WTS(Xi): The write timestamp of Xi that wrote the value of
version Xi.
• Basic Idea: Works much like Basic TO with the difference that
instead of WTS(X) and RTS(X) we now utilize the highest WTS(Xi)
and highest RTS(Xi) respectively.
16-15
EPL446: Advanced Database Systems - Demetris Zeinalipour (University of Cyprus)
Multiversion Concurrency Control
(Έλεγχος Ταυτοχρονισμού Με Πολλαπλές Εκδόσεις)
• To ensure serializability, the following rules are used
– C1B) If transaction T issues read(X), find the version i of X that
has the highest WTS(Xi) of all versions of X that is also less than
or equal to TS(T),
TS(T) then accept the read and update the RTS(X)
respectively. Max{WTS(Xi)} TS(T): Read(X)
Accept T (TO ok)
Time