-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ReplaceChangeLogLockStatement #582
base: main
Are you sure you want to change the base?
Conversation
Hi @filipelautert @KushnirykOleh, is there anything else should I improve about this PR? |
Hi @raffaeleflorio , thanks for the PR! Would you be able to convert you example from the description to an unit/integration test? |
Hi @filipelautert I've just pushed I also wrote a test in the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one comment related to.... comments. Besides it looks good! @KushnirykOleh could you review it too?
src/test/java/liquibase/ext/mongodb/lockservice/ReplaceChangeLogLockStatementIT.java
Outdated
Show resolved
Hide resolved
|
The current
update
method ofReplaceChangeLogLockStatement
is not safe. It allows multiple owner (identified by thelockedBy
field) to acquire the lock simultaneously. And it also allows the release by a different owner. There isn't any fence in the current implementation:liquibase-mongodb/src/main/java/liquibase/ext/mongodb/lockservice/ReplaceChangeLogLockStatement.java
Lines 77 to 84 in 5582bcd
Indeed, by running the following code with the latest liquibase-mongodb version there will be also multiple exceptions:
The proposed implementation blocks multiple acquisition by taking advantage of the Mongo DuplicateKey error. Specifically, an owner will try to acquire only an unlocked lock. And we have multiple scenarios here:
The same approach is used to allow the lock release only by his owner.