Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) with @SqlListener using

40 Views Asked by At

It happens with code which is under nda, so i try explain maximum information i can.

I have a simple implementation of SQS Listener: @SqsListener(value = "${sqs.balance.calculator}", maxConcurrentMessages = "1", maxMessagesPerPoll = "1") Below this annotation i have the method, which get message from SQS and adjust the balance. The balance is same entity for all messages. Method which inside the listener method annotated with @Transactional. So, sometimes i catch error you can see in a header of question. I can't share StackTrace, but i noticed that in root were two exceptions: ObjectOptimisticLockingFailureException and StaleObjectStateException. So in my opinion that occurs because i try to adjust the same balance, but sqs is async working.

Also you can see that i set maxConcurrentMessages and maxMessagesPerPoll to 1. I tried to do listener works sync. Performance for me almost not important, important is correct calculation.

So this approach reduced most of these cases. But sometimes, i catch them, despite what i seem to have done it sync. I noticed also that system still scales: enter image description here and this occurs regardless my activities: It doesn't matter i do 1 transaction or 100. It seems that system scaling and downscaling when it want. I also need notice, that i use spring boot auto configuration for sqs: I only have url and creds for queue in my applications props (no configuration files with beans). The queue is FIFO

I have one theoretical way to resolve it: Do retry if catch this exceptions, but lead told find another way =)

So have i any way to fix it and do it sync in my case? Help please!

0

There are 0 best solutions below