Changes

Jump to navigation Jump to search
305 bytes added ,  19:22, 20 August 2018
* If an updating transaction comes in, it will be queued and executed after all previous read transaction have been executed.
* Subsequent operations (read or write) will be queued until the updating transaction has completed.
 
Each database has its own queue: An update on database A will not block operations on database B. This is under the premise that it can be statically determined, i.e., before the transaction is evaluated, which databases will be accessed by a transaction (see [[#Limitations|below]]). The number of maximum parallel transactions can be adjusted with the [[Options#PARALLEL|PARALLEL]] option.
 
With {{Version|8.6}}, locking has been improved:
 
* Jobs without database access will never be locked. Globally locking jobs can now be executed in parallel with non-locking jobs.
* Each database has its own queue: An update on database A will not block operations on database B. This is under the premise that it can be statically determined, i.e., before the transaction is evaluated, which databases will be accessed by a transaction (see [[#Limitations|below]]).* The number of maximum parallel transactions can be adjusted with the {{Option|FAIRLOCKPARALLEL}} option has been added: .* By default, read transactions will now be 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.
==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:
===Query Options, Pragmas, Annotations===
{{Mark|Introduced with Version 9.1}}: locks via pragmas and function annotations. * You can declare custom locks via the {{Code|query:read-lock}} and {{Code|query:write-lock}} locks via options in the query prolog, pragmas or function annotations.* The value of the option contains the lock string, may contain one or multiple ones lock keys (separated with commas). The default value is an empty string.
* Similar to the internal database locks, write locks block all other operations while read locks allow parallel access.
* The internal locks and XQuery locks can co-exist (there will be no conflicts, even if your lock string equals the name of a database that will be locked by the transaction manager).
In the following two example modulesmodule, locks have been added lock annotations are used to prevent concurrent write operations on the same file:
<pre class="brush:xquery">
module namespace read config = 'readconfig';
(declare %basex:~ Read read-lock on ('CONFIG key. ') function config:read(){declare option query file:read-lock text('CONFIGconfig.txt')};
declare %basex:write-lock('CONFIG') function readconfig:configwrite($data) { file:readwrite-text('config.txt', $data)
};
</pre>
Some explanations: * If a query calls the <pre class="brushcode>config:xquery"read</code>function, a read lock will be acquired for the user-defined {{Code|CONFIG}} lock string before query evaluation.module namespace * If <code>config:write</code> is called by a query, a write = 'lock on this lock string will be set for this query.* If a query calls <code>config:write';</code>, it will be queued until there is no running query left that has {{Code|CONFIG}} locked.* If the writing query will be evaluated, all other queries that will set a {{Code|CONFIG}} lock (reading or writing) will have to wait.
(Local locks can also be declared via pragmas:~ Write lock on CONFIG key. :)declare option query:write-lock 'CONFIG';
declare function write<pre class="brush:filexquery">($data# basex:write-lock CONFIG #) { file:write-text('config.txtxml', $data<config/>)};
</pre>
Some explanationsLocks for the functions of a module can be assigned via option declarations:
* If a query is parsed that is going to call the <codepre class="brush:xquery">readdeclare option basex:file</code> function, a read write-lock will be acquired for the user-defined {{Code|'CONFIG}} lock string before query evaluation.';* If <code>file:write:file('config.xml', <config/code> is referenced by a query, a write lock on this lock string will be set for this query.)* If a query references <code>write:file</codepre>, it will be queued until there is no running query left that has {{Code|files}} locked.* If the writing query will be evaluated, all other queries that will set a {{Code|files}} lock (reading or writing) will have to wait.
In practiceBefore {{Version|9.1}}, it’s often sufficient to only work with (exclusive) write lockswere declared in the {{Code|query}} namespace.
===Java Modules===
=Changelog=
 
;Version 9.1
* Updated: Query lock options were moved from {{Code|query}} to {{Code|basex}} namespace.
;Version 8.6
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu