-
Notifications
You must be signed in to change notification settings - Fork 81
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: use a closure to wrap transactions #469
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.
Just some cosmetic suggestions -- makes sense when I walk through the commits as recommended, and looks good - making this straightforward. And I didn't think we were always rolling back on failures, in some cases we were leaving transactions dangling. Which I guess might work sometimes....
Right, that's the whole point of this PR - we had cases in which dangling transactions blocked new ones. This should really prevent that from happening! |
…ent and sqlcache.informer.factory.DBClient Signed-off-by: Silvio Moioli <[email protected]>
…ent and sqlcache.db.DBClient Signed-off-by: Silvio Moioli <[email protected]>
…ent and sqlcache.informer.DBClient Signed-off-by: Silvio Moioli <[email protected]>
Use the exported interface exclusively in other packages. Signed-off-by: Silvio Moioli <[email protected]>
Signed-off-by: Silvio Moioli <[email protected]>
Signed-off-by: Silvio Moioli <[email protected]>
… exported interface in other packages) Signed-off-by: Silvio Moioli <[email protected]>
Signed-off-by: Silvio Moioli <[email protected]>
This introduces the db.Client.WithTransaction func, which is used for all transactional work in Steve. This function makes sure either Commit or Rollback is called after Beginning a transaction, thereby avoiding cases when a forgotten open transaction can block all other operations. This commit also heavily refactors transaction.Client and associated code in order to make it as minimal and as close to the wrapped sql.Tx functions as possble, in order to reduce cognitive load when working with this part of the codebase. Signed-off-by: Silvio Moioli <[email protected]>
Note that some tests did not make sense any more after the refactoring, therefore those were dropped. Signed-off-by: Silvio Moioli <[email protected]>
Signed-off-by: Silvio Moioli <[email protected]>
Signed-off-by: Silvio Moioli <[email protected]>
Signed-off-by: Silvio Moioli <[email protected]>
Signed-off-by: Silvio Moioli <[email protected]>
Signed-off-by: Silvio Moioli <[email protected]>
31c03f8
to
349ab35
Compare
Rebased on top of current |
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.
Looks great, I like how you hid the Commit()
/ Rollback()
functionality to ensure no one is calling it.
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
This introduces the a
WithTransaction
function, which is then used for all transactional work in Steve.Example:
Because
WithTransaction
takes care of allBegin
s,Commit
s andRollback
s, it eliminates the problem where forgotten open transactions can block all other operations (with long stalling andSQLITE_BUSY
errors).This also:
DBClient
interfaces in one onlydb.Client
interface with one unexported non-test implementation. I found this much easier to followsql.Tx
andsql.Stmt
functions as possible, in order to reduce cognitive load when working with this part of the codebase.gitignore
Partly addresses rancher/rancher#48384
Best reviewed commit-by-commit - the vast majority of the changes are actually mechanical. The core of this change is "just" commit 8d7272e
Credits to @tomleb for suggesting the approach.