java-json-tools/json-patch

Synchronization issue in using this library

Opened this issue · 2 comments

Maybe I am missing something

but in using this library I am creating a sync issue

Thread = T

in the DB:
Class Foo {
int x = 1;
int y = 1;
}

T1 get Foo (x=1, y=1)
T2 get Foo and updates y=2 (x=1, y=2)
T1 update Foo to x=5 (x=5, y=1)

and partial update is not an option because there is not access to the Operation/Path/Value we update

for a server with multiple replica set i need to create a distributed lock in order to avoid sync issue

am i missing any thing?

I am using spring framework

and referring to this article on the implementation of a server controller
https://www.baeldung.com/spring-rest-json-patch#2-the-rest-controller-method

This is a classical concurrent programming issue, not specific to this library.
What I would recommend to you would be to use a version field on your entity and use optimistic locking.
A good idea would be to make the updates transactional as well. If you don't have transaction support on your database, or you want better read performance still, then optimistic locking with a version would be your best bet.