question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Panache MongoDB - Optimistic lock control

See original GitHub issue

Hi guys, hope you are doing well.

I was thinking about something I’ve commented in another ticket some time ago, but in that ticket we are talking about MongoDB migrations. What about we include in MongoDB Panache an optimistic lock feature, just like we have in JPA. Spring and other frameworks already have some similar.

I think it is not so complicated to implement, basically we need an annotation @Version or some similar to identify the field used as “version”, and some adjusts in MongoOperations the methods update, and persistOrUpdate.

Today when we call update, in the MongoOperations.update we build the query:

BsonValue id = document.get(ID);
BsonDocument query = new BsonDocument().append(ID, id);

We can change for some like:

BsonValue id = document.get(ID);
BsonValue version = document.get(VERSION);
return new BsonDocument().append(ID, id).append(VERSION, version);

In addition to that we add an OptimisticLockException to inform users trying to update outdated documents.

Do you think it can work?

Best.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

4reactions
nicolinux72commented, Apr 8, 2021

@loicmathieu @diogocarleto

Hi, this change could be very useful, especially when the same collections on MongoDb are used simultaneously by Quarkus and SpringData. Do you plan to release it soon?

2reactions
diogocarletocommented, Feb 25, 2021

@loicmathieu do you think it makes sense?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simplified Hibernate ORM with Panache - Quarkus
Lock management ​​ Panache provides direct support for database locking with your entity/repository, using findById(Object, LockModeType) or find(). withLock( ...
Read more >
Optimistic locking in Mongo - Medium
Optimistic locking. Usually, by locking we understand denying other clients to modify or in some cases even read some locked record(s).
Read more >
How To SELECT ... FOR UPDATE inside MongoDB ...
MongoDB uses multi-granularity locking that allow shared access to a resource, such as a database or collection. There is a detailed description ...
Read more >
Optimistic locking with Spring Data MongoDB - Evojam
Optimistic locking with Spring Data MongoDB ... When it comes to data access concurrency issues, skewed writes are about as troublesome as they ......
Read more >
C# MongoDb Dependency Injection & Inversion of Control ...
[Solved]-C# MongoDb Dependency Injection & Inversion of Control-mongodb ... mongoDB injection · MongoDB Optimistic Concurrency Control With .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found