cancel
Showing results for 
Search instead for 
Did you mean: 

ConcurrencyFailureException: Failed to update node

spilby
Confirmed Champ
Confirmed Champ
I'm using Alfresco Enterprise v4.1.6

I create a new node and then modify some properties of the parents doing a getNodeService().addProperties.

Sometimes, this addProperties fails and give me a org.springframework.dao.ConcurrencyFailureException: Failed to update node 288941

And when it occurs, I can't see the node that I create and can't doing anything on this node. Only works again if I restart Alfresco tomcat server.

I supose that this ocurrs because various users create nodes with same parents and modify the properties at a same time.  

What can I do to solve this? How do you modify properties or nodes for avoid this exception?

Thank you!
21 REPLIES 21

spilby
Confirmed Champ
Confirmed Champ
But I don't add a child to a delete node. I delete a node with the alfresco explorer and create again with my webscript. And if I don't update the properties, all works ok. The node is created without problems, and I can see it in Alfresco Explorer. Only the updating properties give the problem. 

Maybe is complicate to explain… In resume:

- Run webscript. It creates a folder A, a folder B, a folder C, puts a content in C and update properties of C, B and A. (THIS WORKS) Path obtained: A / B / C

- Go to Alfresco Explorer and delete the node B.

- Run webscript. It creates a folder B (child of A), create a folder C, put a content in C, update the properties of C, B and when try to update the properties of A, throw the concurrency exception. Path obtained: A

If I change my code and don't change properties, only create nodes and put content, all works. Only the getNodeService().addProperties gives the problem.

I try to wait 1 minute before update the properties, but the same error. The properties are blocked forever if I delete the node with Alfresco Explorer. Only if i restart the server I can update the properties again.



romschn
Star Collaborator
Star Collaborator
One more thought would be to separate out your folder creation logic and adding properties logic in two different transactions programmatically.


UserTransaction trx_A = transactionService.getNonPropagatingUserTransaction();
try{
trx_A.begin();
//Folder Creation logic
trx_A.commit();
} catch(Throwable e) {
                        try {
            trx_A.rollback();
         } catch (Throwable ee) {
         
         }
}
//Create another transaction and do same as above and add properties add logic if folder creation was success


Also, for deletion part, i am assuming you want to delete child folder and update parent folder's property. For this scenario as well separate the logic in two different transaction as mentioned above.

See implementing this way works for you or not.

Hope this helps.

spilby
Confirmed Champ
Confirmed Champ
To delete the folder I use the Alfresco Explorer. One thing that I don't understand is that the webscript works fine until I delete from Explorer. I run my webscript X times and works all of them. Only don't works after the delete. And the webscript is the same. And if I restart the server the webscript works again. I supose that if my code don't works, the exception throws always, not only after the delete of the node with the explorer.

Is possible that the explorer have a problem that blocks the modification of the properties of a node, if I delete one of his sons, until the restarting of the server?

romschn
Star Collaborator
Star Collaborator
What options you select while deleting the parent space from alfresco explorer?

spilby
Confirmed Champ
Confirmed Champ
I put the mouse over the folder, click on More, and then Delete folder.

I attach a image.

romschn
Star Collaborator
Star Collaborator
Are you able to manually generate the scenario? I mean, Create a folder structure manually, delete the child  and then add the properties on the parent (through aspect or try modifying existing properties) and see if that causes the problem or not. Again create the same folder hierarchy and repeat the steps and see if it triggers the problem or not. Try following same thing as you do programmatically and see what is the outcome of it. This may help to understand and identify where to look into further to find the solution for the issue you are facing.

Hope this helps.

spilby
Confirmed Champ
Confirmed Champ
Ramesh, I try your solution with transactions, and works! Smiley Surprised) I insert my methods inside the begin and commit, and seems that the problem has been solved. A lot of thanks, Ramesh!

Two questions about this. Is a good practice use always transactions? In the examples that I read on tutorials or forums, don't use usually transactions. Maybe in my case, that do different actions in the same webscript, like create nodes or update properties, is the most correct?

And the other… Why getNonPropagatingUserTransaction and not getUserTransaction? What's the difference?

Thanks again!

romschn
Star Collaborator
Star Collaborator
Glad it worked for you and you finally are now able to get rid of the exception you were getting.

Generally, it is not suggested to explicitly handle the transactions in the custom code. However, to my opinion, if required we can use the explicit transactions to meet the requirement and good thing is that Transaction Service provides the required APIs to do that so we can leverage on it. In your scenario it appears that it was something related to transaction which was causing the exception. Hence, handling the transactions explicitly we made sure that we have the processed node for adding properties hence it should not cause any exceptions on it while adding the properties.

The reason for using non-propagating transaction is - it uses the propagation as REQUIRES_NEW. Hence, each time a new transaction will be created wherein user transaction use the propagation as REQUIRES which means that if the transaction is already running it will take that or else will create a new transaction. So, in order to make sure that each time a new transaction is used non-propagating transaction was mentioned.

Hope this answers your question.

spilby
Confirmed Champ
Confirmed Champ
Yes, it seems that something when I delete the node from the Alfresco Explorer blocks a transaction with the properties, and the commit on all the transactions that I do before change the properties, solve this issue.

Is strange because if I don't put the UserTransaction in the code, each operation (createNode, putContent, addProperties, etc) is doing with her own transaction (if I understand it). Control the transaction only serves for doing 2 or more operations in a same transaction. But isn't my case. I do a transaction for each operation. But I need to put it to solve the concurrency exception.

One question more about the non-propagating… Oks, the non-propagating (REQUIRES_NEW) ensures that the transaction is new always. I supose that the problem using the getUserTransaction is that if the transaction is already running, and I use that, the concurrency problem may appears another time. But use always a new transaction, could give me problems of performance? A lot of users will use this service, and for each one the code will use 4 o 5 transactions (one for each operation). This could cause problems? In which times is better use the running transaction (getUserTransaction option)?

Thanks again!


spilby
Confirmed Champ
Confirmed Champ
Well… the problem continues, more or less… Smiley Surprised( When I delete a node with the Alfresco Explorer and then add more nodes and change the properties with my webscript, the problem has been resolved adding the transactions. All ok. I think all goes ok.

But… now the addProperties give me a concurrency exception if before I EDIT the properties with the Alfresco Explorer and save. ¿?¿?¿?

In resume… I go to a folder with the Alfresco Explorer, edit the properties (right mouse button) and save. This node seems to be blocked, until I restart the server. I can't call to addProperties in my webscript because it returns me the concurrency exception.

I don't understand nothing, the delete problem has been resolved with the transactions, but modify properties seems to run different. What's the problem with the Alfresco Explorer? Why block the properties of the nodes? Smiley Surprised?