18.7 – The Tree Protocol CS257 Spring 2011 Prof TYLin By Ming-Chen Tsai
Motivation for Tree-Based Locking B-tree – treat individual nodes as lockable elements. Almost impossible for concurrent use with shared or exclusive lock modes, with update locks, and 2PL locking. Every transaction worries about rewriting root.
Motivation for Tree-Based Locking But most of the time, tree-node is not rewritten even if insertion/deletion of tuple is involved. Specialized protocol releases root lock as soon as transaction moves down. (Even though this violates 2PL) (2PL = All lock actions precede all unlock actions.)
Rules for Access to Tree- Structured Data Tree Protocol – 4 rules 1. First lock can be any node. 2. Acquire subsequent lock only if transaction already have parent’s lock. 3. Unlock any node anytime. 4. Cannot relock a node previously locked, even if holding parent’s lock.
Rules for Access to Tree- Structured Data T1: A => B => C => D (Non 2PL) T2: B => E (denied: lock by T3 on E; 2PL) T3: E => F => G (Non 2PL) A A B B C C D D E E F F G G
Why the Tree Protocol Works T1T2T3 L1(A); R1(A); L1(B); R1(B); L1(C); R1(C); W1(A); U1(A); L1(D); R1(D); W1(B); U1(B); L2(B); R2(B); L3(E); R3(E); W1(D); U1(D); W1(C); U1(C); L2(E) Denied L3(F); R3(F); W3(F); U3(F); L3(G); R3(G); W3(E); U3(E); L2(E); R2(E); W3(G); U3(G); W2(B); U2(B); W2(E); U2(E);
Why the Tree Protocol Works 10 Transactions T1,T2,…T9, TA T1,T2,T3 lock the root Root left child locked by: T1-T7 Root right chold locked by:T2,T3,T8,T9,TA Let serial order of first subtree be (T4,T1,T5,T2,T6,T3,T7) Second tree (T8,T2,T9,TA,T3) Possibly (T4,T8,T1,T5,T2,T9,T6,TA,T3,T7) A A 7 7