Consistency in Hierarchical Database Systems - Association for

4 downloads 0 Views 552KB Size Report
T1 now is waiting for T2 to UNLOCK B and T2 is waiting for T1 to UNLOCK A. Thus ... requirement that transactions do not lock and unlock the database entities ...
Consistency in Hierarchical Database Systems A B R A H A M SILBERSCHATZ A N D ZVI KEDEM

The Umveraty of Texas at Dallas, Rwhardson, Texas ABSTRACT The problems of locking and consistency m database systems are examined It is assumed that each transacuon, when executed alone, transforms a consistent state into a consistent state A set of conditions is derived to guarantee that when transactions are processed concurrently, the results are the same as would be obtained by processing the transactmns serially These conditions are used to estabhsh a locking protocol in Merarchmal database systems The locking protocol allows transaeuons to request new locks after releasing a lock. However, a data item may be locked at most once as a result of each transacUon It ~s shown that the protocol ensures consistency and that tt ts deadlock free. KEY WORDSAND PHRASES: database, conststency, lock, concurrency, transacUon, mtegrtty, deadlock, sertahzabdtty CR CATEGORIES 4 33, ,4 34

1. lntroductton I n recent years 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 to e n s u r e the integrity o f d a t a b a s e systems t h a t are s u b j e c t e d to m u l t i p l e c o n c u r r e n t u p d a t e activity [4, 7, 131. A c o m m o n a p p r o a c h to t h e integrity p r o b l e m is to g r o u p t h e a c t i o n s o f a process i n t o s e q u e n c e s called transactions w h i c h are u n i t s o f c o n s i s t e n c y [4]. It is a s s u m e d t 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 state i n t o a n e w c o n s i s t e n t state; t h a t is, t r a n s a c t i o n s p r e s e r v e consistency. 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 e c a n n o t violate d a t a b a s e consistency, c o n s i s t e n c y is a s s u r e d i f t h e t o t a l set o f t r a n s a c t i o n s e x e c u t e d i n t h e system is serializable [4, 7]. S e r i a h z a b i l i t y dictates t h a t t h e o u t c o m e o f processing all t h o s e t r a n s a c t i o n s in t h e set 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 as t h a t p r o d u c e d b y r u n n i n g t h e t r a n s a c t i o n s serially i n s o m e order. 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 allows 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 tions, consistency is g e n e r a l l y n o t assured. F o r e x a m p l e , c o n s i d e r t h e two t r a n s a c t i o n s T~ a n d T2 d e s c r i b e d b e l o w (this e x a m p l e is d u e to E s w a r a n et al. [4]): Ti:

A 2. m = 2.

Follows immediately from Lemma 2.

m = 3.

Assume by contradiction, w~thout loss o f generahty, that To w T1,

T1 w T2,

T2 co To.

W a h o u t loss of generality, let V = E(T~) be minimal m the set {E(To), E(Ti), E(T2)) It follows that E(To) > E(T~) and E(T2) _> E(T~). As To w Ta and E(T0) _> V, it follows by Corollary 1 that To locked V before T~ locked it. As Ti co T2 and E(T2) >_V, it follows that T~ locked V before T2 could lock it. Thus To locked V before T2 could. (We have not shown that T2 even locks V; we know though that it has issued a L O C K instruction for a.) Thus by the definition of co, To co T2. We now have To co T2,

I"2 co To,

a cycle o f length 2, contra&cting the induction hypothesis. m > 3.

Assume by contradiction, without loss o f generality, that To co T1, Tl co I"2. . . .

T~-I co To.

Let V & E(T,) be a minimal node in the set {E(To), E(T~) . . . . . E(T~-~)). As T,-~ co T, and T~ co T~÷~, we again note that E(T,-~) >_ E(T,) and E(T,+~) >_ E(T0. (All indices are modulo m.) We also know that both T,-~ and T~+~ issued a L O C K V mstrucUon. There are two eases to be considered. (a) Neither T,-~ nor T~+~ ever locks V. W e first note that as T,_i co T~ and T,+~ co T~+2, it follows by the defmaion o f co that each o f them locked at least one node m the tree. It follows thus that while both o f them were waiting to lock V after they had issued a L O C K for it, they were holding a lock on V's father in the tree, which is ~mpossible. Thus a contradiction is reached. (b) At least one o f T,-~, T,+~ locked V (and possibly unlocked it). Then as both of them issued a L O C K for it, it follows by the defimtion of w that either T,-1 co T,+i or T,+~ w T,-1. In the first case,

Consistency in Hierarchical Database Systems

79

To ~o T1 . . . . . T~-1 ~o T,+i . . . . . Tm-1 ~o To, a cycle of length m - 1 < m is obtained; and in the second case, T,-1 ~o T,,

T, w T~+i,

T,+i oo T,-1,

a cycle of length 3 < m is obtained. This contradicts the induction hypothesis.

[]

C~C co. (This means that T, cz T2 implies T, ~o Tj.)

LEMMA 3.

PROOF. Let t and j be such that T, a Tj. This implies that for at least one variable v located at some node V, T, and Tj both accessed v, but the first access by T2 occurs after the last access by T,. But then of course T~ locked and unlocked Vbefore Tj locked it. Thus by the definition of ~0, T, ~0 Tj. [] COROLLARY 2. PROOF. satisfied.

T Is serializable.

It is sufficient to show that the two assumptions (a) and (b) o f Theorem 1 are

(a) Let t and j be such that t # j and A(T,) N A(Tj) # O. Let v E A(T,) N A(T~), and let v be located in some node V. Then V E L(T,) N L(T,), and either T~ locked and unlocked V before T2 locked it, or Tj locked and unlocked V before T, locked it. Without loss of generality, assume that the first case holds. Then by the definition of ~o, T, ~o Tj; and by Corollary l it immediately follows that for every variable w E A(T,) N A(Tj), the first access of w by Tj occurs after the last access by T~. Thus by the definition of a, T~ c~ Tj. (b) Assume by contradiction that there exists a cycle in the graph (T, a). As, by Lemma 3, (T, c0 is a partial subgraph of (T, ~0), a cycle exists in the graph (T, ~o), contradicting Theorem 2. Thus, there are no cycles under the relation c~. [] COROLLARY 3.

./f system operating under our locking protocol is deadlock free.

PROOF. F o r a point t in time define a relation 8t C_ T x T, where T~ 8t T7 lff at time t, T, is holding a lock on X, and Tj has issued L O C K X but did not lock it by time t. (At time t, Tj is waiting to lock a node on which T, is holding a lock.) Assume by contradiction that the system is deadlocked at time s. Then, without loss of generahty, for some m > 1 there exists a cycle To 8, T1, T1 8, T2 . . . . . Tm-1 8, To. But, by the definittons of 8, and ~o, it follows that 8s C ~o and thus To ~o T1, T1 ~o T2. . . . . Tm-1 ~o To, contradicting Theorem 2.

[]

5. Conclusion We have presented results concerning consistency in database systems. It was assumed that each transaction, when executed alone, transforms a consistent state into a consistent state. A set of condmons was derived to guarantee that when transactions are processed concurrently, the results are the same as would be obtained by processing the transactions serially. These conditions were used to estabhsh a locking protocol in hierarchical database systems. It was shown that the protocol ensures consistency and that it is deadlock free. The proposed locking protocol can be interpreted in two different ways. First, the tree structure imposed on records is a logical wew of the record structure. That is, it provides a systematic way for deciding how a transaction should L O C K and U N L O C K records, so that consistency is preserved and no deadlocks may occur. Second, the tree structure is a physical structure in which pointers (explicit or implicit) from one record to another exist. In this case our locking protocol provides a guideline as to how one should traverse a tree so that consistency is ensured.

80

A. SILBERSCHATZ AND Z. KEDEM

Since t h e r e l a t i o n s h i p b e t w e e n records is r e p r e s e n t e d b y a tree, o n e m a y h o p e t h a t h i g h level m e c h a n i s m s c a n b e p r o v i d e d for 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 records. T h a t is, a p r o g r a m m e r w r i t i n g the 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 specify h o w t h e setting a n d resetting o f locks 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 for e a c h transaction definition the appropriate sequence of LOCKs and UNLOCKs. This question, h o w e v e r , is b e y o n d t h e scope o f this p a p e r a n d will b e e x a m i n e d separately. ACKNOWLEDGMENT. Jeffrey U U m a n .

W e a c k n o w l e d g e t h e suggestions a n d h e l p f u l criticism g i v e n b y

REFERENCES 1 CHAMBERLIN, D D , BOYCE, R F, AND TRAIGER, I L A deadlock-free scheme for resource locking in a

database environment Information Processing 74, North-Holland Pub. Co, Amsterdam, 1974, pp 340-343 2 COFFMAN, E , ELPHICK, M , AND SHOSHANI, A System deadlocks Comptng

Surveys3, 2 (June

1971), 6 7 - 7 8

3 ELLIS,C S. Concurrent search and msertton m 2-3 trees. Tech Rep No 78-05-01, U. of Washington, Seattle, Wash, May 1978. 4 ESWARAN,K P, GRAY,J N, Loam, R A, ANDTRAIGER, I L The notions of consistency and predicate locks in a database system Cumin ACM 19, 11 (Nov. 1976), 624---633. 5. GRAY,J.N. Notes on database operating systems Res Rep RJ 2188, IBM Research Lab, San Jose, Calif., Feb 1978 6. GRAY, J.N, LORIE, R A., AND PUTZOLU, G R Granularity of locks in a shared database Proc lnternat Conf. on Very Large Data Bases, Framlngham, Mass, Sept 1975, pp 428-451 (Available from ACM, New York.) 7 GRAY,J.N., LORIE,R.A., PUTZOLU,G.R, ANDTRAIGER, | L Granularity of locks and degrees of consistency m a shared database Proc IFIP Working Conf on Modeling of Data Base Management Systems, Freudenstadt, Germany, Jan 1976, pp 695-723 8. KING, P F, AND COLLMEYER, A J Database shanng--an efficient meehamsm for supporting concurrent processes. Proc AFIPS 1973 NCC, Vol. ,12, AFIPS Press, Arhngton, Va., pp 271-275 9 KNUTH,D E The Art of Computer Programming, Vol 1 Addison-Wesley, Reading, Mass, 1968 10 PREPARATA,F.P, ANDYEH, R T. Introductwn to Discrete Structures. Addison-Wesley, Readmg, Mass, 1973 11 RIES, D R, AND STONEBRAKER, M Effects of locking granularity m a database management system A CM Trans Database Syst. 2, 3 (Sept 1977), 233-246. 12 ROSENKRANTZ,n J, STEARNS,R E., AND LEWIS, P M II System level concurrency control for d~stnbnted database systems ACM Trans. Database Syst. 3, 2 (June 1978), 178-198, 13. STEARNS,R E., LEWIS, P M II, AND ROSENKRANTZ,D J Concurrency control for database systems Proc IEEE Symp on Foundations of Computer Science, Houston, Texas, Oct 1976, pp 19-32 14 TSICHRITZIS, D.C, AND LOCHOVSKY, F.H Hierarchical database management Comptng Surveys 8, 11 (March 1976), 105-123. RECEIVED APRIL 1978, REVISED JANUARY 1979

Journal ofthe Associationfor Computm8 Machinery,Vol 27, No l, January 1980

Suggest Documents