Optimistic Concurrency Control
April 13, 2017
1
Optimistic Concurrency Control April 13, 2017 1 Serializability - - PowerPoint PPT Presentation
Optimistic Concurrency Control April 13, 2017 1 Serializability Executing transactions serially wastes resources Interleaving transactions creates correctness errors Give transactions the illusion of isolation 2 Serializability Read Read
April 13, 2017
1
Give transactions the illusion of isolation Executing transactions serially wastes resources Interleaving transactions creates correctness errors
2
Commit Abort
Time
Read Read Read Write Write
3
Preserve order of reads, writes across transactions
4
Option 1: Avoid situations that break the illusion
5
Lock an object before reading or writing it Unlock it after the transaction ends This is pessimistic!
6
Not allowed! T2 has to wait!
7
incurred even if no conflicts ever actually occur!
an xact will do, so can’t allow all schedules.
8
We don’t know what a transaction will do until it does.
9
So let the transaction do it.
(Then check if it broke anything later)
10
private copy of all accessed objects.
to updated objects public.
11
Commit Abort
Time
Read Read Read Write Write
12
Commit Abort
Time
Read Read Write Write Read Set Write Set Read
13
ReadSet(Ti): Set of objects read by Ti. WriteSet(Ti): Set of objects written by Ti.
14
Pick a serial order for the transactions (e.g., assign id #s or timestamps) When should we assign Transaction IDs? (Why?)
15
What tests are needed?
16
For all i and k for which i < k, check that Ti completes before Tk begins.
Is this sufficient? Is this efficient?
17
For all i and k for which i < k, check that Ti completes before Tk begins its write phase AND WriteSet(Ti) ⋂ ReadSet(Tk) is empty
How do these two conditions help?
18
For all i and k for which i < k, check that Ti completes its read phase first AND WriteSet(Ti) ⋂ ReadSet(Tk) is empty AND WriteSet(Ti) ⋂ WriteSet(Tk) is empty
How do these three conditions help?
19
20
Which test (or tests) should we use? Hint: How would you implement each test?
parts of the write phase are a critical section.
need a critical section (no write phase).
21
writeset (sets are expensive to allocate/destroy)
22
write timestamp (WTS)
start.
preserved.
23
version.
24
25
26
quite 2PL.
27
Can we avoid read after write conflicts?
28
copy, while readers use an appropriate “old” copy.
allowed to proceed.
blocked until a writer commits.
29
interest”.
each object that it interacts with.
30
31
Writer Timeline
V with WTS = RTS = TS(T).
transactions can see TS values.
32