I have came across one scenario in web application which runs on clustered environment.
We have 2 nodes(both has JVM)
- Node1
- Node2
I am running one database transaction in my application where sequence_no is read and later we increment it with plus 1 like
select sequence from some_table;
nextsequence = sequence + 1; // incrementing sequence
update some_table set sequence = nextsequence; // set the next sequence
Now what happened request goes to Node1 and it increments the sequence no. but was commited slowly to database(takes 1 minute) due to outofmemoryerror on node1. meanwhile another request is gone to Node2 and take sequence no. from database and update it. So both the request got same sequence which we don't wont as we want unique sequence no. for all the requests.
We cannot synchronize transactions as it will not help because it runs on different JVM.
I am wondering what to do next ? Any help is greatly appriciated.