cancel
Showing results for 
Search instead for 
Did you mean: 

How to lock a node in a clustered environment

broeks
Champ in-the-making
Champ in-the-making
Hi. I've been googling around on this, and I'm not quite sure the best approach.

My scenario –

User creates a child node. This node has a mandatory, unique property (prop A) that is constructed based off of a property on the parent node (prop B). The result of creating the child node also includes updating the parent's prop B node, so that a potential next child node would not receive the same (prop B) property on which to base their (prop A) property.

I have captured all of this behavior in an aspect, but I'm worried about concurrency amongst a cluster of servers. I've implemented a solution using  Alfresco LockService, but I can't seem to find out if it locks across multiple servers. Is this dependent on the cluster set up?

Any advice is greatly appreciated.

Thanks!
2 REPLIES 2

mrogers
Star Contributor
Star Contributor
The lock service will work O.K. in a clustered environment.

You can also use the JobLockService if there's a particular set of operations than need to be protected rather than just a property on a single node.

However your design has contention on your parent node which may mean that the conflicting transactions will fail and retry.   If you use the RetryingTransactionHandler (as Alfresco does internally)  then this should be handled automatically.   Also If you can come up with a design that does not contend for the parent node then that will perform better.

broeks
Champ in-the-making
Champ in-the-making
Thanks for the info. Based on what you've said, I'm going to try doing something like this. Do I need to use the lock service within the transaction as well, to ensure that another user isn't able to modify values on nodes I"m working with until the previous user is done working with them? Or is that handled?

The contention issue you bring up is definitely valid. However there won't be a large volume of writes occurring simultaneously by different users – what is more important at this point is ensuring that we can't get into the situation.

Is there any other sources of documentation for transactions? So far, I've been reading the unit tests and other source code from alfresco itself.

RetryingTransactionCallback<Boolean> callback = new RetryingTransactionCallback<Boolean>()
            {
               private myNodeToModify;
                public Boolean execute() throws Throwable
                {
                 // get lock on nodes I'm working with to ensure nobody else can jump in and change them halfway through? 
                 //do stuff with node service, myNodeToModify, and myNodeToModify parent
                }
              
               public setMyNodeToModify(value){//}

            };