Changes

Jump to navigation Jump to search
6 bytes removed ,  13:55, 23 June 2020
no edit summary
* By default, read transactions are favored, and transactions that access no databases can be evaluated even if the transactions limit has been reached. This behavior can be changed via the {{Option|FAIRLOCK}} option.
==Limitations== ===Commands=== Database locking works with all commands unless the glob syntax is used, such as in the following command call: * {{Code|DROP DB new*}}: drop all databases starting with "new" ===XQuery=== Deciding which databases will be accessed by a complex XQuery expression is a non-trivial task. Database detection works for the following types of queries: * {{Code|//item}}, read-locking of the database opened by a client* {{Code|doc('factbook')}}, read-locking of "factbook"* {{Code|collection('db/path/to/docs')}}, read-locking of "db"* {{Code|fn:sum(1 to 100)}}, locking nothing at all* {{Code|delete nodes db:open('test')//*[string-length(local-name(.)) > 5]}}, write-locking of "test" A global lock will be assigned if the name of the database is not a static string: * {{Code|for $db in ('db1', 'db2') return db:open($db)}}* {{Code|doc(doc('test')/reference/text())}}* <code>let $db := 'test' return insert nodes <test/> into db:open($db)</code> The functions [[Databases#XML Documents|fn:doc]] and [[Databases#XML Documents|fn:collection]] can also be used to address that are not stored in a database. However, this may lead to unwanted locks, and you have two options to reduce the number of locks: No database lookups will take place if {{Option|WITHDB}} option is disabled, or if {{Function|Fetch|fetch:xml}} is used instead of [[Databases#XML Documents|fn:doc]]. You can consult the query info output (which you find in the [[GUI#Visualizations|Info View]] of the GUI or which you can turn on by setting {{Option|QUERYINFO}} to {{Code|true}}) to find out which databases have been locked by a query. =XQuery Locks==
By default, access to external resources (files on hard disk, HTTP requests, ...) is not controlled by the transaction monitor of BaseX. You can use custom XQuery locks to do so:
===Options, Pragmas, Annotations===
* You can declare custom read and write locks via options, pragmas or function annotations.
</syntaxhighlight>
===Java Modules===
Locks can also be acquired on [[Java Bindings#Locking|Java functions]] which are imported and invoked from an XQuery expression. It is advisable to explicitly lock Java code whenever it performs sensitive read and write operations.
 
==Limitations==
 
===Commands===
 
Database locking works with all commands unless the glob syntax is used, such as in the following command call:
 
* {{Code|DROP DB new*}}: drop all databases starting with "new"
 
===XQuery===
 
Deciding which databases will be accessed by a complex XQuery expression is a non-trivial task. Database detection works for the following types of queries:
 
* {{Code|//item}}, read-locking of the database opened by a client
* {{Code|doc('factbook')}}, read-locking of "factbook"
* {{Code|collection('db/path/to/docs')}}, read-locking of "db"
* {{Code|fn:sum(1 to 100)}}, locking nothing at all
* {{Code|delete nodes db:open('test')//*[string-length(local-name(.)) > 5]}}, write-locking of "test"
 
A global lock will be assigned if the name of the database is not a static string:
 
* {{Code|for $db in ('db1', 'db2') return db:open($db)}}
* {{Code|doc(doc('test')/reference/text())}}
* <code>let $db := 'test' return insert nodes <test/> into db:open($db)</code>
 
The functions [[Databases#XML Documents|fn:doc]] and [[Databases#XML Documents|fn:collection]] can also be used to address that are not stored in a database. However, this may lead to unwanted locks, and you have two options to reduce the number of locks: No database lookups will take place if {{Option|WITHDB}} option is disabled, or if {{Function|Fetch|fetch:xml}} is used instead of [[Databases#XML Documents|fn:doc]].
 
You can consult the query info output (which you find in the [[GUI#Visualizations|Info View]] of the GUI or which you can turn on by setting {{Option|QUERYINFO}} to {{Code|true}}) to find out which databases have been locked by a query.
=File-System Locks=
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu