You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by ms...@email.cz on 2012/02/06 16:07:56 UTC

Any way how to remove node lock?

Hi,

I experimented with node locking. I am under JBoss with XATransaction and if I understand this correctly it means it has now container managed transactions which means transaction starts when I create new session and end on session logout.

To make lock visible to another session I used:
newSession
lock Node
session logout

newSession
modifyNode
unlock Node
session logout

I just found that I have to transfer lock token so fixed version is:
newSession
lock Node
get lock token
session logout

newSession
add lock token
modifyNode
unlock Node
session logout

Is it correct? But from my first incorrect test I have now some locked nodes. Is there any wahy how to remove locks
from nodes?

Thanks

Marek

Re: Re: Re: Re: Re: Re: Any way how to remove node lock?

Posted by ms...@email.cz.
So to answer my original question: It is possible but not in 2.2.9.

See https://issues.apache.org/jira/browse/JCR-2859

Following code sample should do it:
                LockManager lockManager = session.getWorkspace().getLockManager();
                Lock lock = null;
                try {
                    lock = lockManager.getLock(node.getPath());
                } catch (LockException ex) {                    
                }
                if (lock != null) {
                    lockManager.addLockToken(lock.getLockToken());
                    lockManager.unlock(node.getPath());
                }

Unfortunately from Jackrabbit JIRA I am not able to say in which version is will appear. (Of course I could backport this
patch and it should work as it is simple.) But as I said above I will use in memory locking because it is what I need. I do not need persistent locking when only one application writes to repository.

Marek

Re: Re: Re: Re: Re: Any way how to remove node lock?

Posted by ms...@email.cz.
Yes. It was exactly reason why it failed. I need to store lock token to another variable.
Now it works. 

Thanks a lot for hint.

Marek

> ------------ Původní zpráva ------------
> Od: Mark Herman <MH...@NBME.org>
> Předmět: Re: Re: Re: Re: Any way how to remove node lock?
> Datum: 06.2.2012 18:10:37
> ----------------------------------------
> Check your 2nd lock.getLockTocken().  There is a chance that it's returning
> null since you disconnected that session where the object was retrieved
> from.  
> 
> Also, output a session.getUserID() just to be 100% who you're running as.
> I'm not too familiar with the config you gave earlier, but it's possible
> repository.login() is being called which results in an anonymous session.
> 
> --
> View this message in context:
> http://jackrabbit.510166.n4.nabble.com/Any-way-how-to-remove-node-lock-tp4361516p4361987.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
> 
> 
> 

Marek Slama
mslama@email.cz

Re: Re: Re: Re: Any way how to remove node lock?

Posted by Mark Herman <MH...@NBME.org>.
Check your 2nd lock.getLockTocken().  There is a chance that it's returning
null since you disconnected that session where the object was retrieved
from.  

Also, output a session.getUserID() just to be 100% who you're running as.
I'm not too familiar with the config you gave earlier, but it's possible
repository.login() is being called which results in an anonymous session.

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Any-way-how-to-remove-node-lock-tp4361516p4361987.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Re: Re: Re: Any way how to remove node lock?

Posted by ms...@email.cz.
I found another problem with transferring lock token between sessions:

        Lock lock = null;
        Session session;
        session = sessionFactory.newSession();
        try {
            lock = tryLockNode(session, companyPath);
            logger.debug("LockToken:" + lock.getLockToken());
            session.save();
        } finally {
            session.logout();
        }
        session = sessionFactory.newSession();
        LockManager lockManager = null;
        try {
            if (lock != null) {
                lockManager = session.getWorkspace().getLockManager();
                lockManager.addLockToken(lock.getLockToken());
            }
            return doUpdateCompany(session, company, sendMessage, containerId, companyPath);
        } finally {
            if (lockManager != null) {
                lockManager.unlock(companyPath);
            }
            session.logout();
        }

