-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Postgres] StandardLockManager does not work for parallel machines / Liquibase run with multiple instances in parallel lead to error messages (e.g. "already exists") #2315
Comments
Thank you @eaglerainbow for all the detail you have provided here. We are reviewing. By the way if you haven't yet visited https://forum.liquibase.org/ we would love to have you join in the conversations over there. I know other members would clearly benefit from your experience. Thanks again! |
Thanks for your response. The coding looks strangely asymmetric.
Will have a look, if I can help there somewhere... |
I was looking into liquibase again because I wanted to double check if the changes of #2327 still work so that I'm able to spin up multiple OCI containers that all try to update the database schema on a PostgreSQL database. I think that the locking works fine but Failing
Surviving
In the logs you can observe that both services try to apply the same changelog Unfortunately, the test I introdubce in #2327 does not catch that case but I can reliable reproduce this issue. @nvoxland, @kataggart, please, tell us what to do next? Create a new issue? |
Hello @schrieveslaach - those logs were generated using which liquibase version? 4.20.0? Cause if I'm right we added some more resets to the locking mechanisms. |
Hi @filipelautert, these logs were generated with Liquibase 4.19.0 (sorry, I forgot to include the version number). Do you want me test it again with 4.20.0? I skimmed through the changelog and I'm not sure if you are referring to #3775 that should improve the locking mechanism. |
Hello @schrieveslaach - it was #3396 , merged on 4.18.0 - time flies! So it should be fine on 4.19.0, and it means there is another point were we need to reset it. |
Environment
Liquibase Version: 4.5.0
Liquibase Integration & Version: spring-boot 2.6.2
Liquibase Extension(s) & Version: none
Database Vendor & Version: Postgres 12
Operating System Type & Version: Linux Ubuntu
Description
We have a PostgreSQL 12 server which contains a lot of schemas. Each schema is of the same structure (e.g. changelog).
On startup of the application, it needs to be ensured that the schemas are on the latest state. There may be multiple machines (!) starting up in parallel. Each machine then will have its own liquibase instance running.
During the process, it may happen that two machines try to work on the same schema (however, they will have the same changelog then - ensured by deployment&configuration) .
As of today, we observe that error messages may be raised because the first machine has already performed all updates of the changelog, whilst the second machine tries to apply them a second time.
Typical symptoms are:
Looking at
liquibase/liquibase-core/src/main/java/liquibase/sqlgenerator/core/SelectFromDatabaseChangeLogLockGenerator.java
Line 48 in 6a609ce
The code-review currently tells us that with only shared-locking the record on the table
databasechangelog
, two machines might enter the critical path atliquibase/liquibase-core/src/main/java/liquibase/lockservice/StandardLockService.java
Line 279 in 6a609ce
Steps To Reproduce
Code Review, see links above
Actual Behavior
Two parallel liquibase machines may run the same changes in the changelog on the same schema (hence failing).
Expected/Desired Behavior
Locking works as expected (parallel execution on the same schema is prohibited) and subsequent executions detect that nothing has to be done.
The text was updated successfully, but these errors were encountered: