A Transaction Mechanism for Native XML Database

5
A Transaction Mechanism for Native XML Database HUI TAN, XINMENG CHEN College of Computer Wuhan University Wuhan 430072, Hubei CHINA [email protected] JINGUANG GU College of Computer Science and Technology Wuhan University of Science and Technology Wuhan 430081, Hubei CHINA [email protected] Abstract: Concurrent accessing of XML data becomes more and more important for XML-based applications, especially for Native XML Database systems (NXD) because of the dramatic growth of number and complexity of such applications. Transaction is a potential solution for the concurent accessing of XML data. However, research on transaction of NXD is still very limited. This paper proposes a transaction model for NXD management systems. It introduces a NXD storage model which is suitable for accessing XML data using XPath and XQuery. A locking protocol, Schema path Lock Protocol, is designed for this transaction model. An implementation of such transaction model is presented last in this paper. Key–Words: Distributed Transaction Process, Multi-granularity Lock, Native XML Database, XQuery 1 Introduction Integration on XML-based information is an impor- tant topic for web-based information systems. Due to its ability to express semi-structured information, XML is rapidly becoming a language of choice to express and store information on the web. XML documents could be stored in text files, relational or object-oriented database (XML Enabled Database, XED) or native XML database (NXD). Therefore, all features presented in relational and object-oriented databases can be revisited in the context of XML doc- uments. Concurrency control mechanism allows mul- tiple users to query and update a document simulta- neously. Concurrency control has been extensively studied in the context of traditional database man- agement system such as RDBMSs and OODBMSs. Some important concepts such as locks, transactions, schedulers are introduces as well as protocols such as two phase locking (2PL) for serializability. Instead, the research on transaction in NXD is still very lim- ited. Transaction mechanisms for rational and object- oriented database could be used for XML documents transaction in XED. One way to provide concurrent access to an XML document is to store the document in relational database and using the existing locking schemes in RDBMS. However, such method often causes over-restrictive locks while guaranteeing seri- alizability. Most NXD systems such as Tamino[9] and Xindice lock the entire XML document for concur- rency control, which also cause lots of limitation. In order to ensure the serializability of transaction, lock- ing must prevent the phantom problem. There are two well-known locking mechanisms for solving phan- toms problem, physical index based locking and logi- cal predicate based locking. The index based locking, such as key range locking, has been widely adopted for RDBMS. Unfortunately, index based locking is not applicable for XML data management for the ab- sence of an efficient index structure for an XML doc- ument model. The predicate based locking is a better choice for native XML database, but it is expensive. This paper will introduce a new transaction model to improve the concurrently accessing ability of NXD and solve the problem of phantoms. The remain- der of this paper is structured as follows. Section 2 gives the general discussion about the storage and accessing properties of native XML database. Sec- tion 3 discusses the locking protocol of the transac- tion, a new fine-granularity locking algorithm named Schema Path Lock (SPLOCK) is introduced in this section. Section 4 presents an implementation of this transaction model. Section 5 summarizes the whole paper. 2 Storage and Accessing Properties of NXD 2.1 The Property of Storage of NXD Efficient and effective synchronization of concurrent access to an XML document is greatly facilitated if a specialized internal representation is used, which en- Proceedings of the 5th WSEAS International Conference on Applied Computer Science, Hangzhou, China, April 16-18, 2006 (pp486-490)

Transcript of A Transaction Mechanism for Native XML Database

A Transaction Mechanism for Native XML Database

HUI TAN, XINMENG CHENCollege of Computer

Wuhan UniversityWuhan 430072, Hubei

[email protected]

JINGUANG GUCollege of Computer Science and TechnologyWuhan University of Science and Technology

Wuhan 430081, HubeiCHINA

[email protected]

