-
Notifications
You must be signed in to change notification settings - Fork 379
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
When a SQL error occurs, clean up all prepared statement. #2936
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,20 @@ func expandPlaceholderSQL(sql string, num int, first, rest string) string { | |
return strings.Replace(sql, placeholderSQL, parameters, 1) | ||
} | ||
|
||
// clearAllStmt clean up all sql.Stmt in cache | ||
func (m *mySQLTreeStorage) cleanAllStmt() { | ||
m.statementMutex.Lock() | ||
defer m.statementMutex.Unlock() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some kind of logging for this would be really useful. This should be a rare event in an otherwise healthy system:
Actually, for bonus points I think it's worth incrementing a counter whenever we clear statements, which should appear on monitoring dashboards and allow correlation with potential impacts such as increased latency or errors. Take a look at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
for _, ns := range m.statements { | ||
for _, s := range ns { | ||
s.Close() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check the error returned from Close. Maybe not much more to do other than log the failure, but I don't like letting errors like this simply disappear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
} | ||
} | ||
|
||
m.statements = make(map[string]map[int]*sql.Stmt) | ||
} | ||
|
||
// getStmt creates and caches sql.Stmt structs based on the passed in statement | ||
// and number of bound arguments. | ||
// TODO(al,martin): consider pulling this all out as a separate unit for reuse | ||
|
@@ -200,6 +214,7 @@ func (t *treeTX) getSubtrees(ctx context.Context, treeRevision int64, ids [][]by | |
|
||
rows, err := stx.QueryContext(ctx, args...) | ||
if err != nil { | ||
t.ts.cleanAllStmt() | ||
klog.Warningf("Failed to get merkle subtrees: %s", err) | ||
return nil, err | ||
} | ||
|
@@ -296,6 +311,7 @@ func (t *treeTX) storeSubtrees(ctx context.Context, subtrees []*storagepb.Subtre | |
|
||
r, err := stx.ExecContext(ctx, args...) | ||
if err != nil { | ||
t.ts.cleanAllStmt() | ||
klog.Warningf("Failed to set merkle subtrees: %s", err) | ||
return err | ||
} | ||
|
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.
Would
clearStmtCache
be a clearer name for this func?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.
fixed