Consistency in Database Systems

download Consistency in Database Systems

of 9

Transcript of Consistency in Database Systems

  • 7/29/2019 Consistency in Database Systems

    1/9

    Consistency in Hierarchical Database SystemsA B R A H A M S I L B E R S C H A T Z A N D Z V I K E D E MThe Um veraty of Texas at Dallas, Rwhardson, TexasABSTRACT Th e problem s of locking and consistency m d ataba se systems are exam ined It is assum ed that eachtransac uon , wh en executed alone, t ransform s a consistent sta te into a consistent sta te A set of conditions isderived to guaran tee that whe n transact io ns are processed concurrently, the results are the sam e as would beobta ined by processing the transactm ns serial ly Th ese condit ion s are used to estab hsh a locking protocol inMerarchmal databas e systems Th e locking protocol a l lows transae uon s to request new locks after re leasing alock. However, a da ta i tem m ay be locked at m ost once as a result of each transacUon It ~s sho wn tha t theprotocol ensures consistency and that tt ts deadlock free.KEY WORDS AND PHRASES: da tab as e, conststency , lock , concurren cy, transacU on, mteg rtty, d eadlock , sertahza-bdt tyCR CATEGORIES 4 33, ,4 34

    1 . l n t r o d u c t t o nI n r e c e n t y e a r s t h e r e h a s b e e n a g r o w i n g a w a r e n e s s o f t h e n e e d t o e n s u r e t h e i n t e g r i t y o fd a t a b a s e s y s t e m s t h a t a r e s u b j e c t e d t o m u l t i p l e c o n c u r r e n t u p d a t e a c t iv i t y [4 , 7 , 1 3 1. Ac o m m o n a p p r o a c h t o th e i n te g r i ty p r o b l e m i s t o g r o u p t h e a c t i o n s o f a p r o c e s s i n t os e q u e n c e s c a l l e d t r a n s a c t i o n s w h i c h a r e u n i t s o f c o n s i s t e n c y [4 ]. I t i s a s s u m e d t h a t e a c ht r a n s a c t i o n w h e n e x e c u t e d a l o n e t r a n s f o r m s a c o n s i s t e n t s ta t e i n t o a n e w c o n s i s t e n t st a te ;t h a t is , t r a n s a c t io n s p r e s e r v e c o n s i s te n c y . G i v e n t h a t e a c h t r a n s a c t t o n w h e n e x e c u t e d a l o n ec a n n o t v i o l a t e d a t a b a s e c o n s i s t e n c y , c o n s i s t e n c y i s a s s u r e d i f t h e t o t a l se t o f t r a n s a c t i o n se x e c u t e d i n t h e system s s e r i a l i z a b l e [4 , 7 ]. S e r i a h z a b i l i t y d i c t a t e s t h a t t h e o u t c o m e o fp r o c e s s i n g a l l t h o s e t r a n s a c t io n s i n t h e s e t c o n c u r r e n t l y m u s t b e t h e s a m e a s t h a t p r o d u c e db y r u n n i n g t h e t r a n s a c t i o n s s e r i a l ly i n s o m e o r d e r .

    W h e n n o c o n t r o l is i n d u c e d o n a s y s t e m w h i c h a l lo w s c o n c u r r e n t e x e c u t i o n o f t r a n s a c -t io n s , c o n s i s t e n c y is g e n e r a l l y n o t a s s u r e d . F o r e x a m p l e , c o n s i d e r t h e t w o t r a n s a c t i o n s T ~a n d T 2 d e s c r i b e d b e l o w ( t h i s e x a m p l e i s d u e t o E s w a r a n e t al . [4 ]) :

    T i : A

  • 7/29/2019 Consistency in Database Systems

    2/9

    Consistency in Hierarchical Database Systems 73T i: B

  • 7/29/2019 Consistency in Database Systems

    3/9

    74 A . S I L B E R S C H A T Z A N D Z . K E D E MT h i s p a p e r e x a m i n e s t h e p r o b l e m s o f lo c k i n g a n d c o n s i s t e n c y i n m o r e d e ta i l. I n S e c t i o n

    3 w e d e f m e a " l es s t h a n " r e l a ti o n b e t w e e n p a i r s o f t r a n s a c ti o n s t h a t a c c e s s s o m e c o m m o nv a r i a b le s . G i v e n t h i s re l a t io n , w h i c h i s i r re f le x i v e , a n t i s y m m e t r i c , a n d t r a n s i ti v e , w e p r o v et h a t i f t h is r e l a t i o n h o l d s b e t w e e n e v e r y p a i r o f i n t e r a c t i n g t r a n s a c t i o n s , t h e n t h e s y s t e m i ss e ri a li z ab l e. T h i s " l es s t h a n " r e l a ti o n p r o v i d e s a g e n e r a l m e t h o d f o r d e c i d i n g w h a t k i n d o fl o c k i n g p r o t o c o l s e n s u r e c o n s i s t e n c y . ( F o r e x a m p l e , E s w a r a n ' s r e s u l t s t a t i n g t h a t h i sl o c k i n g p r o t o c o l e n su r e s c o n s i s te n c y f o ll o w s f r o m o u r T h e o r e m 1 .) I n S e c t i o n 4 w e a p p l yo u r r e s u l t to h i e r a r c h ic a l d a t a b a s e s y s te m s . W e t a k e a d v a n t a g e o f t h e s t r u c tu r e o f t h ed a t a b a s e a n d d e f i n e a n e f f i ci e nt l o c k i n g p r o t o c o l w h i c h a l l o w s a t r a n s a c t i o n t o l o c k a d a t ai t e m a f te r r e le a s in g a n o t h e r d a t a i te m . H o w e v e r , a d a t a i t e m m a y n o t b e l o c k e d tw i c e b yt h e s a m e t r a n sa c t to n . W e d e m o n s t r a t e t h a t o u r l o c k in g p r o t o c o l e n s u r e s s e ri a li z ab i li ty a n df r e e d o m f r o m d e a d lo c k s .3 . Genera l Resu l tW e p r o c e e d t o i n v e s t i g a te w h a t c o n d i t i o n s w i l l g u a r a n t e e t h a t a s y s t e m ~s s e r ia l iz a b l e . I no r d e r t o d o s o i t i s n e c e s s a r y t o d e f i n e s e v e r a l t e r m s a n d s t a te s e v e r a l a s s u m p t i o n s .T h e s et o f al l t r a n s a c ti o n s e x e c u t e d b e t w e e n t w o c o n s e c u t i v e q m e s c e n t s t at e s w il l b ed e n o t e d b y T . A s y s t e m i s s a i d t o b e i n a q u i e s c e n t s t at e i f n o t r a n s a c t i o n s a r e b e i n gp r o c e s s e d a t t h a t t i m e . E a c h t r a n s a c t i o n T , i n T a c c e s s e s ( r e t r i e v e s o r / a n d u p d a t e s ) s o m eo f t h e d a t a b a s e v a r i a b l e s a s a r e s u l t o f it s e x e c u t i o n , t h e s e t o f a ll t h e s e v a r i a b l e s i s d e n o t e db y A ( T 3 . W e d e f i n e a r e l a t i o n a C T x T , w h e r e T , a T j ( r e a d s T , p r e c e d e s T ~) i f f

    ( a ) A(T , ) N A(T~) # O , and( b ) f o r e v e r y V E A ( T 0 A A ( T j ), T j a c c e s s e d V f o r t h e f i rs t t im e o n l y a f t e r T~ h a d

    a c c e s s e d V f o r t h e l a s t t im eLEMMA 1. a tS i rre f lex ive an d ant i sym m etr ic (bu t no t necessar i ly transi ttve).THEOREM 1. L e t t h e s et T a_ {T, I i = 0 , 1 . . . . n - 1} o f t h e t r a n sa c t io n s e x e c u t e d b e t w e e n

    two quiesce nt s ta tes sa t i s fy the fo l lo w in g condi tions:(a ) i f i # j and A(T, ) N A ( T j ) # ( ~, then T~ a T j or T~ a T , , a nd(b) the re la t ton a has no cyc les .

    Then T i s ser ta l i zable .P R O O F . L e t a * b e t h e r e f l e x iv e - t r a n s it i v e c l o s u r e o f a . B y a s s u m p t i o n ( b ) a * t sa n t i s y m m e t r i c a n d t h e r e f o r e a p a r t i a l o r d e r . T h u s , T a d m i t s a c o n s i s t e n t e n u m e r a t i o n

    u n d e r a * [1 0]. W i t h o u t l o s s o f g e n e r a l i t y l e t i t b e T o , T 1 . . . . T n - 1 . T h u s , b e c a u s e o fa s s u m p u o n ( a) , a n d b y t h e d e f i n it i o n o f a, t h e o u t c o m e o f th e c o n c u r r e n t e x e c u t i o n i s t h esam e a s t he s e r i a l execu t i on : To , T1 . . . . Tn -1 . [ ]

    T h e r e l a t t o n a + , w h i c h i s t h e t r a n s i t i v e c l o s u r e o f a , I s in f a c t t h e " l e s s t h a n " r e l a t i o nr e f e r r e d t o i n S e c t i o n 2 .T h e a s s u m p t i o n s o f T h e o r e m 1 p r o v i d e a f r a m e w o r k f o r d e c i d i n g u p o n l o c k i n g r u le s i n

    a n e n v i r o n m e n t w h e r e c o n c u r r e n t e x e c u t i o n is p e r m i t te d . T h e s e a s s u m p t i o n s d o n o t s p e c i fyh o w l o c k i n g s h o u l d b e d o n e , b u t r a t h e r p r o v t d e a n i n s i g h t in t o t h is q u e s ti o n . F o r e x a m p l e ,E s w a r a n e t a l. [4 ] d e s c r i b e d a l o c k i n g p r o t o c o l w h i c h r e q u i r e s t h a t a t r a n s a c t i o n c a n n o tr e q u e s t n e w l o c k s a f t e r r e l e a s i n g a l o c k . I t c a n b e s h o w n t h a t t h e i r p r o t o c o l s a t i s f i e s t h ea s s u m p t i o n s o f T h e o r e m 1. I n S e c t i o n 4 a l o c k i n g p r o t o c o l f o r h i e r a r c h i c a l d a t a b a s es y s te m s i s d e s c ri b ed . T h e p r o o f t h a t t h e p r o t o c o l e n s u r e s s e r i a h z a b i li t y f o l lo w s f r o m o u rt h e o r e m .4 . L o c k i n g P r o t o co l f o r H t e ra r c h ic a l D a t a b a s e S y s t e m sI n S e c t i o n 3 w e h a v e d e f i n e d a s e t o f c o n d i t i o n s t o e n s u r e s e r i a li z a b il i ty . W e p r o c e e d n o wt o u s e t h e s e c o n d i t i o n s t o d e f i n e a l o c k i n g p r o t o c o l f o r h i e r a r c h i c a l d a t a b a s e s y s t e m s [ 1 4 ] .W e p r o v e t h a t t h e p r o t o c o l e n s u r e s t h a t a s y s t e m i s s e r i a h z a b l e a n d t h a t i t i s d e a d l o c k f r e e.

  • 7/29/2019 Consistency in Database Systems

    4/9

    Cons t s tency i n H i e rarch ica l D a t abase Sys t em s

    FIG 1

    75

    W e a s s u m e t h a t t h e d a t a b a s e i s p a r t i t i o n e d i n t o s m a l l d i s j o in t u n i t s w h i c h w e r e f e r t o a srecords. T h e r e l a t i o n s h i p b e t w e e n r e c o r d s i s r e p r e s e n t e d b y a t r e e [9 ]. A s u s u a l w e w r i t e X_> Y f o r tw o n o d e s X a n d Y i n t h e t r e e i f a n d o n l y i f X i s a w e a k a n c e s t o r o f Y , n a m e l y , Yo r i ts a n c e s to r . A n e x a m p l e o f a s m a l l d a t a b a s e t r e e is p r e s e n t e d i n F i g u r e 1, w h e r e e a c hnode c o r r e s p o n d s t o a r e c o r d .

    A l o c k i n g a l g o r i t h m f o r a h i e r a r c h i c a l o r g a n i z e d s y s t e m w a s d i s c u s s e d b y G r a y [5 ]. Al o c k is a s s o c i a t e d w i t h e a c h r e c o r d i n t h e t r e e ( r e s t r ic t e d h i e r a r c h y ) . A t r a n s a c t i o n m a yr e q u e s t t o l o c k a p a r t i c u l a r r e c o r d m t h e t re e . O n c e a r e q u e s t i s g r a n t e d , t h e e n t i r e s u b t r e er o o t e d a t t h e r e q u e s t e d l o c k e d r e c o r d i s c o n s i d e r e d t o b e l o c k e d b y t h e t r a n s a c t i o nr e q u e s t i n g t h e l o ck . T h e p r o b l e m i s t o f i n d a t e c h m q u e f o r l m p h c i t l y l o c k i n g a n e n t i r es u b t r e e . I n o r d e r t o l o c k a s u b t r e e r o o t e d a t r e c o r d R i t i s n e c e s s a r y t o p r e v e n t a t r a n s a c t i o nf r o m s u c c e s s f u ll y l o c k i n g t h e a n c e s t o r s o f R w h i l e R i s s t il l b e i n g l o c k e d . G r a y h a sp r o p o s e d a n e w a c c e s s m o d e , c a l l e d intent ion mode, t o " t a g " ( l o c k ) a ll a n c e s t o r s o f a n o d et o b e l o c k e d . T h e s e t a g s s ig n a l t h e f a c t t h a t l o c k i n g i s b e i n g d o n e a t a l o w e r l e v e l a n dt h e r e b y p r e v e n t i m p l i c i t o r e x p h c i t l o c k s o n t h e a n c e s t o r s . T h u s m o r d e r t o l o c k a s u b t r e er o o t e d a t n o d e R o n e m u s t f i rs t l o c k a ll t h e a n c e s t o r s o f R m i n t e n t i o n m o d e a n d o n l y t h e nl o c k n o d e R .

    I n G r a y ' s m o d e l l o c k s a r e r e q u e s t e d i n r o o t t o le a f o r d e r . O n c e a n o d e i s l o c k e d , n of u r t h e r e x p h c i t lo c k i n g i s r e q u i r e d a t l o w e r l e v e ls . L o c k s a r e r e l e a s e d e i t h e r a t t h e e n d o ft h e t r a n s a c t i o n i n a n y o r d e r ( o r i n l e a f to r o o t o r d e r ) . T it/is s c h e m e h a s t h e a d v a n t a g e t h a tf o r c e r ta i n h i e r a r c h i e s t h e n u m b e r o f lo c k s t h a t n e e d t o b e se t m a y b e f a r fe w e r t h a n t h en u m b e r o f n o d e s a c c e s s e d b y t h e l o c k i n g t r a n s a c t i o n . T h i s i s d u e t o th e f a c t t h a t l o c k i n gi s d o n e o n a s u b t r e e b a s i s r a t h e r t h a n o n a r e c o r d b a s i s . O n e d r a w b a c k o f th i s s c h e m e i st h a t i n s o m e c a s e s it m a y r e s u l t i n t h e l o ss o f p o t e n t i a l c o n c u r r e n c y . T h i s i s b e c a u s e o f t h er e q u i r e m e n t t h a t a l l t h e a n c e s t o r s o f a n a c c e s s e d n o d e m u s t b e l o c k e d b y t h e a c c e s s i n gt r a n sa c t io n . T h i s r e q u i r e m e n t m a y a l so r e su l t m u n n e c e s s a r y o v e r h e a d f o r i n te n U o n m o d el o c k i n g i f a t r a n s a c t i o n n e e d n o t s t a r t a c c e s s i n g t h e t r e e a t i ts r o o t . I n t h e f o l l o w i n g w ep r o p o s e a n a l te r n a t iv e t o G r a y ' s l o c k i n g a l g o r it h m i n w h i c h l o c k i n g is d o n e o n a r e c o r db a si s. T h is w i l l e h m i n a t e t h e d r a w b a c k s w e h a v e p o i n t e d o u t i n G r a y ' s s c h e m e . H o w e v e r ,f o r c e r t a i n h i e r a rc h i e s , a g r e a t e r n u m b e r o f lo c k s ( to b e s e t ) m a y b e r e q u i r e d .

    U n d e r o u r s c h e m e , i n o r d e r t o a c c e s s a r e c o r d , a t r a n s a c t i o n m u s t f ir s t l o c k it . I f t h er e c o r d i s a l r e a d y l o c k e d ( b y a n o t h e r t r a n sa c t io n ) , t h e t r a n s a c t i o n w i l l b e s u s p e n d e d . T h es u s p e n d e d t r a n s a c t io n m a y r e s u m e i ts e x e c u t i o n w h e n a n o t h e r t r a n s a c t t o n u n l o c k s th i sr e c o r d . O n l y o n e t r a n s a c t i o n r e s u m e s ~ ts e x e c u t i o n a s a r e s u l t o f a s in g l e u n l o c k i n s t r u c t i o n .

  • 7/29/2019 Consistency in Database Systems

    5/9

    76 A. SILBERSCHATZAND Z. KEDEMWe denote the fact that a transaction T, has issued a LOCK instruction for a record X andhas successfully locked X by writing T, l o c k e d X . Each transaction T~ must select a firstrecord in the database tree to be locked; this first record is denoted by E(T3. The recordsin the subtree with root node E(T,) are the only records that may be locked by transactionT,. Moreover, a transaction may lock a particular record only if its father is currently beinglocked by the transaction. For example, suppose that E(T,) is the node B in the databasetree of Figure 1. T, can only access records B, C, D, E, F, G, H, and I. In order to lockD, T, must first lock the record C; simdarly to lock E it must first lock G.

    A transaction may unlock a particular record after having fimshed accessing that record.We assume that all locked records are unlocked withm a fimte amount of time. (We willshow that our locking protocol is deadlock free.) We also reqmre that a record which hasbeen unlocked by T, is not locked again by the same transaction. These requirements canbe shown to guarantee seriahzabihty. In addition these rules ensure that a system isdeadlock free.Let us illustrate how these locking rules apply to the database tree of Ftgure 1. SupposeE(T,) = B. A particular sequence of LOCK and UNL OCK instructions which follows ourlocking rules isL O C K B ,L O C K C ,L O C K D ,U N L O C K D ,L O C K G ,U N L O C K B ,U N L O C K C,L O C K E ,L O C K F ,U N L O C K G ,U N L O C K F ,U N L O C K E

    The following sequence of LOCKs and UNLOCKs violates our rules since C is lockedtwice by the same transaction:L O C K B ,L O C K C ,U N L O C K C ,L O C K F ,L O C K C ,U N L O C K F ,U N L O C K C

    We now formally present our locking protocol and the results following from it. Wedenote by Eft,) the first node (record) locked by transaction T,. We also say that T, ish o l d i n g a l o c k o n r e c o r d R if and only if the node R was l o c k e d by T, previously and hasnot yet been unlocked.L o c k i n g P r o t o c o l

    (a) T, may lock R # E(T,) if and only if T, is holding a lock on R's father in the databasetree.(b) After unlocking R, T, may not lock it again.(c) T, may access only those nodes on which it is holdmg a lock.It can be easily seen that our locking protocol does not require transactions lockingsome set of nodes to lock these nodes m the same order Moreover, the subgraph of thetree spanned by the nodes of the tree for which a transaction is holding a lock (at some

  • 7/29/2019 Consistency in Database Systems

    6/9

    Cons i s tency i n H t e rarch i ca l D a t abase Sys t em s 77p o i n t m t i m e ) i s n o t n e c e s s a r i l y c o n n e c t e d . A l s o i t i s e v i d e n t t h a t t h e s e t o f a ll th e n o d e sl o c k e d b y a t r a n s a c t io n t h r o u g h o u t t h e e x e c u ti o n is c o n n e c t e d . F u r t h e r m o r e , f o r a n yc o n n e c t e d s u b g r a p h o f th e t r e e t h e r e e x is ts a t r a n s a c t io n o b e y i n g o u r p r o t o c o l w h i c h l o c k se x a c t l y t h o s e n o d e s w h i c h s p a n t h e s u b g r a p h . ( F o r e x a m p l e , a tr a n s a c t i o n m a y l o c k t h en o d e s i n t h e o r d e r i m p o s e d b y a d e p t h - f i r s t s e a r c h o f th e c o n n e c t e d s u b s e t; th e n i t m a yu n l o c k a l l t h e l o c k e d n o d e s . )

    W e n o w e x a m i n e i n g r e a te r d e t a d t h e i n t e ra c t io n s p o s s ib l e a m o n g t h e t r an s a c U o n se x e c u t e d c o n c u r r e n tl y . F o r a t r a n s a c t i o n T , w e d e n o t e b y L ( T , ) th e s e t o f a l l n o d e s o f t h et r e e f o r w h i c h T , i s s u e d a L O C K i n s t r u c t io n .

    W e d e f i n e a r e l a t i on co C T x T w he r e T , co T ~ i f f( a ) L ( T , ) f3 L ( T j ) ~ ~ 3, an d( b ) t h e r e e x i s t s a n o d e V E L ( T , ) 1"3 L ( T j ) s u c h t h a t T , l o c k e d V a n d T ~ e i t h e r n e v e r

    l o c k e d i t o r l o c k e d i t o n l y a f t e r T , u n l o c k e d i t . ( N o t e t h a t i t is ir r e l e v a n t w h e n T j i s s u e d aL O C K V i n s tr u c ti o n .)

    T h e r e l a t i o n co d e s c r i b e s a v e r y w e a k c o n s t r a i n t o n t h e r e l a t i v e in t e r a c t i o n b e t w e e n T ,a n d T j . W e p r o c e e d t o s h o w t h a t i t l m p h e s a m u c h s t ro n g e r " o r d e r i n g " r e l a t i o n

    LEMMA 2. Th e relatton co ts an t tsym m etrtcP R O O F . W i t h o u t l o s s o f g e n e r a l i t y , a s s u m e b y c o n t r a d i c t i o n t h a t T o co T 1, a n d T 1 co T o.

    W e f i r st n o t e t h a t e t t h e r E ( T o ) >_ E ( T ~ ) o r E ( T ~ ) _> E ( T 0 ). I n d e e d , o t h e r w i s e t h e sub t reesr o o t e d a t E ( T 0 ) a n d E ( T 1 ) a r e d i s j o i n t a n d L ( T o ) tq L (T 1 ) = ~3. L e t V ~ m i n ( E ( T o ) ,E ( T 0 } . T h e n i t f o l lo w s t h a t V m u s t b e t h e g r e a t e s t n o d e i n t h e s e t L ( T o ) N L ( T 0 . W i t h o u tl os s o f g e n e r a h t y , a s s u m e t h a t V = E ( To ). D e f i n e n o w :

    0 , T o l o c k e d V b e f o r e T i l o c k e d V ;l =~ 0 , T o l o c k e d V a n d T ~ n e v e r l o c k e d V;

    l , o t h e r w i s e ;a n d j a__ l - i .

    T o r e i t e r a t e ' T , l o c k e d V ; a n d i f t r a n s a c u o n T j e v e r l o c k e d V , i t d i d s o a f t e r T , u n l o c k e dit.

    L e tX l = E ( T , ) , X 2 . . . . . X p = V , . . . . X w

    b e t h e s e q u e n c e o f a l l t h e n o d e s f o r w h i c h T , i ss u e d a L O C K i n s tr u c ti o n . T h e n o d e s a r el i st e d i n t h e o r d e r m w h i c h t h e L O C K i n s t r u c t i o n s w e r e is s u e d . ( I f t = 0 , t h e n p - - 1 .) N o t et h a t T , l o c k e d a t l e a s t t h e n o d e s X ~, X 2, . . . , X w - l . A s T j co T , , i t f o l l o w s t h a t i f

    M & ( m l T j l o c k e d Xm b e f o r e T , l o c k e d i t, o r T , n e v e r l o c k e d Xm }t h e n M # ~ . L e t r = m i n ( M ) . ( N o t e t h a t X r ~s t h e f ir s t e l e m e n t i n t h e s e q u e n c e w h t c h i sa l s o m M , a n d n o t a m i n i m a l e l e m e n t m t h e t re e w h i c h is also i n M . ) B y t h e d e f i n i t io n o ft he p r o t o co l , f o r so m e q , p _< q < r , X q i s t he f a t h e r o f X r i n t he t r ee . A s X q _< V_< E ( T j )i n t h e t r e e , it f o l l o w s t h a t Xq m u s t h a v e b e e n l o c k e d b y T j w h e n i t l o c k e d Xr. B u t , b y t h ed e f i n it z o n o f r, tt a l s o f o ll o w s t h a t T , l o c k e d ( a n d u n l o c k e d ) X q b e f o r e T j l o c k e d i t. T h e r ea r e t w o c a s e s to b e c o n s i d e r e d :

    ( a ) T , l o c k e d Xr. I n t h i s c a s e i t f o l l o w s f r o m Xq _< V_< E ( T 3 t h a t T ~ c o u l d n o t l o c k X rw i t h o u t h o l d i n g a l o c k o n Xq a t t h e s a m e t i m e . A s T j lo c k e d Xq o n l y a f t e r T , u n l o c k e d i t,i t f o l lo w s t h a t T j c o u l d n o t l o c k X r b e f o r e T , u n l o c k e d l t - - a c o n t r a d i c t i o n to t h e f a c t t h a tr ~ M .

    ( b ) T , i s s u e d a L O C K X r i n s t r u c t i o n b u t n e v e r l o c k e d X r I n t h i s c a s e i t f o l lo w s t h a t T ,n e v e r u n l o c k e d Xq a n d t h u s T j n e v e r l o c k e d Xq, a n d t h us n e v e r l o c k e d X r - - a c o n t ra d t ct lo n .

  • 7/29/2019 Consistency in Database Systems

    7/9

    78 A. SILBER SCttATZ AO Z. KEDEStW e h a v e t h u s s h o w n t h a t w e c a n n o t h a v e b o t h T , co T~ a n d T j w T , , a n d L e m m a 2 h a s b e e np r o v e d . [ ]

    COROLLARY 1. I f T , ~o Tj, th en every n ode in L ( T , ) f 3 L ( T j ) which has been locked bybo th T , and T~ was locked b y T , f i rs t .

    P R O O F . I n d e e d , o t h e r w i s e T , w T~ a n d T j w T , , c o n t r a d i c t i n g L e m m a 2 . [ ]W e c a n n o w s u m m a r i z e s o m e c o n s t r a in t s o n t h e r e l a t i v e i n t e ra c t i o n s b e t w e e n t r a n s a c -

    t io n s . F o r a n y t w o t r a n s a c t i o n s T , , T j t h e s e t L ( T , ) N L ( T j ) i s a t r e e ; f u r t h e r m o r e i f T ,l o c k e d t h e r o o t o f th a t t r e e b e f o r e T j d i d , th e n i ts e v e ry n o d e t h a t w a s l o c k e d b y T , a n d T jw a s l o c k e d b t T , f ir st . A n a l g o r i t h m d e v e l o p e d i n d e p e n d e n t l y b y E l l i s [3 ] f o r c o n c u r r e n to p e r a t i o n s o n 2 - 3 t re e s h a s a s i m i l a r f e a tu r e . O v e r s i m p l i f y i n g , a n d u s i n g s o m e o f h e rt e r m i n o l o g y , a wrtter, m i ts r e s t r u c t u r i n g p h a s e , m o v e s a l o n g a p a t h f r o m a l e a f t o th e r o o to f t h e tr e e. F o r t h e s e g m e n t o f s u c h a p a t h c o m m o n t o t w o w r i te r s , i f t h e w r i t e r T , l o c k e dt h e l o w e st n o d e b e f o r e T j d i d , th e n e v e r y n o d e i n t h a t s e g m e n t w a s l o c k e d b y T , b e f o r e T jl o c k e d i t.THEOREM 2. co* , the reflexive-transitive closure o f co, is a g a m a l order.

    P R O O F . T o p r o v e T h e o r e m 2 , i t w i l l s u f fi c e t o s h o w t h a t t h e r e a r e n o c y c l e s o f l e n g t ht w o o r m o r e i n t h e d i r e c t e d g r a p h ( T , co ). L e t T = ( To , T 1 . . . . T n -1 } . W e s h a l l p r o v e b yi n d u c t i o n o n m t h a t t h e r e a r e n o c y c l e s

    T, 0 co T,~, T, 1 co T,~ . . . . T,m_ co T, oo f l e n g t h m > 2 .

    m = 2. F o l l o w s i m m e d i a t e l y f r o m L e m m a 2 .m = 3 . A s s u m e b y c o n t r a d i c t i o n , w ~ t h o u t l o s s o f g e n e r a h t y , t h a t

    To w T1, T1 w T2, T2 co To.W a h o u t l o s s o f g e n e r a l i t y , l e t V = E ( T ~) b e m i n i m a l m t h e s e t {E ( To ), E ( T i ) , E ( T 2 ) ) I tf o l l ow s t ha t E ( T o) > E ( T ~ ) an d E ( T 2) _> E ( T ~ ) . A s T o w T a an d E ( T 0) _> V , i t f o l l ow s byC o r o l l a r y 1 t h a t T o l o c k e d V b e f o r e T ~ lo c k e d i t. A s T i co T 2 a n d E ( T 2 ) >_ V , i t f o l l o w s t h a tT ~ l o c k e d V b e f o r e T 2 c o u l d l o c k i t. T h u s T o l o c k e d V b e f o r e T 2 c o u l d . ( W e h a v e n o ts h o w n t h a t T 2 e v e n l o c k s V; w e k n o w t h o u g h t h a t i t h a s i s s u e d a L O C K i n s t ru c t i o n f o r a . )T h u s b y t h e d e f i n i t i o n o f co, T o co T 2. W e n o w h a v e

    To co T2, I"2 co To,a c y c l e o f l e n g t h 2 , c o n t r a & c t i n g t h e i n d u c t i o n h y p o t h e s i s.

    m > 3 . A s s u m e b y c o n t r a d i c t i o n , w i t h o u t l o ss o f g e n e r a l i ty , t h a tTo co T1, T l co I "2 . . . T ~ - I co To.

    L e t V & E ( T , ) b e a m i n i m a l n o d e i n t h e s e t { E (T o ), E( T ~ ) . . . . E ( T ~ - ~ ) ) . A s T ,- ~ co T , a n dT ~ co T ~ ~, w e a g a i n n o t e t h a t E ( T , - ~ ) > _ E ( T , ) a n d E ( T ,+ ~ ) >_ E ( T 0 . ( A l l i n d i c e s a r e m o d u l om . ) W e a l s o k n o w t h a t b o t h T , - ~ a n d T ~+~ i s s u e d a L O C K V m s t r u c U o n . T h e r e a r e t w oe a s e s to b e c o n s i d e r e d .

    ( a ) N e i t he r T , - ~ no r T ~+ ~ ev e r l oc ks V . W e f i r s t no t e t ha t a s T , _ i co T ~ an d T , + ~ co T ~+ 2,i t f o l lo w s b y t h e d e f m a i o n o f co t h a t e a c h o f t h e m l o c k e d a t l e as t o n e n o d e m t h e t r ee . I tf o ll o w s t h u s t h a t w h i le b o t h o f t h e m w e r e w a i t i n g t o l o c k V a f t e r t h e y h a d i s su e d a L O C Kf o r it , t h e y w e r e h o l d i n g a l o c k o n V ' s f a t h e r i n t h e t r ee , w h i c h i s ~ m p o s s ib l e . T h u s ac o n t r a d i c t i o n i s r e a c h e d .

    ( b ) A t le a s t o n e o f T ,- ~ , T ,+ ~ l o c k e d V ( a n d p o s s i b l y u n l o c k e d i t) . T h e n a s b o t h o ft h e m i s s u e d a L O C K f o r it , i t f o l l o w s b y t h e d e f i m t i o n o f w t h a t e i t h e r T , -1 co T , + i o rT ,+ ~ w T , -1 . I n t he f i r s t c a se ,

  • 7/29/2019 Consistency in Database Systems

    8/9

    C ons i s t ency i n H ie rarch i ca l Da tabase Sys t ems 79To ~o T1 . . . . . T~-1 ~o T ,+ i . . . . Tm-1 ~o To,

    a c y c le o f l e n g t h m - 1 < m i s o b t a i n e d ; a n d i n t h e s e c o n d c a s e ,T, -1 ~o T, , T , w T~+i , T,+ i oo T,-1 ,

    a c y c l e o f l e n g t h 3 < m i s o b t a i n e d . T h i s c o n t r a d i c t s t h e i n d u c t i o n h y p o t h e s i s . [ ]LEM MA 3. C~ C co. (Th i s means t ha t T , cz T2 impl ies T , ~o Tj .)P R O O F . L e t t a n d j b e s u c h t h a t T , a T j . T h i s i m p l i e s t h a t f o r a t l e a s t o n e v a r i a b l e v

    l o c a t e d a t s o m e n o d e V , T , a n d T j b o t h a c c e s s e d v , b u t t h e f i r st a c c e s s b y T 2 o c c u r s a f t e rt h e l a s t a c c e s s b y T , . B u t t h e n o f c o u r s e T~ l o c k e d a n d u n l o c k e d V b e f o r e T j l o c k e d i t. T h u sby t h e de f i n i t i on o f ~0, T , ~0 T j . [ ]

    COROLLARY 2. T Is seria lizable .PR OO F. I t i s s u f f i c ie n t t o s h o w t h a t t h e t w o a s s u m p t i o n s ( a ) a n d ( b ) o f T h e o r e m 1 a r e

    sa t i s f i ed .( a ) L e t t a n d j b e s u c h t h a t t # j a n d A ( T , ) N A ( T j ) # O . L e t v E A ( T , ) N A (T ~) , a n d l e t

    v b e l o c a t e d i n s o m e n o d e V . T h e n V E L ( T , ) N L ( T , ), a n d e i t h e r T~ l o c k e d a n d u n l o c k e dV b e f o r e T 2 l o c k e d i t , o r T j l o c k e d a n d u n l o c k e d V b e f o r e T , l o c k e d i t. W i t h o u t l o s s o fg e n e r a l i t y , a s s u m e t h a t t h e f i r s t c a s e h o l d s . T h e n b y t h e d e f i n i t i o n o f ~o, T , ~o T j ; a n d b yC o r o l l a r y l it i m m e d i a t e l y f o l l o w s t h a t f o r every v a r i a b l e w E A ( T , ) N A ( T j ) , t h e f i r s ta c c e s s o f w b y T j o c c u r s a f t e r t h e l a s t a c c e s s b y T ~. T h u s b y t h e d e f i n i t i o n o f a , T ~ c~ T j .

    ( b ) A s s u m e b y c o n t r a d i c t i o n th a t t h e r e ex i st s a c y c le i n th e g r a p h ( T , a ) . A s , b y L e m m a3 , ( T , c 0 i s a p a r t i a l s u b g r a p h o f ( T , ~ 0 ), a c y c l e e x i s t s i n t h e g r a p h ( T , ~ o), c o n t r a d i c t i n gT h e o r e m 2 . T h u s , t h e r e a r e n o c y c l e s u n d e r t h e r e l a t i o n c~. [ ]

    COROL LARY 3. ./f sy s t em opera t ing under our l ock ing p ro toco l i s dead lo ck f r ee .P R O O F . F o r a p o i n t t i n t i m e d e f i n e a r e l a t i o n 8 t C_ T x T , w h e r e T~ 8 t T 7 l f f a t t i m e t,

    T , is h o l d i n g a l o c k o n X , a n d T j h a s i s s u e d L O C K X b u t d i d n o t l o c k it b y ti m e t . ( A t t i m et, T j i s w a i t i n g t o l o c k a n o d e o n w h i c h T , is h o l d i n g a l o c k . ) A s s u m e b y c o n t r a d i c t i o n t h a tt h e s y s t e m i s d e a d l o c k e d a t ti m e s . T h e n , w i t h o u t l o ss o f g e n e r a h t y , f o r s o m e m > 1 t h e r eex i s t s a cyc l e

    To 8 , T1 , T1 8 , T2 . . . . Tm-1 8 , To.B u t , b y t h e d e f i n i t t o n s o f 8 , a n d ~o, i t f o l l o w s t h a t 8 s C ~o a n d t h u s

    To ~o T1, T1 ~o T2 . . . . Tm-1 ~o To,c o n t r a d i c t in g T h e o r e m 2 . [ ]5. ConclusionW e h a v e p r e s e n t e d r e s u l t s c o n c e r n i n g c o n s i s t e n c y i n d a t a b a s e s y s t e m s . I t w a s a s s u m e dt h a t e a c h t r a n s a c t i o n , w h e n e x e c u t e d a l o n e , t r a n s f o r m s a c o n s i s t e n t s t a t e i n t o a c o n s i s t e n ts ta t e. A s e t o f c o n d m o n s w a s d e r i v e d t o g u a r a n t e e t h a t w h e n t r a n s a c t io n s a r e p r o c e s s e dc o n c u r r e n t l y , th e r e s u l ts a r e th e s a m e a s w o u l d b e o b t a i n e d b y p r o c e s s i n g th e t r a n s a c t i o n ss e r ia l ly . T h e s e c o n d i t i o n s w e r e u s e d t o e s t a b h s h a l o c k i n g p r o t o c o l i n h i e r a r c h i c a l d a t a b a s es y s t em s . I t w a s s h o w n t h a t t h e p r o t o c o l e n s u r e s c o n s i s t e n c y a n d t h a t i t i s d e a d l o c k fr e e .T h e p r o p o s e d l o c k i n g p r o t o c o l c a n b e i n t e r p r e t e d i n t w o d i f fe r e n t w a y s. F i r s t , th e t r e es t r u c t u r e i m p o s e d o n r e c o r d s i s a l o g i c a l w e w o f t h e r e c o r d s t r u c t u r e . T h a t i s , i t p r o v i d e sa s y s te m a t ic w a y f o r d e c i d in g h o w a t r a n s a c ti o n s h o u ld L O C K a n d U N L O C K r e co r d s, sot h a t c o n s i s te n c y is p r e s e r v e d a n d n o d e a d l o c k s m a y o c c u r . S e c o n d , t h e t r e e s t r u c tu r e i s ap h y s i c a l s t r u c t u r e i n w h i c h p o i n t e r s ( e x p l i c i t o r i m p l i c i t ) f r o m o n e r e c o r d t o a n o t h e r e x i s t.I n t h i s ca s e o u r l o c k i n g p r o t o c o l p r o v i d e s a g u i d e l i n e a s to h o w o n e s h o u l d t r a v e rs e a t r e es o t h a t c o n s i s t e n c y i s e n s u r e d .

  • 7/29/2019 Consistency in Database Systems

    9/9

    80 A. SILBERSCHATZ AND Z. KEDEMS i n c e t h e r e l a t i o n s h i p b e t w e e n r e c o rd s i s r e p r e s e n t e d b y a t re e , o n e m a y h o p e t h a t h i g h -

    l ev e l m e c h a n i s m s c a n b e p r o v i d e d fo r a u t o m a t i c L O C K i n g a n d U N L O C K i n g o f r e c o rd s .T h a t i s , a p r o g r a m m e r w r i t i n g t h e d e f i n i t i o n o f a t r a n s a c t i o n n e e d n o t s p e c i f y h o w t h es e t t in g a n d r e s e t t i n g o f l o c k s s h o u l d b e d o n e . I n s t e a d , a c o m p i l e r m i g h t g e n e r a t e f o r e a c ht r a n s a c t i o n d e f in i t i o n th e a p p r o p r i a te s e q u e n c e o f L O C K s a n d U N L O C K s . T h i s q u e s t i o n ,h o w e v e r , i s b e y o n d t h e s c op e o f th i s p a p e r a n d w i l l b e e x a m i n e d s e p a ra t e ly .A CK NO W LE DG ME NT . W e a c k n o w l e d g e t h e s u g g e s t i o n s a n d h e l p f u l c r i t i c i s m g i v e n b yJ e f f r e y U U m a n .R E F E R E N C E S

    1 CHAMBERLIN, D D , BOYCE, R F , AND TRAIGER, I L A deadlock-free scheme for resource locking in ada tabase envi ro nm ent Inform at ion Processing 74, No rth-Ho l land Pub. C o, Am ste rdam, 1974, pp 340-3432 COFFMAN, E , ELPHICK, M , AND SHOSHANI, A System deadlocks Comptng Surveys3 , 2 ( J u n e 1 9 7 1 ), 6 7 - 7 83 ELLIS,C S . Con current sea rch and m ser t ton m 2-3 t rees. Tech Rep No 78-05-01, U . of W ashington, Seat tle,W a sh , Ma y 1978 .4 ESWARAN,K P , GRAY, J N , Lo am , R A , AND TRAIGER, I L Th e notion s of consistency and predicate locksin a data bas e system Cumin ACM 19, 11 (Nov. 197 6), 624---633.5 . GRAY, J .N . Notes on da tabase opera t ing systems Res Rep RJ 2188, IBM Research L ab , San Jose , Ca li f. ,F e b 19786. GRAY, J. N , LORIE, R A., AND PUTZOLU, G R Gr anu lari ty of locks in a share d datab ase Proc lnt ern at

    Conf . on Very Large Data Bases, Fram lngham , M ass , Sept 1975, pp 428-451 (Ava i lable f rom AC M, NewYork.)7 GR AY , .N., LORIE, R.A ., PUTZOLU,G .R , A N D TRAIGER, | L Gr anu lari ty of locks an d degrees of consistencym a sha re d da ta ba se P roc IF IP W ork i ng Conf on M ode l ing o f D a t a Ba se M a na ge me n t S ys te ms,Freudens tadt , Germ any, Jan 1976, pp 695-7238. KING, P F , AND COLLMEYER, A J D a t a ba se sha nn g- - a n e f fi ci en t m e e ha msm fo r suppor t ing c onc ur re n tprocesses. Proc AF IPS 1973 NCC , Vol. ,12, AF IPS Press, Arh ngto n, Va., pp 271-2759 KNUTH, D E The Art of Computer Programming, Vol 1 Addison-Wesley, Reading, Mass, 196810 PREPARATA,F. P, AND YEH, R T. Introductwn to Discrete Structures. Addison-Wesley, Read mg, M ass , 197311 RIES, D R , AND STONEBRAKER, M Effec ts of locking granu la r i ty m a da tabas e manag em ent sys tem A CMTrans Database Syst. 2, 3 (Sept 1977), 233-246.12 ROSENKRANTZ,n J, STEARNS, R E., AND LEWIS, P M II System level conc urren cy contro l for d~stnbn tedda tabase systems AC M Trans. Database Syst. 3, 2 (Ju ne 1978), 178-198,13. STEARNS, R E., LEW IS, P M II, AND ROSENKRANTZ, D J Co ncu rren cy con tro l for da tab ase sy stems Pro cIEEE Sy mp on Fou nda t ions of Com pute r Science , Houston, Texas , Oc t 1976, pp 19-3214 TSICHRITZIS, D .C , AND LOCHOVSKY, F.H Hierarchical dat ab ase m an ag em en t Comptng Surveys 8, 11(M arch 1976), 105-123.RECEIVED APRIL 197 8, REVISED JANUARY 1 979

    Journal ofth e Association or Comp utm Machinery,Vol 27, No l, January 1980