Chapter 18.5: An Architecture for a Locking Scheduler

Download Report

Transcript Chapter 18.5: An Architecture for a Locking Scheduler

Chapter 18.5: An Architecture
for a Locking Scheduler
Loc Nguyen
Class ID: 213
Feb 27, 2008
02/27/2008
Loc Nguyen
1
Overview
 Assume knowledge of:
 Lock
 Two phase lock
 Lock modes: shared, exclusive, update
 Consider a simple scheduler that:
 Insert locks for transaction
 Release locks when told
02/27/2008
Loc Nguyen
2
Two-part Scheduler
transactions
R(A); W(B); COMMIT(T); …
Scheduler, Part I
LOCK(A); R(A); …
Lock
table
Scheduler, Part II
R(A); W(B); …
DB
02/27/2008
Loc Nguyen
3
Semantics of Two-part Scheduler
 Part I: select & insert appropriate lock
modes to db operations (read,write,
or update)
 Part II: take actions (a lock or db
operation) from Part I
 Determine the transaction (T) that action
belongs and status of T (delayed or not)
02/27/2008
Loc Nguyen
4
Semantics (Cont’d)
 If T is delayed, action is delayed and
added to wait list
 If not,
 Action is db operation, to be executed
 Is lock, check lock table
 Granted, update lock table w. granted entry
 Else, update lock table w. lock request;
delay further actions for T until lock granted
02/27/2008
Loc Nguyen
5
Semantics (Cont’d)
 When T is done (commits or aborts),
transaction manager (belongs to T)
notify Part I to release all locks, if
exists waiting lock, Part I notifies Part
II
 Part II when notified, determines next
transaction T’ to get lock to continue.
02/27/2008
Loc Nguyen
6
The Lock Table
Group mode: U
Waiting: yes
List: <pointer>
A
B
02/27/2008
Tran Mode Wait Tnext Next
T1
S
no
T2
U
no
T3
X
yes
T1
S
no
Loc Nguyen
Group modes:
- S: only shared locks
- U: one update lock
and zero or
shared locks
- X: one exclusive lock
and no other locks
7
Handling Lock Requests
Group mode: U
Waiting: yes
List: <pointer>
A
B
02/27/2008
Tran Mode Wait Tnext Next
T1
S
no
T2
U
no
T3
X
yes
T1
S
no
 SL1(A):
 GM=S;W=N
 UL2(A):
 GM=U;W=N
 XL3(A):
 GM=U;W=Y
Loc Nguyen
8
Handling Unlock Requests
Group mode: U
Waiting: yes


T1
S
no
Same as group
mode, no action
Diff; then check
entire list for new
group mode
T2
U
no


List: <pointer>
A
B
Remove entry
Update group mode

Tran Mode Wait Tnext Next


02/27/2008
T3
X
yes
T1
S
no

Update wait if “yes”



Loc Nguyen
S: GM(S) or
nothing
U: GM(S) or
nothing
X: nothing
1st come 1st serve
Prio. shared locks
Prio. upgrading
9
Q&A
 Thank you!
02/27/2008
Loc Nguyen
10