Hello, Garret.

 I have a couple of ideas that can help you and hopefully the other
Sedna XQuery developers.

 At first, I don't think that it is very convenient to swap
statements, so the best way is to use explicit document lock, though
it might look a bit hacky:

(:begin transaction:)

UPDATE INSERT () INTO doc("COUNTER")/any-non-existent-node-
 (: this one leaves the document intact, but locks it with eXclusive lock :)

data(doc("COUNTER")/COUNTER)

UPDATE REPLACE $x in doc("COUNTER")/COUNTER/COUNT with <COUNT>{$x+5}</COUNT>

(:end transaction:)

 The first statement has almost zero overhead, because insert
operator checks for input sequence to be empty. Notice, that 'UPDATE
INSERT () INTO doc("COUNTER")' does actually read blocks, thus given
example (which does not, because of Sedna XPath processing feature)
should be much faster. However 'UPDATE DELETE
doc("COUNTER")/any-non-existent-node-' is the most simple and fast way
to lock the document, but would rather not recommend it, because you
never can expect when you stumble and the aftermath of accidental
delete are much worse than that of insert.

 The second idea is that Ivan's replace statement just won't work.
Sedna will not replace a node with an atomic string value. Working
statement should look like:

UPDATE REPLACE $x in doc("COUNTER")/COUNTER/COUNT/text() with text
{string($x+5) }

Thanks.
Ilya.

On Fri, Dec 24, 2010 at 3:54 PM, Ivan Shcheklein <shchekl...@gmail.com> wrote:
> Hi Garrett,
>
> Sorry, for the delay. Below you can find my comments ...
>
>> The count would be determined by executing the following query (would
>> return 10 in the above example):
>> data(doc("COUNTER")/COUNTER)
>>
>> The count would be incrementd by 5 with the following query:
>> UPDATE REPLACE $x in doc("COUNTER")/COUNTER/COUNT with
>> <COUNT>{$x+5}</COUNT>
>>
>> Then starting at 11 till 15, Elements would be added in with the following
>> query (with x replaced by number)
>> UPDATE insert(<ELENMENTx id='x'></ELEMENTx>) into doc("doc")//
>>
>> Is there a way to ensure that between the read of the COUNT value, and the
>> UPDATE of the COUNT value, that no other client reads or writes to the COUNT
>> value?
>
> To prevent counter read between the first and second statements you just
> need to swap them - first you update counter (and ensure exclusive locking
> on doc('counter')), then you read the value (since delta is known it's easy
> to get initial value):
>
> (:begin transaction:)
> UPDATE REPLACE $x in doc("COUNTER")/COUNTER/COUNT with <COUNT>{$x+5}</COUNT>
> data(doc("COUNTER")/COUNTER) - 5
> (:end transaction:)
>
> Note, don't forget that at least first two statement must be within one
> transaction.
>
> BTW, try also to replace text() node instead of the whole <count>, something
> like this should work (let me know if it doesn't :) ):
>
> UPDATE REPLACE $x in doc("COUNTER")/COUNTER/COUNT/text() with string($x+5)
>
>
> Ivan Shcheklein,
> Sedna Team
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment,
> and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> Sedna-discussion mailing list
> Sedna-discussion@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sedna-discussion
>
>

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Sedna-discussion mailing list
Sedna-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sedna-discussion

Reply via email to