-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
[SQL Lab] Add commit to resolve query table lock #8262
Conversation
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. But want to get confirm from @mistercrunch or @villebro.
Hmm. Tracing back it seems there is already a |
@villebro There is a commit prior to calling This happened about 100-200 times a day, sometimes more, and was in line with our general usage stats (which makes sense, people would see it more often if they were running queries more often). I was able to get logs showing that the specific row in the query table was locked for updating, and all instances of this error went away after deploying this change. |
Ah, right you are, my bad. Weird that this hasn't caused more problems over the years. To keep the code clean, perhaps we should remove the prior commit, I'm not sure it's needed after this. Also it might make sense to disable autoflush and do a single manual flush before execution to avoid unnenessary traffic. (thinking out loud, not sure this would work/help performance). |
I think we'd still want the previous commit in case an exception is raised in the execute function (like not allowing dml statements) but we still want to ensure the query is updated first |
As for the autoflush, I'm not sure why we didn't disable it before, perhaps @mistercrunch can provide some insight |
I reread the code carefully and brushed up on docs regarding flushing and committing, and I agree, this makes sense, i.e. committing away the inexpensive mutating (=locking) parts of the transaction prior to the expensive non-mutating select. While disabling autoflush mid-flight appears to be ok (https://github.com/sqlalchemy/sqlalchemy/wiki/DisableAutoflush), I wouldn't expect this to have a big impact on performance, so probably better to leave that out for now. |
CATEGORY
Choose one
SUMMARY
We've been trying to track down database row locking issues when trying to call the
stop_query
endpoint for several months now. After digging into this file, it seems like the session that we create to run sql queries has autoflush enabled. Therefore, we're locking the db on these rows until committing the changes to the query. We don't commit this until after the query finishes, so the row gets locked and we can't set the query to stopped. By committing before running the query, this seems to have resolved the issue for us.TEST PLAN
CI + Deployed in our production environment
ADDITIONAL INFORMATION
REVIEWERS
@graceguo-supercat @michellethomas @john-bodley @mistercrunch