Hi Geert ,
Thanks for your explanation.
Yes you are right., But still the other user is able to update the
document which is locked by some other user. (Where both of my user has
admin privilege.)
I locked the document harmonyUsers.xml using (admin user)
xquery version "1.0-ml";
xdmp:lock-acquire("harmonyUsers.xml", "exclusive", "infinity", "admin
user has locked the file", ())
when i execute
xdmp:document-locks("harmonyUsers.xml")
It returned
<lock:lock xmlns:lock="http://marklogic.com/xdmp/lock">
<lock:lock-type>write</lock:lock-type>
<lock:lock-scope>exclusive</lock:lock-scope>
- <lock:active-locks>
- <lock:active-lock>
<lock:depth>infinity</lock:depth>
<lock:owner>admin user has locked the file</lock:owner>
<lock:timeout>0</lock:timeout>
<lock:lock-token>http://marklogic.com/xdmp/locks/6b0a37d2dfff88ed</
lock:lock-token>
<lock:timestamp>1237974934</lock:timestamp>
<sec:user-id xmlns:sec="http://marklogic.com/xdmp/security">
15957104643729017271</sec:user-id>
</lock:active-lock>
</lock:active-locks>
</lock:lock>
When i opened another cq instance with different user (santhosh , who also
has admin privilege) and executed the following xquery :
xquery version "1.0-ml";
<role-screen>
{
try {
let $u := doc("harmonyUsers.xml")/users
return
if($u) then (
xdmp:node-insert-child($u, <user>
<userName>user1</userName>
<userId>user1</userId>
<password>password1</password>
<role>1021</role>
</user>)
)
else ()
} catch($e) {
"Error in updating the document harmonyUsers.xml" , $e
}
}
</role-screen>
This is executing fine and inserting a new element to the document even
though the document (harmonyUser.xml) is locked by another user (admin).
But, as per the requirement it should not perform insert operation untill
it is released by admin user.
What should be done in this senario to stop the second user from modifying
the document locked by the first user?
Thanks and Regards,
Santhosh Rajasekaran
Tata Consultancy Services
Mailto: [email protected]
Website: http://www.tcs.com
____________________________________________
Experience certainty. IT Services
Business Solutions
Outsourcing
____________________________________________
Geert Josten <[email protected]>
Sent by: [email protected]
03/20/2009 09:22 PM
Please respond to
General Mark Logic Developer Discussion <[email protected]>
To
General Mark Logic Developer Discussion <[email protected]>
cc
Subject
RE: [MarkLogic Dev General] problem in locking a document using
xdmp:lock-acquire() function in marklogic - reg.,
Hi Santhosh,
Doing two consecutive calls to xdmp:lock-acquire like that means you are
executing them as the same user. This is allowed, and effectively works
like a lock refresh. You will notice that the timestamp is changed at the
second lock-acquire, when retrieving the lock info in between and
afterwards. The lock-token also changes.
I executed the following from CQ as one of my test admin users:
xquery version "1.0-ml";
xdmp:lock-acquire("test", "exclusive", "0", "user 1", 60
(: seconds :));
xdmp:document-locks("test");
xdmp:lock-acquire("test", "exclusive", "0", "user 1", 60
(: seconds :));
xdmp:document-locks("test")
Which resulted in:
<lock:lock xmlns:lock="http://marklogic.com/xdmp/lock">
<lock:lock-type>write</lock:lock-type>
<lock:lock-scope>exclusive</lock:lock-scope>
<lock:active-locks>
<lock:active-lock>
<lock:depth>0</lock:depth>
<lock:owner>user 1</lock:owner>
<lock:timeout>60</lock:timeout>
<lock:lock-token>
http://marklogic.com/xdmp/locks/bb7f84e5b862aaf5</lock:lock-token>
<lock:timestamp>1237563585</lock:timestamp>
<sec:user-id xmlns:sec="
http://marklogic.com/xdmp/security">16820305860789264222</sec:user-id>
</lock:active-lock>
</lock:active-locks>
</lock:lock>
<lock:lock xmlns:lock="http://marklogic.com/xdmp/lock">
<lock:lock-type>write</lock:lock-type>
<lock:lock-scope>exclusive</lock:lock-scope>
<lock:active-locks>
<lock:active-lock>
<lock:depth>0</lock:depth>
<lock:owner>user 1</lock:owner>
<lock:timeout>60</lock:timeout>
<lock:lock-token>
http://marklogic.com/xdmp/locks/fcd14040d3c75679</lock:lock-token>
<lock:timestamp>1237563587</lock:timestamp>
<sec:user-id xmlns:sec="
http://marklogic.com/xdmp/security">16820305860789264222</sec:user-id>
</lock:active-lock>
</lock:active-locks>
</lock:lock>
(The uri "test" happens to point to some test document in my local
MarkLogic Server database.)
I then executed the same code in a different CQ instance in which I logged
in as some other test admin user. I did so before the lock was timed out.
This resulted in the following exception:
[1.0-ml] XDMP-LOCKCONFLICT: xdmp:lock-acquire("test",
"exclusive", "0", "user 1", 60) -- A conflicting lock exists on this
document
Stack trace:
line 3:
1: xquery version "1.0-ml";
2:
3: xdmp:lock-acquire("test", "exclusive", "0", "user 1",
60 (: seconds :));
4:
5: xdmp:document-locks("test");
xdmp:eval("xquery version
"1.0-ml"; xdmp:lock-...", (), <options
xmlns="xdmp:eval"><database>5730891291474139731</database><modules>0</modules><def...</options>)
So, it does work exclusively, but you will have to use different users. If
you cannot use different users, but have to resort to application-level
users, then read this thread: http://markmail.org/thread/olpid5r34mkg6fza
Note: keep also in mind that releasing locks is usually only allowed to
the user that has acquired the lock, but as admin you are allowed to
release any lock.
Kind regards,
Geert
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Santhosh Raj
> Sent: vrijdag 20 maart 2009 15:06
> To: General Mark Logic Developer Discussion
> Subject: RE: [MarkLogic Dev General] problem in locking a
> document using xdmp:lock-acquire() function in marklogic - reg.,
>
>
> Hi Geert Josten,
>
> I have tried all the options for the lock method, the
> doucment is locked, but still other user can able to update
> the document even though the lock is not yet released.
>
>
> xdmp:lock-acquire("harmonyUsers.xml",
> "exclusive",
> "infinity",
> "Admin has locked the document",
> ())
>
> xdmp:lock-acquire("harmonyUsers.xml",
> "exclusive",
> "infinity",
> "Admin has locked the document",
> xs:unsignedLong(1200))
>
> xdmp:lock-acquire("harmonyUsers.xml")
>
> What should i do?
>
> When i execute this:
> <root>
> {
> for $locks in xdmp:document-locks()
> return <document-URI>{xdmp:node-uri($locks)}</document-URI>
> }
> </root>
>
> It is returning the document which i have locked, that means
> the document is getting locked, but still there is no use of
> that lock, any how the other user is able to update/insert
> the node in the document still.
>
>
>
> Thanks and Regards,
> Santhosh Rajasekaran
> Tata Consultancy Services
> Mailto: [email protected]
> Website: http://www.tcs.com <http://www.tcs.com/>
> ____________________________________________
> Experience certainty. IT Services
> Business Solutions
> Outsourcing
> ____________________________________________
>
>
>
> Geert Josten <[email protected]> Sent by:
> [email protected]
>
> 03/20/2009 03:09 PM
> Please respond to
> General Mark Logic Developer Discussion
> <[email protected]>
>
> To
> General Mark Logic Developer Discussion
> <[email protected]> cc Subject
> RE: [MarkLogic Dev General] problem in locking a document
> using xdmp:lock-acquire() function in marklogic - reg.,
>
>
>
>
>
>
> Hi Santhosh,
>
> You are passing the value "shared" as second argument to
> xdmp:lock-acquire(). You should rather use "exclusive"
> instead. Moreover, if you are just trying to synchronize
> updates to this file, MarkLogic Server does that
> automatically. You might want to look at how so-called
> 'write-locks' work. I believe it is mentioned in the
> Developers guide.
>
> Kind regards,
> Geert
>
>
>
> Drs. G.P.H. Josten
> Consultant
>
> <http://www.daidalos.nl/>
> Daidalos BV
> Source of Innovation
> Hoekeindsehof 1-4
> 2665 JZ Bleiswijk
> Tel.: +31 (0) 10 850 1200
> Fax: +31 (0) 10 850 1199
> www.daidalos.nl <http://www.daidalos.nl/>
> KvK 27164984
> De informatie - verzonden in of met dit emailbericht - is
> afkomstig van Daidalos BV en is uitsluitend bestemd voor de
> geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen,
> verzoeken wij u het te verwijderen. Aan dit bericht kunnen
> geen rechten worden ontleend.
>
>
> ________________________________
>
> From: [email protected]
> [mailto:[email protected]
> <mailto:[email protected]> ] On Behalf
> Of Santhosh Raj
> Sent: vrijdag 20 maart 2009 7:17
> To: [email protected]
> Subject: [MarkLogic Dev General] problem in locking a
> document using xdmp:lock-acquire() function in marklogic - reg.,
>
>
>
> Hi all,
>
> I want to lock a particular document present in the
> marklogic database, so that other users can't do any update/
> modification to that document untill the lock is released.
>
> To achieve this task marklogic provides inbuilt functions
>
> xdmp:lock-acquire() - Acquire a lock on a document or
> directory .
>
> xdmp:lock-release() - Unlock a document or directory.
>
> I used xdmp:lock-acquire() to lock a document by an user,
> but still that particular document is
> modifiable(update/insert data to that document) by other user.
>
> Locking of document: (Current user name is : admin)
>
> <result>
> {
> try{
> <current-user>
> {
> xdmp:get-current-user( )
> }
> </current-user>,
>
> xdmp:lock-acquire("harmonyUsers.xml",
> "shared",
> "infinity",
> <href>http://example.com/~user
> <http://example.com/~user> </href>,
> ())
>
> }catch ($e) {
> "Error during acquiring lock on the document", $e },
> "Document locked"
>
> }
> </result>
>
>
> Inserting a record to the same document (locked) by another
> user : (Current user name is : santhosh)
>
> xquery version "1.0-ml";
> (: __________________________________________________________
> :: (Q1.1)
> :: Trying to insert a child node to the locked document.
> ::
> :: __________________________________________________________
> :)
> <role-screen>
> {
> let $u := doc("harmonyUsers.xml")//use...@locked="false"]
> return
> if($u) then (
> xdmp:node-insert-child($u,<user>
> <userName>sonabh123</userName>
> <userId>sonabh123</userId>
> <password>sonabh123</password>
> <role>123456</role>
> </user>),
> xdmp:get-current-user( )
> )
> else ()
>
> }
> </role-screen>
>
> This insert operation is done successfully even though the
> document is locked by other user(admin) .
>
> This is the document which i loaded to marklogic server.
>
>
> Can any body please suggest some solution or idea to this problem.
>
> Thanks in advance.
>
>
>
>
> Regards,
> Santhosh Rajasekaran
> Tata Consultancy Services
> Mailto: [email protected]
> Website: http://www.tcs.com <http://www.tcs.com/>
> ____________________________________________
> Experience certainty. IT Services
> Business Solutions
> Outsourcing
> ____________________________________________
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
> <http://xqzone.com/mailman/listinfo/general>
>
> ForwardSourceID:NT000096BA
>
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
> _______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
ForwardSourceID:NT00009712
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general