-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 driver should wait for lock #13
Conversation
For your previous comment about using a context instead, I would prefer that but the best solution would be to change the Driver interface to pass a context to lock and unlock. I'm happy to do that in another PR if you think this is a good approach. |
I like the idea of requiring context in the Driver interface but this is a breaking change which shouldn't be made on a whim. Also, I'm wary about the behavior of the underlying DB. e.g. if a DB driver function call times out while running a migration, what's that mean? |
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.
This change breaks the current behavior of Driver.Lock()
.The current behavior is that if the lock cannot be obtained, then an error should be returned.
This behavior is documented, which implies that Driver.Lock()
should not block indefinitely.
I would argue that the fact there is a LockTimeout Says to me wait this long to try to get a lock, though you could say this is more for the database to be available. But the mysql driver change merged in #8 does the same thing with waiting for the lock. The only difference is they are setting their own lock timeout instead of using the configuration variable (which is even more confusing to me). |
Thanks for bringing However, I think there's a design flaw and that lock acquisition timeouts should be managed by the DB driver since the lock behavior is DB dependent. I'd like to avoid creating any dangling locks, but the impact doesn't seem catastrophic since the odds of creating them are low. From a DRY perspective, I'd much rather have the lock timeouts be managed by This means that users should be aware that in rare cases, dangling locks may be created and other migrations for the same DB will be blocked from running until So I think your changes are fine and will merge them once tests pass. |
That all makes sense, I do think a "spring" cleaning might need to be done of the code to document odd issues like this. What you say makes perfect sense and I will be happy to help where I can in any cleanup efforts. It seems the tests are failing for Cassandra and Mysql if I'm reading it right which is odd since this change doesn't touch their code. I'll try to see whats up. |
@dhui I cant seem to get the tests to rerun. I'm not sure how my postgres driver changes would cause mysql and cassandra tests to fail. |
Are you able to reproduce the errors locally? If you find the import rewrites too annoying, you can modify the project's location in your Go workspace accordingly. |
@Teddy-Schmitz try rebasing your changes. The master branch now builds! |
11cc198
to
046d1cb
Compare
I still am getting test failures for mysql locally. But I rebased and pushed it up lets see if CI fails. |
It seems the postgres driver wasn't following convention as the Lock method will wait for the timeout before stopping the operation. But the driver was using postgres_try_advisory_lock which immediately errors if it cant acquire instead of waiting. This fixes that.