Lecture 9 notes

advertisement
Optimistic Methods for
Concurrency Controlx
Yumin Pan
2015/4/8
EECS 584, Fall 2009
1
Contents
Validation phase
 Validation conditions
 Transaction numbers
 Serial validation
 Parallel validation

2015/4/8
EECS 584, Fall 2009
2
Concurrency
Definition: computations running simulta
neously, and potentially interacting with
each other.
 Transactions should executed serial.
 Two methods to ensure we get the
desired result

– Locking
– Optimistic Concurrency control
2015/4/8
EECS 584, Fall 2009
3
Optimistic Concurrency control
Reading phase
 Validation phase
 Write Phase

Validation phase
If inconsistency detected, roll back and
redo the computation in some other
sequence, and “hope” this time
everything will be fine.
 Otherwise, we go on.
 How can we tell the transaction is
inconsistent?

Inconsistency Transaction
Account A transfer $100 to Account B
 Account A transfer $100 to Account C

Read
Balance A
Read
Balance A
$100
Account A
Account C
$100
Account B
Write
Balance A-100
Write
Balance A-100
BalanceCorrect
A reduced by 100
Serial Equivalence

A criterion to verify the correctness of
execution of transactions
T: transaction
 D: set of all possible result

Validation conditions 1

Two transaction A,B are consistent
– Assume A starts earlier than B

If one finished before another starts
B
A
Validation conditions 2
If the write of the A didn’t influence the
read of B.
 And the B won’t overwrite the result of
the A before A finishes.

A
B
A
Validation conditions 3
The write of A won’t influence the read
and write of B.
 And A finishes read before B finishes
read

B
A
Transaction numbers
Using a counter (tnc) to distinguish
different transactions
 We assign this number at the end of the
read phase.


Ensure condition 3 is always valid
Serial validation
Implementation of condition 1 and 2
 To ensure atomicity

– Before a transaction write back
– We check whether the write sets of
transactions between start tn to finish tn
intersects its read set
– The whole check should be atomic and be
protected by locks

To minimize the critical section, we can
move some work to valid part
Parallel validation
Use all three conditions
 Assign transaction number after the
write phase if validation succeeds.
 To implement condition 3

– Introduce the active set
– Add transaction id to active set after read
phase
– Check whether the write sets of active set
intersects the read or write set of the
current transaction
Thank You !
2015/4/8
EECS 584, Fall 2009
14
Download