Changes

Jump to navigation Jump to search
980 bytes added ,  23:12, 13 January 2013
Documentation for database locking.
This article is part of the [[Advanced User's Guide]].
The BaseX client-server architecture offers ACID safe transactions,
with multiple readers and single writers. Here are some more
informations about the transaction management.
=Concurrency Control=
The concurrency control checks for each transaction, which will perform a read or write operation BaseX 7.5.1 introduces locking on the database, the status of the lock object and decides whether the isolation is guaranteed for that transaction or level. Writing transactions do not. If the isolation can be guaranteed the transaction will be started immediately. Otherwise, the transaction enters a waiting queue and waits till the transaction monitor validates and starts the transactionnecessarily block all other transactions any more. The transaction monitor starts either the next writing transaction or the next group number of reading parallel transactions (if there are any on can be limited by setting the queue)[[Options#PARALLEL|PARALLEL option]].
==Transaction Monitor==
The transaction monitor ensures that just one writing transaction is active at the same time. This seems to be or an odd mechanism, but it is needed since the complexity arbitrary amount of updates increased and it is possible now to access multiple databases in one XQuery Update query.<br />To avoid starvation of any transaction and wrong execution orders the waiting queue works with the FIFO principle (reading transactions ''per database'First-In First-Out'), which states thatthe first process that arrives are active at the server will be the first one that will be executed. The FIFO principle cannot be adhered in a group of readingtransactions, as they run in different threads and thus can overtake each other.<br/>The use of the monitor also prevents the system from deadlocks, because the critical resource is only assigned to one writing transaction resp. a group ofreading transactionssame time.
Deadlocks are prevented by using preclaiming two phase locking. Execution is starvation-free as lock aquiration is queued per database. Because of XQuery Update specifies all updates are written at the end of the query, locking is strict with the exception that databases for which BaseX recognizes it will not write to are downgraded to read locks. Locks are not synchronized between multiple BaseX instances. We generally recommend working with the client/server architecture if concurrent write operations are to be performed. =Locking=Limitations== As XQuery is a very powerful language, deciding which databases will be accessed by a query is non-trivial. Optimization is work in progress. Databases locked by a query are listed in the GUI's [[GUI#Visualizations|Info View]] and on the command line client if [[Options#QUERYINFO|QUERYINFO]] is set. If you think too much is locked, please give us a note on our [http://basex.org/open-source/ mailing list] with some example code. Currently identifying which databases to lock is limited to database calls directly addressing databases without references (or none at all). Some examples on database-locking enabled queries: * {{Code|doc('factbook')}}, read-locking "factbook"* {{Code|collection('db/path/to/docs')}}, read-locking "db"* {{Code|fn:sum(1 to 100)}}, locking nothing at all* {{Code|delete nodes doc('test')//*[string-length(local-name(.)) > 5]}}, write-locking "test"* {{Code|CREATE DB newdb}}, write-locking "newdb" All of these queries can be executed in parallel. Some examples on queries not supported by database-locking yet: * <code>let $db := 'factbook' return doc($db)</code>, will read lock globally: referencing database names isn't supported yet* {{Code|for $db in ('factbook') return doc($db)}}, will read lock globally: ditto* {{Code|doc(doc('test')/reference/text())}}, will read lock globally: ditto* <code>let $db := 'test' return insert nodes <test/> into doc($db)</code>, will write lock globally: ditto =Before BaseX 7.5.1=
==Update Operations==
editor, reviewer
35

edits

Navigation menu