concurrency control
DESCRIPTION
Concurrency Control. Conflict serializability Two phase locking Optimistic concurrency control. Source: slides by Hector Garcia-Molina. Concurrently Executing Transactions. T1T2…Tn. DB (consistency constraints). Example:. T1:Read(A)T2:Read(A) A A+100A A 2 - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/1.jpg)
1
Concurrency ControlConflict serializability
Two phase lockingOptimistic concurrency
controlSource: slides by Hector Garcia-Molina
![Page 2: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/2.jpg)
2
Concurrently Executing Transactions
T1 T2 … Tn
DB(consistencyconstraints)
![Page 3: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/3.jpg)
3
Example:T1: Read(A) T2: Read(A)
A A+100 A A2Write(A) Write(A)Read(B) Read(B)B B+100 B B2Write(B) Write(B)
Constraint: A=B
![Page 4: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/4.jpg)
4
Schedule AT1T2Read(A); A A+100Write(A);Read(B); B B+100;Write(B);
Read(A);A A2;Write(A); Read(B);B B2;Write(B);
A B25 25
125
125
250
250250 250
![Page 5: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/5.jpg)
5
Schedule BT1T2
Read(A);A A2;Write(A);Read(B);B B2;Write(B);
Read(A); A A+100Write(A);Read(B); B B+100;Write(B);
A B25 25
50
50
150
150150 150
![Page 6: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/6.jpg)
6
Schedule CT1T2Read(A); A A+100Write(A);
Read(A);A A2;Write(A);
Read(B); B B+100;Write(B);
Read(B);B B2;Write(B);
A B25 25
125
250
125
250250 250
![Page 7: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/7.jpg)
7
Schedule DT1T2Read(A); A A+100Write(A);
Read(A);A A2;Write(A); Read(B);B B2;Write(B);
Read(B); B B+100;Write(B);
A B25 25
125
250
50
150250 150
![Page 8: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/8.jpg)
8
Schedule ET1T2’Read(A); A A+100Write(A);
Read(A);A A1;Write(A); Read(B);B B1;Write(B);
Read(B); B B+100;Write(B);
A B25 25
125
125
25
125125 125
Same as Schedule Dbut with new T2’
![Page 9: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/9.jpg)
9
Want schedules that are “good”,regardless of
initial state and transaction semantics
Only look at order of read and writes
Example: Sc = r1(A) w1(A) r2(A) w2(A) r1(B) w1(B) r2(B)
w2(B)
![Page 10: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/10.jpg)
10
Sc’ = r1(A) w1(A) r1(B) w1(B) r2(A) w2(A) r2(B) w2(B)
T1 T2
Example: Sc = r1(A) w1(A) r2(A) w2(A) r1(B) w1(B) r2(B) w2(B)
![Page 11: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/11.jpg)
11
However, for Sd:Sd = r1(A) w1(A) r2(A) w2(A) r2(B) w2(B) r1(B)
w1(B)
as a matter of fact, T2 must precede T1
in any equivalent schedule, i.e., T2 T1
![Page 12: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/12.jpg)
12
T1 T2 Sd cannot be rearrangedinto a serial scheduleSd is not “equivalent” toany serial scheduleSd is “bad”
T2 T1 Also, T1 T2
![Page 13: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/13.jpg)
13
Returning to ScSc=r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
T1 T2 T1 T2
no cycles Sc is “equivalent” to aserial schedule(in this case T1,T2)
![Page 14: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/14.jpg)
14
ConceptsTransaction: sequence of ri(x), wi(x) actions
Conflicting actions: r1(A) w2(A) w1(A) w2(A) r1(A) w2(A)
Schedule: represents chronological order in which actions are executed
Serial schedule: no interleaving of actions or transactions
![Page 15: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/15.jpg)
15
What about concurrent actions?
T1 issues System Input(X) t XRead(X,t) issues completes
Input(X) time
T2 issuesWrite(B,s)
Systemissues
Input(B)
Input(B)completes
B s
Systemissues
Output(B)Output(B)completes
![Page 16: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/16.jpg)
16
So net effect is either
S=…r1(X)…w2(B)… or
S=…w2(B)…r1(X)…
![Page 17: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/17.jpg)
17
Assume equivalent to either r1(A) w2(A)or w2(A) r1(A)
low level synchronization mechanism Assumption called “atomic actions”
What about conflicting, concurrent actions on same object?
start r1(A) end r1(A)
start w2(A) end w2(A) time
![Page 18: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/18.jpg)
18
DefinitionS1, S2 are conflict equivalent schedules
if S1 can be transformed into S2 by a series of swaps on non-conflicting actions.
![Page 19: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/19.jpg)
19
DefinitionA schedule is conflict serializable if it
is conflict equivalent to some serial schedule.
![Page 20: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/20.jpg)
20
Nodes: transactions in SArcs: Ti Tj whenever
there is an action of Ti in S there is an action of Tj later in S both actions are on same database
element and at least one is a write
Precedence graph P(S) (S is schedule)
![Page 21: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/21.jpg)
21
Exercise: What is P(S) for
S = w3(A) w2(C) r1(A) w1(B) r1(C) w2(A) r4(A) w4(D)
Is S serializable?
![Page 22: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/22.jpg)
22
Another Exercise: What is P(S) for
S = w1(A) r2(A) r3(A) w4(A) ?
![Page 23: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/23.jpg)
23
Characterizing Conflict Serializability
Theorem:
A schedule is conflict serializableif and only if
its precedence graph has no cycles.
![Page 24: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/24.jpg)
24
How to enforce serializable schedules?Option 1: run system, recording P(S) at end of day, check for cycles in
P(S) declare execution good if no cycles
else bad
![Page 25: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/25.jpg)
25
Option 2: prevent cycles in P(S) from occurring
T1 T2 ….. Tn
Scheduler
DB
How to enforce serializable schedules?
![Page 26: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/26.jpg)
26
A locking protocol
Two new actions:lock (exclusive): li (A)
unlock: ui (A)
schedulerT1 T2
locktable
![Page 27: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/27.jpg)
27
Rule #1: Well-formed ("consistent") transactions
Ti: … li(A) … pi(A) … ui(A) ...
pi(A) is either a read or a write
![Page 28: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/28.jpg)
28
Rule #2 Legal scheduler
S = …….. li(A) ………... ui(A) ……...
no lj(A)
I.e., only one transaction has a DB elementlocked at any time.
![Page 29: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/29.jpg)
29
What transactions are well-formed?
S1 = l1(A) l1(B) r1(A) w1(B) l2(B) u1(A) u1(B)r2(B) w2(B) u2(B) l3(B) r3(B) u3(B)
S2 = l1(A) r1(A) w1(B) u1(A) u1(B)l2(B) r2(B) w2(B) l3(B) r3(B) u3(B)
S3 = l1(A) r1(A) u1(A) l1(B) w1(B) u1(B)l2(B) r2(B) w2(B) u2(B) l3(B) r3(B) u3(B)
Exercise:
What schedules are legal?
![Page 30: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/30.jpg)
30
Schedule FT1 T2l1(A);Read(A)A A+100;Write(A);u1(A)
l2(A);Read(A)A Ax2;Write(A);u2(A)l2(B);Read(B)B Bx2;Write(B);u2(B)
l1(B);Read(B)B B+100;Write(B);u1(B)
![Page 31: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/31.jpg)
31
Schedule F
T1 T2 25 25l1(A);Read(A)A A+100;Write(A);u1(A) 125
l2(A);Read(A)A Ax2;Write(A);u2(A) 250l2(B);Read(B)B Bx2;Write(B);u2(B) 50
l1(B);Read(B)B B+100;Write(B);u1(B) 150
250 150
A B
![Page 32: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/32.jpg)
32
Rule #3 Two phase locking (2PL)
for transactionsTi = ……. li(A) ………... ui(A) ……...
no unlocks no locks
![Page 33: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/33.jpg)
33
# locksheld byTi
Time Growing Shrinking Phase Phase
![Page 34: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/34.jpg)
34
Schedule GT1 T2l1(A);Read(A)A A+100;Write(A)l1(B); u1(A)
l2(A);Read(A) A Ax2;Write(A);ll22(B)(B)
delayed
![Page 35: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/35.jpg)
35
Schedule G
T1 T2l1(A);Read(A)A A+100;Write(A)l1(B); u1(A)
l2(A);Read(A) A Ax2;Write(A);ll22(B)(B)
Read(B);B B+100Write(B); u1(B)
delayed
![Page 36: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/36.jpg)
36
Schedule GT1 T2l1(A);Read(A)A A+100;Write(A)l1(B); u1(A)
l2(A);Read(A) A Ax2;Write(A);ll22(B)(B)
Read(B);B B+100Write(B); u1(B)
l2(B); u2(A);Read(B) B Bx2;Write(B);u2(B);
delayed
![Page 37: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/37.jpg)
37
Schedule H (T2 reversed)
T1 T2l1(A); Read(A) l2(B);Read(B)A A+100;Write(A) B Bx2;Write(B)ll11(B)(B) l l22(A)(A)
delayeddelayed
Deadlock!
![Page 38: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/38.jpg)
38
Assume deadlocked transactions are rolled back They have no effect They do not appear in schedule
E.g., Schedule H =
This space intentionallyleft blank!
![Page 39: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/39.jpg)
39
Next step:
Show that rules #1,2,3 conflict- serializable schedules
![Page 40: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/40.jpg)
40
Conflict rules for li(A), ui(A):
li(A), lj(A) conflict li(A), uj(A) conflict
Note: no conflict < ui(A), uj(A)>, < li(A), rj(A)>,...
![Page 41: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/41.jpg)
41
2PL Ensures Conflict-Serializability
Theorem:Every schedule produced by two-phase locking, i.e., every read and write is preceded by a
lock and followed by an unlock no DB item is simultaneously locked by
more than one transaction for each transaction, the last lock
precedes the first unlockis conflict-serializable.
![Page 42: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/42.jpg)
42
Beyond this simple 2PL protocol, it is all a matter of improving performance and allowing more concurrency…. Shared locks Increment locks Multiple granularity Other types of concurrency control
mechanisms
![Page 43: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/43.jpg)
43
Shared locksSo far:S = ...l1(A) r1(A) u1(A) … l2(A) r2(A) u2(A) …
Do not conflict
Instead:S=... ls1(A) r1(A) ls2(A) r2(A) …. us1(A) us2(A)
![Page 44: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/44.jpg)
44
Lock actionsl-ti(A): lock A in t mode (t is S or X)u-ti(A): unlock t mode (t is S or X)
Shorthand:ui(A): unlock whatever modes
Ti has locked A
![Page 45: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/45.jpg)
45
Rule #1 Well formed transactionsT1 =... l-S1(A) … r1(A) … u1 (A) …T1 =... l-X1(A) … w1(A) … u1 (A) …
I.e., must hold a shared lock to read and must hold an exclusive lock to write
![Page 46: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/46.jpg)
46
What about transactions that read and write same object?
Option 1: Request exclusive lockT1 = ...l-X1(A) … r1(A) ... w1(A) ... u(A)
…
![Page 47: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/47.jpg)
47
Option 2: Upgrade (E.g., need to read, but don’t know if will write…)
T1=... l-S1(A) … r1(A) ... l-X1(A) …w1(A) ...u(A)…
Think of- Get 2nd lock on A, or- Drop S, get X lock
• What about transactions that read and write same object?
![Page 48: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/48.jpg)
48
Rule #2 Legal schedulerS = ....l-Si(A) … … ui(A) …
no l-Xj(A)S = ... l-Xi(A) … … ui(A) …
no l-Xj(A) no l-Sj(A)
I.e., an element can be locked exclusively by one transaction or by several in shared mode, but not both
![Page 49: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/49.jpg)
49
A way to summarize Rule #2Compatibility matrix
S XS true falseX false false
![Page 50: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/50.jpg)
50
Rule # 3 2PL transactionsNo change except for upgrades:(I) If upgrade gets more locks
(e.g., S {S, X}) then no change!(II) If upgrade releases read (shared)
lock (e.g., S X)- can be allowed in growing phase
![Page 51: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/51.jpg)
51
2PL Ensures Conflict-Serializability With Shared
LocksTheorem:
Every schedule produced by two-phase locking, modified to handle shared locks,is conflict-serializable.
![Page 52: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/52.jpg)
52
Lock types beyond S/XExamples:
(1) increment lock(2) update lock
![Page 53: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/53.jpg)
53
Example (1): increment lock Atomic increment action: INi(A)
{Read(A); A A+k; Write(A)}
INi(A), INj(A) do not conflict!A=7
A=5 A=17A=15
INi(A)+2
INj(A)+10
+10INj(A)
+2INi(A)
![Page 54: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/54.jpg)
54
Compatibility S X IMatrix S
XI
![Page 55: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/55.jpg)
55
Compatibility S X IMatrix S T F F
X F F FI F F T
![Page 56: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/56.jpg)
56
Update locksA common deadlock problem with upgrades:T1 T2l-S1(A)
l-S2(A)l-Xl-X11(A)(A)
l-Xl-X22(A)(A) --- Deadlock ---
![Page 57: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/57.jpg)
57
SolutionIf Ti wants to read A and knows itmay later want to write A, it requestsupdate lock (not shared)
![Page 58: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/58.jpg)
58
Comp. Matrix S X USXU
New request
Lock alreadyheld in
![Page 59: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/59.jpg)
59
Comp. Matrix S X US T F TX F F FU TorF F F
-> symmetric table?
New request
Lock alreadyheld in
![Page 60: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/60.jpg)
60
Note: object A may be locked in different modes at the same time...
S1=...l-S1(A)…l-S2(A)…l-U3(A)… l-S4(A)…? l-U4(A)…? To grant a lock in mode t, mode t must be compatible with all currently held locks on object
![Page 61: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/61.jpg)
61
How does locking work in practice? Every system is different
(E.g., may not even provide CONFLICT-SERIALIZABLE schedules)
But here is one (simplified) way ...
![Page 62: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/62.jpg)
62
(1) Don’t trust transactions torequest/release
locks(2) Hold all locks until transaction
commits#locks
time
Sample Locking System:
![Page 63: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/63.jpg)
63
Ti
Read(A),Write(B)
l(A),Read(A),l(B),Write(B)…
Read(A),Write(B)
Scheduler, part I
Scheduler, part II
DB
locktable
![Page 64: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/64.jpg)
64
Lock table Conceptually
A
BC
...
Lock info for BLock info for C
If null, object is unlockedEv
ery
poss
ible
obj
ect
![Page 65: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/65.jpg)
65
But use hash table:
A
If object not found in hash table, it is unlocked
Lock info for AA
......
H
![Page 66: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/66.jpg)
66
Lock info for A - example tran mode wait? Nxt T_link
Object:AGroup mode:UWaiting:yesList:
T1 S no
T2 U no
T3 XX yes
To other T3 records
![Page 67: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/67.jpg)
67
What are the objects we lock?
?
Relation A
Relation B
...
Tuple ATuple BTuple C
...
Disk block
ADisk block
B
...
DB DB DB
![Page 68: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/68.jpg)
68
Locking works in any case, but should we choose small or large objects?
If we lock large objects (e.g., Relations) Need few locks Low concurrency
If we lock small objects (e.g., tuples,fields) Need more locks More concurrency
![Page 69: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/69.jpg)
69
We can have it both ways!!
Called multi-granularity locking.
![Page 70: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/70.jpg)
70
Optimistic Concurrency Control
Locking is pessimistic -- assumes something bad will try to happen and prevents it
Instead assume conflicts won't occur in the common case, then check at the end of a transaction timestamping validation
![Page 71: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/71.jpg)
71
Timestamping Assign a "timestamp" to each
transaction Keep track of the timestamp of the
last transaction to read and write each DB element
Compare these values to check for serializability
Abort transaction if there is a violation
![Page 72: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/72.jpg)
72
ValidationTransactions have 3 phases:(1) Read
all DB values read writes to temporary storage no locking
(2) Validate check if schedule so far is serializable
(3) Write if validate ok, write to DB
![Page 73: Concurrency Control](https://reader036.vdocument.in/reader036/viewer/2022062309/56815ac8550346895dc89890/html5/thumbnails/73.jpg)
73
Comparison Space usage of optimistic CC is
about the same as locking: roughly proportional to number of DB elements accessed
Optimistic CC is useful when conflicts are rare system resources are plentiful there are real-time constraints