Skip to content
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

[YugabyteDB] Improve locking mechanism during migrations #76

Merged
merged 4 commits into from
Feb 12, 2025

Conversation

ashetkar
Copy link
Contributor

@ashetkar ashetkar commented Jan 30, 2025

This plugin replaced the use if PG Advisory locks during migrations with a mechanism using SELECT ... FOR UPDATE. This PR further improves this locking mechanism as explained below.

  • Ensure only the owner of the lock unlocks it
    • There was a possibility that another thread might set the locked column to false in the YB_FLYWAY_LOCK_TABLE table even if it didn't set it to true earlier.
    • To avoid this, changed column locked of type boolean to lock_id of type bigint and checking its value while resetting it.
  • Ensure the lock is not held indefinitely
    • Added a timestamp column in the lock table
    • If this (current_time - timestamp) is more than a specified ttl value (default 5min and configurable via a system property), the lock is reset.
  • Tested the changes with existing tests in flyway-tests

@ashetkar ashetkar changed the title [YugabyteDB] Improve locking [YugabyteDB] Improve locking mechanism during migrations Feb 4, 2025
@ashetkar
Copy link
Contributor Author

cc @Barry-RG Please take look. Thanks

@WilliamL-RG WilliamL-RG merged commit 33a9004 into flyway:main Feb 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants