-
Notifications
You must be signed in to change notification settings - Fork 57
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(waku_archive): only allow a single instance to execute migrations #2736
Conversation
This PR may contain changes to database schema of one of the drivers. If you are introducing any changes to the schema, make sure the upgrade from the latest release to this change passes without any errors/issues. Please make sure the label |
You can find the image built from this PR at
Built from 5d20b65 |
You can find the image built from this PR at
Built from 5d20b65 |
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.
LGTM! Thanks for it! 💯
let lockedRes = await s.getStr( | ||
fmt""" | ||
SELECT pg_try_advisory_lock({lockId}) | ||
""" | ||
) | ||
if lockedRes.isErr(): | ||
return err("error acquiring a lock: " & $lockedRes.error) | ||
|
||
if lockedRes.value == "f": | ||
return err("another waku instance is currently executing a migration") |
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.
I think it could be a little bit more concise with the valueOr
approach ( notice that we also use isOkOr
for Result[void, ...]
)
let lockedRes = await s.getStr( | |
fmt""" | |
SELECT pg_try_advisory_lock({lockId}) | |
""" | |
) | |
if lockedRes.isErr(): | |
return err("error acquiring a lock: " & $lockedRes.error) | |
if lockedRes.value == "f": | |
return err("another waku instance is currently executing a migration") | |
let locked = (await s.getStr( | |
fmt""" | |
SELECT pg_try_advisory_lock({lockId}) | |
""" | |
)).valueOr: | |
return err("error acquiring a lock: " & $error) | |
if locked == "f": | |
return err("another waku instance is currently executing a migration") |
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.
Thanks so much! 🤩
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.
Nice, thanks.
Description
Uses an advisory lock which acts as a mutex for the postgresql migrations.
This lock will be acquired before any migration is executed. If it's not possible to acquire, the instance will fail to start with these errors:
Once the migration process is done, the lock will be released.
This is required for scenarios in which a postgresql database is used by more than one node (like in status).
cc: @jakubgs
Issue
closes #2726