190 likes | 210 Views
This paper introduces the Tree Locking Protocol (TLP) for achieving serializability and deadlock freedom in database operations. It presents the protocol's basic rules, properties, and demonstrates its effectiveness through theoretical proofs.
E N D
Tree Locking Protocol Silberchatz and Kedem, JACM, January1980
Database Operations • Ri(x) – Transaction Ti READS data item x. • Wi(x) – Transaction Ti WRITES data item x.
Database Operations - Locks • Transactions may obtain/release locks on data items. • LRi(x) – Ti obtains READ LOCK on x. • LWi(x) – Ti obtains WRITE LOCK on x. • Ui(x) – Ti releases LOCK on x. • lockedi (x,R): LRi (x) issued but Ui (x) not issued yet (Ti has READ LOCK on x). • lockedi (x,W): LWi (x) issued but Ui (x) not issued yet.
Basic Rules • A transaction must hold an appropriate lock in order to issue a database operation: • Ri(x) lockedi(x,R) • Wi(x) lockedi(x,W) • A write lock can not coexist with locks of other transactions:
Simplification • We do not distinguish between READ and WRITE operations. READs behave as WRITEs. Both are ACCESS operations. • W and R are replaced by A. • RL and WL are replaced by L. • The rules become: • Ai(x) lockedi(x)
Notation • Given an execution, we define: • FIRST(A) – First occurrence of operation of type A • LAST(A) – Last occurrence of operation of type A. • - Event B happens after event A. • For a transaction Ti we define: • A(Ti)={The set of data items accessed by Ti} • L(Ti)={The set of data items locked by Ti}
Relation a • Tia Tj if: • Observations: • a is irreflexive • a is anti-symmetric
Serializability-A Sufficient Condition • An execution T such that: • a has no cycles. is serializable. • Proof: • Consider the transitive closure a* of a. • a* has no cycles • W.l.o.g, let T1,T2, … be a possible topologic order. • The serial execution T’ = T1 T2 … is equivalent to T.
Tree Locking Protocol • The data items have a tree hierarchy. • There is a one-to-one correspondence between the data items and the nodes of a tree. • The protocol: • Ai(x) lockedi(x) • A transaction can not lock a data item previously unlocked by it.
Properties of TLP: • Notation: E(Ti) denotes the first node locked by Ti. • Lemma 1: L(Ti) is a connected subgraph of the tree. • Corollary: L(Ti) is a tree, rooted at E(Ti). • Proof (of lemma 1): • Assume by contradiction and there is at least one non-locked node on the path joining them.
Properties of TLP (cont’d) LCA(x,y) • W.l.o.g there is such node between LCA and x. Consider the one which is closest to x and its child (on the path) w. • Ti can not lock LCA(x,y) • Ti can not lock y, a contradiction. y x
Relation w • Tiw Tj if: • Lemma: • w is anti-symmetric. • Proof: • Assume by contradiction that T1w T2, T2w T1. • Consider E(T1) and E(T2). One of them is descendent of the other. Otherwise • W.l.o.g assume E(T2) is descendent of E(T1). • Note that:
w is anti-symmetric • Assume T1 locked E(T2) before T2. • T2w T1, then : • Let l(x) be the distance of x from E(T1). Consider an x such that l(x) is minimum. • x is not E(T1), otherwise E(T1)=E(T2) contradicts our assumption. Therefore, l(x) > 0. • From TLP: • Then: • Consider the time intervals t1, t2 in which locked1(p(x)) and locked2(p(x)) are true.
w is anti-symmetric • t1 and t2 are disjoint. • Li(x) is in ti, ,,therefore t2 precedes t1. • Implying: • But l(p(x)) < l(x), a contradiction. • Now, assume T2 locked E(T2) before T1. • T1w T2, then ….
w is acyclic • Corollary: If Tiw Tj then: • Lemma: w has no cycles. • Proof: • Assume by contradiction that there are cycles. Choose a cycle of minimum possible length k. • Note that k > 2. • Consider all the nodes E(Ti) for Ti in the cycle, there is a partial order on them implied by the tree. • Let v=E(Tj) a minimal element in this partial order. • Both E(Tj-1) and E(Tj+1) are v’s ancestors.
w is acyclic • Consider Tj-1w Tjw Tj+1. • v is in L(Tj-1), L(Tj) and L(Tj+1). • Because of the corollary above, they locked it in the order Tj-1, Tj, Tj+1. • Then Tj-1 locked v before Tj+1: Tj-1w Tj+1. • T1w T2 … Tj-1w Tj+1w … w Tk is a cycle of length k-1, a contradiction.
Serializability under TLP • Theorem: Any execution obeying TLP is rerializable. • Proof: Let T be any execution under TLP. • By definition: • w is acyclic, then a is acyclic. • Part 1 of the sufficient condition is satisfied by by the corollary to the anti-symmetry Lemma. • T is serializable.
Deadlock Freedom of TLP • Theorem: Any execution obeying TLP deadlock free. • Proof: Let T be any execution under TLP, and t any time during the execution. • Consider the “waits for” relation dt • If Tidt Tj then, there is a data item x, for which lockedj(x) and Li(x) is issued (but not granted) as of time t. • Then
Deadlock Freedom of TLP • Then Tiw Tj • dt is acyclic T is deadlock free.