Hi Jonna,

 

It does seem unusual to have to basic a transaction on the success of an
insert in 2 different databases whether or not those 2 databases are on the
same server.  While it would be nice to be able to combine both databases
onto one server, that may not always be the case.

 

Since it is difficult if not impossible to roll back the inserts in 2
different databases in the context of a single transaction, I might approach
the problem as follows:

 

1.       Try to identify why the rollbacks might occur:

 

a.       Is it just that I want to be sure that the basic insertion works?

b.      Are there any subsequent validation triggered by the insertion that
you want to verify or else roll back?  You could always prevalidate the
content before inserting it into the new database - I do this by running any
destination transforms on my content and validate the result locally without
saving the content so that I know the destination transforms will work when
inserted into the new databse.

c.       Other?

 

2.       After determining the possible causes of the rollback, I would like
to suggest that you perform the inserts in a temporary directory URI in each
database.  Next run a script to verify that each insertion succeeded.
Include any necessary validations or checks that would otherwise trigger a
rollback.  Use the outcome of the script to determine whether or not to
"rollback" the update; that is if the content inserts correctly in both
databases and passes any required validation, I would feel fairly confident
that you could then move the content into the desired destination directory
URI in each database assigning any necessary collections, permissions,
and/or document properties.  Yes it would require a subsequent insertion,
but the likelihood of a successful insertion might meet your requirement.
And of course remove the content from the temporary directory URI when done.

 

Maybe this is a poor man's way of doing things, but I hope it at least gives
you food for thought.

 

Tim

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Jonna Marry
Sent: Wednesday, February 27, 2013 6:36 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Single transaction and rollback on
failure

 

Hi,

My requirement is to load 2 different documents(actual document and metadata
document) in two different Database. We have a condition that if any one of
the insert operation fails we need to rollback the entire transaction.(i.e.
Need to revoke the last insert operation)

ML version 5.0
Example:

Consider a  main.xqy which will invoke a file "check.xqy".
main.xqy 

xdmp:invoke( ("/check.xqy")), (
  xs:QName("input"), xdmp:quote($input),
   ),())
 

check.xqy - We have used invoke statements to call "insertFirst.xqy" and
"insertSecond.xqy" to insert the documents. Database in which these
documents should get loaded will be mentioned in these "insertFirst" and
insertSecond" xqy files.

let $res1 := xdmp:invoke( ("/insertFirst.xqy")), (
            xs:QName("input"), $input,
                ),())
return if(fn:not( fn:contains( $res1, "Error"))) then

        let $res2 = xdmp:invoke( ("/insertSecond.xqy")), (
                    xs:QName("input"), $input,
                   ),())
        return  if(fn:not( fn:contains( $res2, "Error"))) then 
                    (: "Need to rollback the insertOne changes" :)
                          xdmp:rollback()

                else
                    ( :"Success and commit both insert operation" :)
                   xdmp:commit()
        else
        ( "Throw exception")

We are unable to commit/rollback the entire transaction. we tried  "declare
option xdmp:transaction-mode "update";" or
"<isolation>same-statement</isolation>  " options.

Added  "xdmp:commit()" or "xdmp:rollback" based on the success/failure , but
after these commit/rollback statements , we couldn't able to process any
other statements in the xqy file.

Please suggest how to handle  this scenario to rollback the transaction.

Regards,
Jonna



 

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to