Abstract: Concurrent accessing of XML data becomes more and more important for XML-based applications,especially for Native XML Database systems (NXD) because of the dramatic growth of number and complexityof such applications. Transaction is a potential solution for the concurent accessing of XML data. However,research on transaction of NXD is still very limited. This paper proposes a transaction model for NXD managementsystems. It introduces a NXD storage model which is suitable for accessing XML data using XPath and XQuery.A locking protocol, Schema path Lock Protocol, is designed for this transaction model. An implementation ofsuch transaction model is presented last in this paper.

Key–Words: Distributed Transaction Process, Multi-granularity Lock, Native XML Database, XQuery

1 Introduction

Integration on XML-based information is an impor-tant topic for web-based information systems. Dueto its ability to express semi-structured information,XML is rapidly becoming a language of choice toexpress and store information on the web. XMLdocuments could be stored in text files, relationalor object-oriented database (XML Enabled Database,XED) or native XML database (NXD). Therefore, allfeatures presented in relational and object-orienteddatabases can be revisited in the context of XML doc-uments. Concurrency control mechanism allows mul-tiple users to query and update a document simulta-neously. Concurrency control has been extensivelystudied in the context of traditional database man-agement system such as RDBMSs and OODBMSs.Some important concepts such as locks, transactions,schedulers are introduces as well as protocols such astwo phase locking (2PL) for serializability. Instead,the research on transaction in NXD is still very lim-ited. Transaction mechanisms for rational and object-oriented database could be used for XML documentstransaction in XED. One way to provide concurrentaccess to an XML document is to store the documentin relational database and using the existing lockingschemes in RDBMS. However, such method oftencauses over-restrictive locks while guaranteeing seri-alizability. Most NXD systems such as Tamino[9] andXindice lock the entire XML document for concur-rency control, which also cause lots of limitation. Inorder to ensure the serializability of transaction, lock-

ing must prevent the phantom problem. There are twowell-known locking mechanisms for solving phan-toms problem, physical index based locking and logi-cal predicate based locking. The index based locking,such as key range locking, has been widely adoptedfor RDBMS. Unfortunately, index based locking isnot applicable for XML data management for the ab-sence of an efficient index structure for an XML doc-ument model. The predicate based locking is a betterchoice for native XML database, but it is expensive.

This paper will introduce a new transaction modelto improve the concurrently accessing ability of NXDand solve the problem of phantoms. The remain-der of this paper is structured as follows. Section2 gives the general discussion about the storage andaccessing properties of native XML database. Sec-tion 3 discusses the locking protocol of the transac-tion, a new fine-granularity locking algorithm namedSchema Path Lock (SPLOCK) is introduced in thissection. Section 4 presents an implementation of thistransaction model. Section 5 summarizes the wholepaper.

2 Storage and Accessing Propertiesof NXD

2.1 The Property of Storage of NXDEfficient and effective synchronization of concurrentaccess to an XML document is greatly facilitated if aspecialized internal representation is used, which en-

Proceedings of the 5th WSEAS International Conference on Applied Computer Science, Hangzhou, China, April 16-18, 2006 (pp486-490)

ables fine-granular locking. For this reason, it is suit-able to discuss the property of storage model of nativeXML database firstly, though the storage model is notthe key topic of this paper.

An XML document can be described as a treestructure, the root of the tree represents the root ofthe XML document, and the nodes of the tree rep-resent different kinds of elements of the XML docu-ment, which are element nodes, attribute nodes or textnodes. Some storage models such as taDOM[8] usedifferent kinds of shape to denote the different kindsof nodes when they represent the XML document in agraph, in our strategy, it need not to identify the dif-ference of the nodes, because all the discussion of usare based on the precondition that the interface of thenative XML database storage is XPath based languagesuch as XQuery or XUpdate. XML document can berepresented as a tree with tags on the nodes, name itas Td = (Vd, Ed, δd,Σd, rootd, oid, typed, oidd), andVd is a node set of the tree; Ed is an edge set ofthe tree, edge represents the relationship between el-ement nodes; δd is a mapping function of nodes. Ev-ery node has a type which corresponds with an uniqueidentifier, and these types and identifiers belong to setΣd and oid respectively, and corresponding mappingfunctions are typed and oidd. Each XML data tree hasa root node rootd[11].

