[MarkLogic Dev General] Sequences in XCC
ian at marklogic.com
Sat Mar 24 08:18:29 PST 2007
semi-colon (;) can be used to separate two entire XQuery expressions
into different transaction contexts. Each "side" of the ; is parsed as
a stand-alone XQuery expression and evaluated independently (and
sequentially). Your cq command uses the ; in this way.
However, it sounds like what you are trying to do is embed the
semi-colon into the middle of a single XQuery expression in order to be
able to "write" and then "read" back a file. This doesn't work, because
what comes "before" the semi-colon is interpreted as a stand-alone (and
probably now syntactically illegal) XQuery expression. What comes after
is a second (also probably now syntactically illegal) XQuery expression.
Hence your error message.
The broadest generalization is that MarkLogic Server currently
implements a model in which there is an implicit commit at the end of
each XQuery expression (there are some exceptions to this for triggers
and other things, but this is the best generalization to start with).
In addition, there are no explicit "commit" operators (currently)
available. When you combine that with the fact that MarkLogic Server
implements snapshot semantics for read-only statement (effectively
transaction, in the generalization above) contexts and readers/writers
locks for statements containing updates, it's difficult to do what
you're trying to do in a single XQuery expression.
All that being said, there is a very sharp tool (in other words, be very
very careful) available via the xdmp:eval() and xdmp:invoke() commands.
With eval and invoke, there is an option available to specify whether
you want the eval()'d or invoke()'d XQuery expression to evaluate in the
"calling" XQuery module's statement context - or whether you want it to
evaluate in an independent (ie. different transaction) context. If you
choose the latter option, it becomes possible to do some more powerful
things. However, it also becomes possible to complete shoot yourself in
the foot by creating programmatic deadlock conditions - ie. a series of
events in which the algorithmic relationship between the parent XQuery
and the invoke()'d or eval()'d XQuery always results in a locking
conflict - both the parent and the "child" query both need to acquire a
lock, and no matter how hard the server tries, it cannot resolve it.
In this case, you can end up with a "stuck" query thread at a very very
low level in the server, and the only way out will likely be to restart
the server. (Note that other query processing should continue
unabated.) This is a well-known and documented problem that results
from using the very sharp tool incorrectly. So be careful about this.
Note further that if you really want to do what you're talking about
below, I suspect that you may need to use two different invok'd query
contexts to do the replacement and to return the updated value of a.xml,
because the "snapshot" time of the parent query (assuming it's a
read-only query running with snapshot semantics) will be "before" the
update time of the invoke'd query, so it won't see it. But a second
invok'd query, in another independent context, will. If the parent
query is running with readers/writers locks (ie. it contains update
commands), you may only need one "sub-query", as long as the reader lock
needs to be acquired *after* the invoke'd query evaluates and does its
updates. (If the reader lock is acquired before the invok'd query, then
you'll end up in the deadlock above.)
I hope that you can make some sense of this, rather than my having
totally confused you. The developer's guide provides more information
about this in Section 2.5, probably right after the part you read in
From: general-bounces at developer.marklogic.com
[mailto:general-bounces at developer.marklogic.com] On Behalf Of Paul
Sent: Saturday, March 24, 2007 4:25 AM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Sequences in XCC
I'm trying to use the transactional context character ';' as per the
developer guide, however I don't seem to be getting it right
I appear to be able to do this in cq:
and results in
however if put this in any other context, ie a function, it stops being
able to understand the semi colon:
XDMP-UNEXPECTED: Unexpected token syntax error, unexpected SemiColon_,
expecting Comma_ or Rbrace_
Am I missing something obvious? the developers guide doensn't have much
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the General