Microprocessing and Microprogramming 37 (1993) 127-130 North-Holland
127
On Hierarchical Locking of Composite Objects W. Cellary and W. Wieczerzycki Franco-Polish School of New Information and Communication Technologies Mansfelda 4, 60-854 Poznan, Poland
A stamp locking method is proposed, which is addressed to multiversion object-orienteddatabases. The method deals with aLl semantic relationshipsbetween objects and object versions in the database in uniform, hierarchical way. Hierarchical locking proposed does not require intentional locks.
1
Introduction
Object-oriented databases (OODBs) are addressed to non-traditional domains, such as computer aided design and management, software engineering and office information. To be used efficiently, on the one hand, they have to support all traditional database functions, s u c h as concurrency control, recovery, access authorization, data distribution, etc., and on the other hand they have to provide objectoriented features such as class inheritance, object encapsulation, object versions, etc. One of the most important OODBS concept is a composite object. An object is composite if its attributes are references to other objects related with it via the "IS-COMPOSED-OF" relationship. A component object may itself be a composite object. Thus, objects related by the "IS-COMPOSED-OF" relationship constitute a hierarchy, called composition hierarchy. OODBs provide the users with functions concerning the entire collection of objects related by a composition hierarchy. Composite objects require proper management. It is particularly hard in the case of
multiuser and multiversion OODBs. The main problem is how to maintain consistency of the database, which is related to two aspects: concurrency and versioning. The concurrency aspect of the O O D B consistency problem is similar to the one in traditional databases. It follows from concurrent transaction processing. Versioning aspect of database consistency concerns identificationof versions of different objects that go together. To solve the p~oblem of concurrent transaction processing two-phase locking method is commonly used. In this method, each transaction must firstlock a data item before performing a read or write operation on it (lock=rig phase), and then unlock it in commit phase. Commit phase begins after setting all the locks requested by the transaction. A lock may be granted if accessed data item is currently unlocked. Otherwise, requested lock has to be compared with loks set by other transactions. It still may be granted if it is compatible with all locks currently set. In a case of a transaction accessing many data items a great number of locks must be set. To reduce the number of lock setting, hierarchical locking methods are used, providing a trade-off between
128
W. Cellary, W. Wieczerzycki
maximization of the concurrency degree and minimization of locking overhead. In the hierarchicai locking methods a database is viewed as a hierarchy of a lockable units, called granules. A granularity hierarchy is represented by a tree whose vertices are granules and whose edges connect higher level granules to lower level ones. When a transaction sets a lock on a granule at a given level of the granularity hierarchy, it is implicitly locking all its descendants. To guarantee hierarchical locking correctness, it is necessary to ensure that after setting a lock on a given vertex of the granularity hierarchy by a particular transaction no other transaction obtains an incompatible lock on any of its predecessors. To solve this problem special locks, called intentional locks, are used. Before locking a particular vertex of the granularity hierarchy a transaction has to intentiona£1y lock all its predecessors [1]. The classical hierarchical locking algorithm cannot be directly applied for the multiversion O O D B s . It follows from the fact, that in multiversion O O D B s at least four hierarchies may be distinguished: granularity, inheritance, composition and version derivation. All of them should be taken into account by a hierarchical locking method in the same way. Any attempt to adopt the classical method leads to a great number of intentional locks and complex locking strategy [2]. The reason is that intentional locks have to be independently set in all the hierarchies,which are usually composed of much more levels then the granularity hierarchy. In a case of transactions tending to access leaves of these hierarchies, the number of intentional locks to be set is excessively great. In this paper, to avoid intentionallocking, a stamp locking approach is proposed. In Section 2 the general concept of stamp locking methods is brieflypresented. In Section 3 the sketch of a stamp locking method adapted for
monoversion composite objects is presented. Section 4 concludes the paper.
2
Stamp Locking Approach
The main notion of the approach presented is a stamp lock that contains information on the position of locked object in all the OODB hierarchies. Thus, to lock entire subtrees of these hierarchies it is sufficient to set a single stamp lock instead of a number of intentional locks. A stamp lock is composed of a lock mode and a listof node stamps, corresponding to hierarchies concerned. The lock mode describes the properties of the stamp lock in all the hierarchies concerned. In some of them a stamp lock (exclusive or shared) may be hierarchical, in the others non-hierarchical. W h e n a stamp lock is hierarchicalin a particular hierarchy, it explicitlylocks the root and implicitly all the component nodes of a hierarchy subtree. On the contrary, when a stamp lock is non-hierarchical in a particular hierarchy, it explicitly locks only one hierarchy node. The list of node stamps contains one node stamp per hierarchy concerned. In the simplest case, when the stamp locking method concerns only one hierarchy, a stamp lock is a pair (lock_mode, node.stamp). Each node stamp is constructed in such a way that it makes it possible to identify all the node ancestors. If a node is the n-th child of its parent node, whose node stamp is p, then the child node is stamped p.n. The root node is stamped 0. Node stamps may be compared by the use of special operators. By the comparison of two node stamps it is possible to deduce if the respective subtrees of hierarchy have common nodes or not. If not, then the stamp locks are certainly compatible. Otherwise, they may be
On hierarchical locking of composite objects incompatible. To determine the compatibility of two stamp locks a logical rule on node stamps has to be evaluated. Stamp locking methods may be extended for directed acyclic graphs (DAGs) [4]. In this case, however, locking protocol has to be modified. In some cases, to lock subgraphs of a DAG it is necessary to set more then one stamp lock. Moreover, to guarantee unambiguity of assigning stamps to nodes having more then one direct predecessor a special stamping algorithm has to be used.
129
where z means "exclusive", s means "shared", upper case letters mean "hierarchical" and lower case letters mean "non-hieraxchical'. Locks (z, c8) and (s, cs) concern a single object whose composition stamp is c8. Locks (X, cs) and (S, cs) concern a composite object stamped c8 and al] its nested components. If cs=O, locks (X, 0) and (S, 0) concern the whole database.
/
3
Stamp Locking Method for
\
/
0
Composite Objects Composition hierarchy concerns composite objects and their components. In fact, there are as many different composition hierarchies as root composite objects. However, to be locked efficiently, one composition hierarchy is required. It may be easily obtained by the creation of a fictitious composite object whose components are all the root composite objects. Assuming single composition hierarchy, the position of an object in this hierarchy may be identified by a single composition stamp, that is syntactically identical with the node stamp (cf. Section 2). An example of a composition hierarchy is shown in Fig. 1. The fictitious composite object is stamped 0. The simple object A is stamped 0.1. The composite object B, composed of objects C and D, is stamped 0.2. As follows from Section 2, a stamp lock, denoted SL, is defined as a pair:
SL =(lm, cs), where lm is a lock mode and cs is a composition stamp of the object being locked. In the method four stamp locks are distinguished:
O.Z2 Figure 1. Composition hierarchy All the locks presented above axe set on the database (i.e. no locks axe set on objects). A requested stamp lock is granted if it is compatible with all the locks currently set. Lock compatibility is determined by logical rules on composition stamps, using the following three operators. Let csl and cs2 be two composition stamps. • Stamps c81 and cs2 axe different, denoted cs~! = cs2 , if they indicate different nodes of composition hierarchy; • Stamp csl includes stamp cs2 , denoted
130
W. Cellary, W. Wieczerzycki
csz > cs2 , if the node identified by csz is a successor of a node identified by cs2 in the composition hierarchy; • Stamp csl is included in stamp cs2, denoted csz < cs2 , if the node identified by csl is a predecessor of the node identified by cs2 in the composition hierarchy, or the nodes are the same. The logical rules are:
In the method, transaction accessing a composite object has to set one stamp lock only. Lock is granted if it is compatible with all the locks set by other transactions. To determine compatibility of the stamp lock requested with the locks set, it is sufficient to evaluate corresponding rule from the compatibility matrix. It is worth to notice that efficiency of the stamp locking method is similar to that of the classical non-hierarchical method (cf. Section 1).
rl: -~(csz < cs2 V csz > cs2), r2: -,(csl < cs2),
4
r3:-~(cs2 < csl),
The stamp locking method presented above concerns monoversion composite objects. The main feature of this method is its efficiency and simplicity: no intentional locks are used. The method may be extended for version derivation hierarchy [3] and inheritance hierarchy [4], offering hierarchical locking of multiversion composite objects and subtrees of classes.
r4: csz[ = cs2 • Lock compatibility matrix is given on Fig. 2.
SLsSLr ( X , c s 2 ) ( x , c s 2 ) { S , c s 2 ) ( s , c s ~ (x,csl)
rl
r2
rl
r2
(x,cs 1)
r3
r4
r3
r4
(S,cs
)
rl
r2
true
true
I )
r3
r4
true
true
Conclusions
References
(s,cs
1
[1]
Gray J. "Notes on Database Operating Systems", Operating Systems: An Advanced Course, Springer-Verlag, 1978.
[2]
Kim W., Bertino E., Gaxza J.F. "Composite Objects Revisited", Proc. ACM SIGMOD Conf., 1989.
[3]
Wieczerzycki W. "Concurrency Control for M,Itiversion Composite Objects", Proc. VI ISCIS Conf., Elsevier, 1991.
[41
Wieczerzycki W. "Concurrency Control for Multiversion Object-Oriented Databases" (in Polish), Ph. D. Thesis, Poznan, 1992.
Figure 2. Lock compatibility matrix As an example consider compatibility of stamp locks SL, = (X, c81) and SLr = (X, cs2), determined by the rule rl. This rule says that requested stamp lock SLr is compatible with the set stamp lock SLo, if SLr and SL, concern different objects and neither object stamped CSl is a component (successor in the composition hierarchy) of an object cs~ , nor object stamped CSl is composed (is a predecessor in the composition hierarchy) of object C8 2
.