Professional Documents
Culture Documents
CONCURRENCY CONTROL
Hunh Vn Quc Phng
Thi Th Thu Thy
10707010
00707188
CONTENT
Locks
Optimistic concurrency control
Timestamp ordering
Atomicity
Consistency
Isolation
Durability
4
Concurrency control:
TRANSACTION U
balance = b.getBalance( );
b.setBalance(balance*1.1);
a.withdraw(balance/10);
balance = b.getBalance( );
b.setBalance(balance*1.1);
c.withdraw(balance/10);
balance = b.getBalance( );
b.setBalance(balance*1.1);
a.withdraw(balance/10);
$200
$220
$80
$280
Inconsistent retrievals
problem
TRANSACTION V
TRANSACTION W
a.withdraw(100);
b.deposit(100);
aBranch.branchTotal( );
a.withdraw(100);
b.deposit(100);
$100
$300
total = a.getBalance( );
total = total + b.getBalance( );
total = total + c.getBalance( );
.
.
$100
$300
balance = b.getBalance( );
b.setBalance(balance*1.1);
c.withdraw(balance/10);
$200
$220
balance = b.getBalance( ); $220
b.setBalance(balance*1.1); $242
a.withdraw(balance/10);
$80
c.withdraw(balance/10) ;
$278
TRANSACTION W
a.withdraw(100);
b.deposit(100);
aBranch.branchTotal( );
a.withdraw(100);
b.deposit(100);
$100
$300
total = a.getBalance( );
total = total + b.getBalance( );
total = total + c.getBalance( );
.
.
$100
$400
10
Conflict
Read
Read
Write
NO
YES
YES
Read
Write
Write
11
Dirty read
Premature writes
Solutions:
Recoverability of transactions
Avoid cascading aborts
Strict execution of transactions
Tentative versions
12
TRANSACTION U
a.getBalance( );
a.setBalance(balance+10);
a.getBalance( );
a.setBalance(balance+20);
balance = a.getBalance( );
a.setBalance(balance+10);
$100
$110
balance = a.getBalance( );
a.setBalance(balance+20);
commit transaction;
$110
$130
abort transaction;
-Recoverability of transactions: delay commits until after the
commitment of any other transaction whose uncommitted
state has been observed.
-Cascading aborts: the aborting of any transactions may cause
further transactions to be aborted transactions are only
allowed to read objects that were written by committed
transactions.
13
TRANSACTION U
a.setBalance(105);
a.setBalance(110);
a.setBalance(105);
$100
$105
a.setBalance(110);
$110
14
Nested transaction
T: top-level
transaction
T1 = openSubTransaction
openSubTransaction
T2 =
commit
T1
T2
openSubTransaction
openSubTransaction
T11
openSubTransaction
T12
prov.commi
t
abort
T21
openSubTransaction
prov.commi
t
prov.commi
t
T211
prov.commi
t
15
16
17
METHOD FOR
CONCURRENT CONTROL
Lock:
TRANSACTION T
TRANSACTION U
balance = b.getBalance( );
b.setBalance(balance*1.1);
a.withdraw(balance/10);
balance = b.getBalance( );
b.setBalance(balance*1.1);
c.withdraw(balance/10);
openTransaction
balance = b.getBalance( ); lock B
b.setBalance(balance*1.1);
a.withdraw(balance/10);
lock A
openTransaction
balance = b.getBalance( );
closeTransaction
unlock A,B
b.setBalance(balance*1.1);
c.withdraw(balance/10) ;
closeTransaction
wait for
Tlock on B
lock B
lock C
unlock B,C
19
METHOD FOR
CONCURRENT CONTROL
Lock:
20
Lock compatibility
Read
none OK
read OK
write Wait
Lock requested
Write
OK
wait
wait
21
22
METHOD FOR
CONCURRENT CONTROL
Transaction U
Lock
Operations
Lock
write lock A
wait for Us lock
on B
b.deposit(200)
write lock B
a.Withdraw(200)
wait for Ts
lock on A
24
METHOD FOR
CONCURRENT CONTROL
Deadlock:
METHOD FOR
CONCURRENT CONTROL
Deadlock:
26
METHOD FOR
CONCURRENT CONTROL
27
none
read
write
commit
Read
write
commit
OK
OK
OK
Wait
OK
OK
wait
wait
OK
wait
-------
none
read
write
I-read
I-write
Read
Lock to be set
write
I-read
OK
OK
wait
OK
Wait
OK
wait
wait
wait
wait
OK
OK
wait
OK
OK
I-write
OK
wait
wait
OK
OK
29
METHOD FOR
CONCURRENT CONTROL
Drawbacks of locking:
METHOD FOR
CONCURRENT CONTROL
METHOD FOR
CONCURRENT CONTROL
3 phases of a transaction:
32
METHOD FOR
CONCURRENT CONTROL
METHOD FOR
CONCURRENT CONTROL
Timestamp ordering:
No deadlock
34
METHOD FOR
CONCURRENT CONTROL
else
abort transaction Tc
35
METHOD FOR
CONCURRENT CONTROL
if (Dselected is committed)
perform read operation on the version D selected
else
wait until the transaction that made version Dselected
aborts then reapply the read rule
commits or
}
Else
abort transaction Tc
36
METHOD FOR
CONCURRENT CONTROL
37
METHOD FOR
CONCURRENT CONTROL
THE END
Q&A
39