Node Getting Overridden while writing to Node | Community
Skip to main content
Level 2
November 3, 2022
Solved

Node Getting Overridden while writing to Node

  • November 3, 2022
  • 1 reply
  • 2170 views

Hi Team

 

I am updating  nodes' properties through a post servlet.

But observing that when simultaneous requests are coming, it's overriding the node.

 

So when the node is being updated it doesn't get locked or blocked in AEM and hence other requests are find this as an available node which can be updated.

 

I have tried making the post method synchronized, but that's not helping either.

 

Could you please suggest a solution for this.

 

Regards

Bishnu

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

Hi @shashi_mulugu 

 

Thanks for responding.

we have a list of unique consumable items for the end user on our application. This list of items have unique id.( e.g. we can consider list of seats in a cinema. -- typically the way a table stores the data with unique key).

 

These we were trying to store in aem nodes with that unique ids.

This is where we are facing issues in solutioning.

 

For these end user consumable items, what approach can be taken up.

 

Regards

Bishnu


Basically you are facing the problem of concurrent writes, and you need to handle that situation on your own. The typical approach is handle failing writes and trying to repeat the operation. Depending on the load on the system and the level of parallel writes up to 3 tries can be sufficient, but it can also continue to fail every now and then.

In that case you need to switch to a different strategy and you need to synchronize the writes like this:

 

synchronized (lockobject) {

  resourceresolver.refresh();

  dothewrites();

  resourceresolver.commit();

}

 

the refresh is important.

 

1 reply

arunpatidar
Community Advisor
Community Advisor
November 3, 2022

If you use a single session then JCR will lock the parallel operation of same node.

 

Can you please explain the usecase here?

Arun Patidar
Level 2
November 4, 2022

Thanks for the response @arunpatidar .

On further analysis we found the issue may be different.

following is the use case.

1. The client could not provision a Data Base and we were asked to maintain the data in AEM.

2. Now that we have long list of nodes containing data, we exposed an API to other team to update the node properties. 

3. Upon receiving the request through servlet we query the list based on unique property and update the node based on availability. And upon successful node save we performed reverse replication to sync the publishers.

4. Now we have realized that when multiple requests come to the server, it is going to different Publisher and updating nodes based on availability. Post that it replicates hence the issue of overriding nodes are happening.

 

We know a DB is recommended for these operations but we are trying to get a workaround through AEM.

 

Regards

Bishnu

joerghoh
Adobe Employee
Adobe Employee
November 4, 2022

Why are doing these operations towards a publish instance?