15.07.2016 Views

MARKLOGIC SERVER

Inside-MarkLogic-Server

Inside-MarkLogic-Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In XQuery, MarkLogic queries from updates using static analysis. Before running a<br />

request, it looks at the code to determine if it includes any calls to update functions.<br />

If so, it's an update. If not, it's a query. Even if at execution time the update doesn't<br />

actually invoke the updating function, it still runs as an update. (Advanced tip: There's<br />

an xdmp:update prolog statement to force a request to be seen as an update. This is<br />

useful when your request performs an update from evaluated or invoked code that can't<br />

be seen by the static analyzer. ) In JavaScript, the system doesn't use static analysis, so<br />

any code that performs updates needs to state its intentions with a declareUpdate()<br />

function.<br />

UPDATES<br />

Locks are acquired during the update execution, yet the actual commit work happens<br />

only after the update finishes successfully. If the update exits with an error, all pending<br />

changes that were part of that update are discarded. By default, each statement is its<br />

own auto-commit transaction. We'll discuss multi-statement transactions later.<br />

During the update request, the executing code can't see the changes it's making.<br />

Technically that's because they haven't taken place. Invoking an update function doesn't<br />

immediately change the data, it just adds a "work order" to the queue of things to do<br />

should the update end successfully.<br />

Philosophically, code can't see the changes it's making because XQuery is a functional<br />

language, and functional languages allow the interesting optimization that different<br />

code blocks can potentially be run in parallel if the blocks don't depend on each other.<br />

If the code blocks can potentially be run in parallel, you shouldn't depend on updates<br />

(which are essentially side effects) to have already happened at any point.<br />

Any batch of updates within a statement has to be non-conflicting. The easiest (but<br />

slightly simplistic) definition of non-conflicting is that they could be run in any order<br />

with the same result. You can't, for example, add a child to a node and then delete<br />

the node, because if the execution were the inverse, it wouldn't make sense. You can,<br />

however, make numerous changes to the same document in the same update, as well as<br />

to many other documents, all as part of the same atomic commit.<br />

40

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!