Most native XML databases use DOM or OEMstorage model to store the XML documents becausethese models can improve the processing perfor-mance when using DOM API to accessing the XMLdocuments. However, it is a better choice to useXPath/XQuery or XUpdate interface to access theXML documents under the web-based information in-tegration environment. Like the schema of RDBMSsor OODBMSs, the schema of XML documents canimprove the performance of querying or updating thedata in the NXDs, so storing the schema informa-tion with the XML documents is a better choice.DataGuide[5] of Lore[1] is the referenced implemen-tations of the schema based storage model. The dataschema of XML document can be defined as a di-rected graph, name it as Gt = (Vt, Et, δt,Σt, roott).And Vt is set of nodes; Et is the edges set betweennodes, edge denotes the nested inclusion of nodes;function δt determines the direction of each edge inEt; Σt is the name set of the nodes, that is type set ofelements; the unique node in graph which has no in-put edge but a output edge is called the root of graph,named it as roott. In this model, children nodes canaccess corresponding parent nodes by means of func-tion δt

−1[11].

2.2 The Property of Accessing Interface ofNXD

XML document can be extracted into a set of severalpath instances, thus each data node corresponds witha path instance respectively. Path expression query isutilized to match path instance of XML document, soas to acquire sound element instance.

Path query can be represented by Q =<Gt, Td, SE, PE,RS >, Gt and Td is query docu-ment schema and document data respectively, PE isquery path expression, SE is the initial elements setof query, RS is the query result set. Since SE is theoriginal point of PE, thus PE is a relative path ab-solutely, moreover, all path connection identifiers inPE just represent the relationship among elements.The original query form of the user may be acquiredby SE + PE.

This paper use a concept named XML extensionto express how to get record set of the query.

Definition 1 For a XML document Td, define XMLextension EXT (Etype) as a set of element instancesin Td whose type is Etype. EXT (Etype) ={oidd(e) | e ∈ Vd ∧ typed ∈ Σd ∧ typed = Etype}

Theorem 2 If absolute path expression query Q =<Gt, Td, roott, PE,RS > is an unique path whichcan access final goal in Gt, and it use End(PE)to express the final element type of path PE, thusRS = EXT (End(PE)).

PE is XPath-like query expression, which can bedescribed as,

PE ::= CFF ::= label|text()|@ ∗ | ∗ |FCF |F [P ]C ::= /|//Where P is the set of predicate condition expres-

sion to limit the quantity of the nodes affected by thequery, it can be described as,

P := F |F O const|P and PO :=< | ≤ | > | ≥ | = | 6=For a specified query expression PEn, it can be

divided into tow parts, one is the pure schema path, itis the path of the schema graph without any predicatecondition, the other is a set of predicate expression.The pure schema path is named as SP , it use uniquelabels to mark every node in the pure schema path,named them as SL = {sl1, sl2, . . . , sln}, SP can beexpressed as:

SP ::= CFF ::= label|text()|@ ∗ | ∗ |FCFC ::= /|//The set of the predicate condition P can be ex-

pressed as {(SL = sl1) ∧ Psl1 , (SL = sl2) ∧

Proceedings of the 5th WSEAS International Conference on Applied Computer Science, Hangzhou, China, April 16-18, 2006 (pp486-490)

Psl2 , . . . , (SL = sln)∧Psln}. Where sli (1 ≤ i ≤ n)is the unique label of a node of the pure schema path,Psli is the predicate condition of the node.

3 Lock Protocol for Native XMLDatabase

3.1 Insufficiency of existing lock mechanismsHow to add locks to the XML document is the firstproblem it need to resolve. The following lock mech-anisms, which may be applied to XML documentstransactions, will be examined.

Table Locking or Document Level Locking. InXED systems, the XML documents may be stored ina parent-child relationship table, In this approach theentire table representing the hierarchy will be lockedin case of query that traverses the hierarchy. If thiswere not the case, a phantom could occur. A lock onthe entire parent-child relationship table makes it im-possible, however, to add an element in a subtree thathas not been read by any user. In NXD systems suchas Tamino, Xindice, the entire document affected bythe query will be locked, it is insufficient to the con-currency of the XML documents.

Predicate Locking. Predicate locks[4] has beenintroduced to fix the problem mentioned above. Thereis no longer any need to lock an entire table; phan-toms cannot occur because predicates are given thatdescribe the tuples that have been selected in anINSERT, UPDATE or DELETE query. however.they are rarely implemented in commercial relationaldatabases systems because they are prohibitively ex-pensive. It’s a better choice to combine the predicatelock and other kind of locks to get a fine-granularitylock mechanism and a high performance to processthe XML documents.

Tree Locking. Tree locking [2] protocols areused in multi-user operating systems to allow concur-rent access to the directory structure like XML doc-uments. In these protocols locks do not hold for en-tire granules but only for nodes, i.e., when a node islocked its descendants are not also locked. However,the operation to add and remove a lock on a node ofthe XML document is expensive too.

Path Locking. Path lock scheme[3] such as PathLock Satisfiability (PLS) and Path Lock Propagation(PLP) means to add read locks or write locks on thepaths affected by the query. Current path lock schemeis to add read or write lock to the instance graph ofthe XML document. Though the path lock can geta multi-granularity lock mechanism for XML docu-ments, but too many locks have to be added to thepath affected by the query, especially by the XPath or

Table 1: Lock compatibility. Compatibilities markedas ‘+’, the uncertain marked as ‘P’, which will betested by the predicate condition.

GrantedRequested IS IX S SIX U X

IS + + + + P PIX + + P P P PS + P + P P P

SIX + P P P P PU P P + P P PX P P P P P P

XQuery based query.

3.2 A multi-granularity lock for the transac-tion of NXD

Path Lock mechanism is a better choice to get amulti-granularity lock mechanism for Native XMLDocuments, especially for the situation that the in-terface of Native XML database system is XPath orXQuery. However, to reduce the lock quantity, itneeds not to add the lock to the instant graph of theXML documents, add lock to the schema graph in-stead. This kind of lock is named as Schema PathLock (SPLOCK), it can be defined as:

Definition 3 Define Schema Path Lock as Ln =(typen, Tn, Gn, PEn), typen is the type of the lock,it can be NONE lock, INTENT SHARE lock (IS),SHARE lock (S), EXCLUSIVE lock (X), UPDATE lock(U), INTENT EXCLUSIVE lock (IX) and SHARE IN-TENT EXCLUSIVE lock (SIX), the compatible matrixof these locks discussed in table 1 and paper [6]; Tn isthe identifier of the transaction who owns the lock, Gn

is the identifier of the node in the XML schema graphwhich the lock holds; PEn is the path expression ofthe transaction.

SPLOCK is the mix of path lock and predicatelock, it adds path lock to the XML schema graph toreduce the quantity of lock of the system and it usesthe predicate condition to restrict the scale of the lockwill be affected.

The schema of the path lock can be one of thefollowing:◦ The schema information stored in the NXDs or dy-

namic generated from the XML documents.

◦ The background knowledge. The knowledge repre-sents in Ontology language such as DAML+OIL orOWL[10], and maps it to XML DTD or Schema us-ing suitable algorithm.

Proceedings of the 5th WSEAS International Conference on Applied Computer Science, Hangzhou, China, April 16-18, 2006 (pp486-490)

When a new lock request to be added to a node ofGt, how to identify the new lock is compatible withthe locks which have been granted to the node. Anew function named Conf(T1, T2) is used to do thistask, T1 is the lock which requests to be added and T2

is the lock has been granted, if Conf(T1, T2) = ‘+′means lock T1 is compatible with lock T2, otherwiseConf(T1, T2) = ‘−′ and lock T1 conflicts with lockT2.

To make the transaction serializable, the follow-ing rule is true.

Theorem 4 To a node of XML schema graph, it has ntransactions named T1, T2, . . . , Tn, and correspond-ing n locks named L1, L2, . . . , Ln. All the locks arecompatible with each other, or T1, T2, . . . , Tn are se-rializable. Now, suppose we want to add a new lockTn+1 to this node, if T1, T2, . . . , Tn, Tn+1 are serial-izable, the following expression must be satisfied.

1. ∀i∀j((1 ≤ i ≤ n ∧ 1 ≤ j ≤ n ∧ i 6= j ∧(i < j)) → (Conf(Tj , Ti) = ‘+′) ∨ RSPEi ∩RSPEj = ∅).

2. ∀i(1 ≤ i ≤ n → (Conf(Tn+1, Ti) = ‘+′) ∨RSPEi ∩RSPEn+1 = ∅).

Proof: first to prove item 2. If Conf(Tn+1, Tn) =‘+′, this means the requesting lock Tn+1 is compatiblewith the granted lock Ti, the transaction is serializableobviously. If Conf(Tn+1, Tn) = ‘−′ and RSPEi ∩RSPEn+1 6= ∅, this means lock Tn+1 and Ti will tryto add lock to the same nodes of the XML documents,these will make the transaction unserializable.

Suppose adding lock in the sequence ofT1, T2, . . . , Tn, it can prove that item 1 is also satis-fied. ut

It can use theorem 4 to get the value ofConf(Ti, Tj) when the compatibility of lock Ti andlock Tj is marked with ‘P’. If RSPEi ∩ RSPEj = ∅,Conf(Ti, Tj) = ‘+′, else Conf(Ti, Tj) = ‘−′.

From section 2.2 we know that a query expres-sion PE can be divided into two parts, one is the pureschema path SP , the other is the predicate conditionP , the query result RS will be chosen by the predicatecondition P . In fact, the lock is added to Gt from theroot to node (see section 3.3), we only need to processthe predicate condition Pslm , while slm is the label ofthe node.

3.3 Scheduling Algorithm for Schema PathLock

How to add locks and add what kind of locks to theSchema tree of the XML document is the problem

must be discussed in this subsection. We fist intro-duce the concept used in the algorithm.

The algorithms to add locks to the schema tree Gt

can be described as following:◦ Adding locks from the root to the nodes of the XML

schema.

◦ Freeing locks from the nodes to root of the XMLschema.

◦ If add S or IS lock to a non-root node, a IS lockor higher level lock (IS, IX, S, SIX, U, X) must beadded to its parent or key ancestor path.

◦ If add X, U, SIX or IX lock to a non-root node, aIX lock or higher level lock (IX, SIX, U, X) must beadded to its parent or key ancestor path.

◦ when adding lock to a node fails, it means the newlock can not obey the theorem 4, the scheduler triesto add locks to the parent node or the key ancestornode based on the path expression of the query re-quest.

◦ A lock conversion operation must be performedwhen the scheduler try to add one or more new kindlock to a schema node which has owns one lock.The scheduler will try to convert current lock to thehighest level lock. described as figure 1.

X

SIX

S IX

IS

U

Figure 1: Lock Conversion Graph.

4 ImplementationAs shown in figure 2, we implement a nativeXML transaction management system in our semi-structured information integration system namedOBSA[7]. It can be divided into four layers logically,◦ XML Data Storage Layer;

◦ XML Data Buffer Layer;

◦ XML Transaction Processing Layer;

◦ XML Transaction Management Layer.

Proceedings of the 5th WSEAS International Conference on Applied Computer Science, Hangzhou, China, April 16-18, 2006 (pp486-490)

