cs257_id215_18.7

advertisement
18.7 THE TREE PROTOCOL
CS 257 – DATABASE SYSTEMS
PRINCIPLES
Presented by:
ASMI SHAH (Class ID: 215)
OUTLINE:

Basics

Motivation for Tree based Locking

Rules for Access to Tree- Structured Data

Why the Tree Protocol works?
BASICS:



18.6 covered the nesting structure of the
database elements, with children being subparts
of the parent.
Here, we have the tree structures formed by the
link pattern of the elements themselves.
Can manage the locks differently from the 2PL
approach.
MOTIVATION FOR TREE BASED LOCKING:
Locking the node is the right level of lock
granularity;
 As locking smaller pieces is not feasible as gain
no benefit,
 Moreover, treating whole B tree as one database
element disturbs the concurrent use of the index.
 Cannot use 2PL as we need to lock the root node
of the B tree, again the root node is not even
always affected, so in that case we don’t need to
lock the root.

RULES FOR ACCESS TO TREE- STRUCTURED
DATA:
1.
2.
3.
4.
A transaction’s first lock may be at any node of
the tree.
Subsequent locks may only be acquired if the
transaction currently has a lock on the parent
node.
Nodes may be unlocked at any time.
A transaction may not relock a node on which it
has released a lock, even if it still holds a lock n
the node’s parent.
WHY THE TREE PROTOCOL WORKS?



Tree protocol forces a serial order on the
transactions involved in a schedule.
Order of precedence: Ti <s Tj, if in schedule S, the
transactions Ti and Tj lock a node in common,
and Ti locks the node first.
If 2 transactions lock several elements in
common, then they are all locked in the same
order.
EXAMPLE:

Transactions T and U lock 2 or more items in
common.
X
T locks First
P
Z
U locks First
Y
U locks First
THE ORDER OF LOCKING:
T locks X first.
 U locks Y before T.
 T locks parent P of Z, before U does.
 T has the lock on P when it locks Z, so U has not
locked P when locks Z.
 Z cannot be the first element that is common
between T and U, as they have common ancestor
X.
 U cannot lock Z before having lock on P as it is
parent to Z, which is after T locks Z.
 Thus, T precedes U at every node they lock in
common.

LONG STORY SHORT!!


If Ti locks the root before Tj, then Ti locks every
node in common with Tj before Tj does. That is Ti
<s Tj, but not Tj <s Ti.
Which states the Tree Protocol.
THANK YOU !!!
Download