with this code I still get Caused by: javax.jcr.lock.LockException: Node not locked by session: 8dc7ae65-fc46-46d7-a73b-5077808edbef
	at org.apache.jackrabbit.core.lock.LockManagerImpl.checkUnlock(LockManagerImpl.java:773) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.lock.LockManagerImpl.checkUnlock(LockManagerImpl.java:754) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.lock.XALockManager.checkUnlock(XALockManager.java:207) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.lock.SessionLockManager.unlock(SessionLockManager.java:202) [jackrabbit-core-2.2.9-noLogs.jar:]
....
when lockManager.unlock(companyPath);

So it looks like transfering lock token between sessions does not work as I expected. To get lock I use:
lock = lockManager.lock(nodePath, false, false, Long.MAX_VALUE, "");

For now I give up using JCR node locking.
As I said before I assumed I must use separate session to lock node so that another sessions will see this lock in my
JBoss env with XATransaction support.

I checked LockerManagerImpl.checkUnlock and its javadoc says:
Default implementation allows unlocking to the lock holder only.

I am looking at Jackrabbit sources now to see if I find anything.

Marek

> ------------ Původní zpráva ------------
> Od: Mark Herman <MH...@NBME.org>
> Předmět: Re: Re: Re: Any way how to remove node lock?
> Datum: 06.2.2012 17:17:01
> ----------------------------------------
> I tried using locks for my application, but ultimately had to take them out. 
> Using admin seemed to solve my problems, but it was not an option to hard
> code admin credentials to create new sessions when needed to address them.
> 
> Locks in Jackrabbit seem a bit too "serious" (perhaps not JR's fault but
> JCR).  It would be nice if you could at least grant access to override locks
> without a lock token.
> 
> For my application I eventually stopped using locking and implemented the
> functionality i needed in my layer above JR.  Luckily for me, that is a
> single java api so it was pretty easy, maybe it's an option for you. 
> 
> --
> View this message in context:
> http://jackrabbit.510166.n4.nabble.com/Any-way-how-to-remove-node-lock-tp4361516p4361768.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
> 
> 
> 

Marek Slama
mslama@email.cz

Re: Re: Re: Any way how to remove node lock?

Posted by Mark Herman <MH...@NBME.org>.
I tried using locks for my application, but ultimately had to take them out. 
Using admin seemed to solve my problems, but it was not an option to hard
code admin credentials to create new sessions when needed to address them.

Locks in Jackrabbit seem a bit too "serious" (perhaps not JR's fault but
JCR).  It would be nice if you could at least grant access to override locks
without a lock token.

For my application I eventually stopped using locking and implemented the
functionality i needed in my layer above JR.  Luckily for me, that is a
single java api so it was pretty easy, maybe it's an option for you. 

--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Any-way-how-to-remove-node-lock-tp4361516p4361768.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Re: Re: Any way how to remove node lock?

Posted by ms...@email.cz.
Hmm,

only way I found so far is to call remove on locked node. But it is just last resort.

One weird thing I found is that when I used:
if (node.isLocked()) {
  node.remove();
} else {
  node.setProperty
}

it throws exception about locked node when node.setProperty is called. I would expect if node is locked node.isLocked() returns true.

Relevant call stack:
Caused by: javax.jcr.lock.LockException: Node locked.
	at org.apache.jackrabbit.core.lock.LockManagerImpl.checkLock(LockManagerImpl.java:734) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.lock.LockManagerImpl.checkLock(LockManagerImpl.java:713) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.lock.LockManagerImpl.checkLock(LockManagerImpl.java:700) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.lock.XALockManager.checkLock(XALockManager.java:174) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.ItemValidator.checkLock(ItemValidator.java:367) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.ItemValidator.checkCondition(ItemValidator.java:288) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.ItemValidator.checkModify(ItemValidator.java:248) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.AddMixinOperation.perform(AddMixinOperation.java:70) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:200) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.ItemImpl.perform(ItemImpl.java:91) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.NodeImpl.addMixin(NodeImpl.java:902) [jackrabbit-core-2.2.9-noLogs.jar:]
	at org.apache.jackrabbit.core.NodeImpl.addMixin(NodeImpl.java:2306) [jackrabbit-core-2.2.9-noLogs.jar:]

For my use case I need only application scoped node locks ie. persistent only during application run. Current node locking
is too strong especially when there is no easy way how to 'reset' locks when something goes wrong.