The XML transaction processing layer implementsthe SPLOCK introduced in this paper, but not im-plements the algorithm of finding key ancestor. Allthe operations are processed in the memory beforethe transactions commit, the buffer manager updatethe data stored in physical storage layer when all thetransactions commit.

5 ConclusionA schema path locking protocol is implemented tosupport ACID[6] and concurrency accessing proper-ties of native XML database, it adds locks on schemagraph of the XML documents to reduce the quantityof locks and use predicate locking to prevent the phan-tom problem of transaction. With the analysis of thequery expression, a more flexible schedule algorithmis introduced to support the conversion of the transac-tion locks.

Transaction Management

Transaction Control Table

Transaction Manager

Scheduler I

Scheduler II

Lock Resource

Table

Access Control

Compiling & Executing

Engine

Log Management

Maintenance of logical and physical log

Restore Management

System failure Logical Log

Physical Log

Buffer Management

Logical Log Buffer

Buffer Manager

Physical Log Buffer

XML Data Buffer

Internal failure

Medium failure

XML Documents

Logical Log Files

Physical Log Files

T r a n s a c t i o n P

r o c e s s i n g

Checkpoint Control

Figure 2: The Implementation of Transaction.

References:

[1] S. Abiteboul, D. Quass, J. McHugh, J. Widom,and J. L. Wiener. The Lorel Query Languagefor Semistructured data. Journal on Digital Li-braries, 1(1):68–88.

[2] N. S. Barghouti and G. E. Kaiser. Concurrencycontrol in advanced database applications. ACMComputing Surveys, 23(3):269–317, 1991.

[3] S. Dekeyser, J. Hidders, and J. Paredaens. ATransaction Model for XML databases. WorldWide Web: Internet and Web Information Sys-tem, 7(1):29–57, 2004.

[4] K. P. Eswaran, J. N. Gray, R. A. Lorie, and I. L.Traiger. The notions of consistency and pred-icate locks in a database system. Communica-tions of the ACM, 19(11):624–633, 1976.

[5] R. Goldman and J. Widom.DataGuides:Enabling Query Formulationand Optimization in Semistructured Databases.In Proceedings of the 23rd International Confer-ence on Very Large Data Bases, pages 436–445.Morgan Kaufmann Publishers Inc, 1997.

[6] J. Gray and A. Reuter. Transaction Processing:Concepts and Techniques. Morgan Kaufmann,1993.

[7] J. Gu, H. Chen, L. Yang, and L. Zhang.OBSA:Ontology-based Semantic InformationProcessing Architecture. In J. Liu and N. Cer-cone, editors, Proceedings of IEEE/WIC/ACMInternational Conference on Web Intelligence2004, pages 607–610, Beijing, 2004. IEEEComputer Society Press.

[8] M. P. Haustein and T. Harder. taDOM:a Tai-lored Synchronization Concept with TunableLock Granularity for the DOM API. In L. A.Kalinichenko, R. Manthey, B. Thalheim, andU. Wloka, editors, Proceedings of 7th East Eu-ropean Conference on Advances in Databasesand Information Systems, volume 2798 of Lec-ture Notes in Computer Science. Springer, 2003.

[9] H. Schoning. Tamino - a DBMS designed forXML. In Proceedings of 7th International Con-ference on Data Engineering. IEEE ComputerSociety Press, 2001.

[10] M. Uschold and M. Gruninger. Ontologies:Principles, Methods and Applications. Knowl-edge Engineering Review, 11(2):93–155, 1996.

[11] G. Wang and M. Liu. Query Processing and Op-timization for Regular Path Expressions. In Pro-ceedings of the 15th International Conferenceon Advanced Information Systems Engineering(CAiSE 2003), Lecture Notes in Computer Sci-ence 2681, pages 30–45, Klagenfurt, Austria,2003. Springer.

Proceedings of the 5th WSEAS International Conference on Applied Computer Science, Hangzhou, China, April 16-18, 2006 (pp486-490)