Marek

> ------------ Původní zpráva ------------
> Od:  <ms...@email.cz>
> Předmět: Re: Re: Any way how to remove node lock?
> Datum: 06.2.2012 16:30:55
> ----------------------------------------
> 
> It looks I am helpless because I use:
> 
>     <bean id="credentials" class="javax.jcr.SimpleCredentials">
>         <constructor-arg index="0" value="admin"/>
>         <constructor-arg index="1">
>             <bean factory-bean="password" factory-method="toCharArray"/>
>         </constructor-arg>
>     </bean>
> 
>     <bean id="password" class="java.lang.String">
>         <constructor-arg index="0" value=""/>
>     </bean>
> 
> This is passed to repository.login for my development environment and it does
> look like admin account.
> 
> Marek
> > ------------ Původní zpráva ------------
> > Od: Mark Herman <MH...@NBME.org>
> > Předmět: Re: Any way how to remove node lock?
> > Datum: 06.2.2012 16:15:24
> > ----------------------------------------
> > 
> > mslama wrote
> > > 
> > > 
> > > But from my first incorrect test I have now some locked nodes. Is there
> > > any wahy how to remove locks from nodes?
> > > 
> > > 
> > 
> > 
> > The only way I have found is to log in as the "admin" account.  That seems
> > to be able to clean up the locks without following the normal rules.  
> > 
> > FYI, you also have to be careful about not logging out. I found that if
> > somewhere you have code that doesn't result in a logout() or you get a hard
> > crash, that session will remain and even if you know the lock token, JR
> > won't let you add it to a 2nd session.
> > 
> > 
> > 
> > --
> > View this message in context:
> >
> http://jackrabbit.510166.n4.nabble.com/Any-way-how-to-remove-node-lock-tp4361516p4361534.html
> > Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
> > 
> > 
> > 
> 
> Marek Slama
> mslama@email.cz
> 
> 
> 

Marek Slama
mslama@email.cz

Re: Re: Any way how to remove node lock?

Posted by ms...@email.cz.
It looks I am helpless because I use:

    <bean id="credentials" class="javax.jcr.SimpleCredentials">
        <constructor-arg index="0" value="admin"/>
        <constructor-arg index="1">
            <bean factory-bean="password" factory-method="toCharArray"/>
        </constructor-arg>
    </bean>

    <bean id="password" class="java.lang.String">
        <constructor-arg index="0" value=""/>
    </bean>

This is passed to repository.login for my development environment and it does look like admin account.

Marek
> ------------ Původní zpráva ------------
> Od: Mark Herman <MH...@NBME.org>
> Předmět: Re: Any way how to remove node lock?
> Datum: 06.2.2012 16:15:24
> ----------------------------------------
> 
> mslama wrote
> > 
> > 
> > But from my first incorrect test I have now some locked nodes. Is there
> > any wahy how to remove locks from nodes?
> > 
> > 
> 
> 
> The only way I have found is to log in as the "admin" account.  That seems
> to be able to clean up the locks without following the normal rules.  
> 
> FYI, you also have to be careful about not logging out. I found that if
> somewhere you have code that doesn't result in a logout() or you get a hard
> crash, that session will remain and even if you know the lock token, JR
> won't let you add it to a 2nd session.
> 
> 
> 
> --
> View this message in context:
> http://jackrabbit.510166.n4.nabble.com/Any-way-how-to-remove-node-lock-tp4361516p4361534.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
> 
> 
> 

Marek Slama
mslama@email.cz

Re: Any way how to remove node lock?

Posted by Mark Herman <MH...@NBME.org>.
mslama wrote
> 
> 
> But from my first incorrect test I have now some locked nodes. Is there
> any wahy how to remove locks from nodes?
> 
> 


The only way I have found is to log in as the "admin" account.  That seems
to be able to clean up the locks without following the normal rules.  

FYI, you also have to be careful about not logging out. I found that if
somewhere you have code that doesn't result in a logout() or you get a hard
crash, that session will remain and even if you know the lock token, JR
won't let you add it to a 2nd session.



--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Any-way-how-to-remove-node-lock-tp4361516p4361534.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.