-
Notifications
You must be signed in to change notification settings - Fork 286
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
Consolidate crdb tx retry and reset #472
Conversation
samkim
commented
Mar 9, 2022
•
edited
Loading
edited
- Remove crdb tx savepoint usage
- Update remaining crdb tx to use datatstore execute
eab0307
to
2e67d2b
Compare
internal/datastore/crdb/namespace.go
Outdated
var err error | ||
var config *core.NamespaceDefinition | ||
var timestamp time.Time | ||
err = cds.execute(ctx, cds.conn, pgx.TxOptions{AccessMode: pgx.ReadOnly}, func(tx pgx.Tx) error { |
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.
So this wraps the reset handling for ReadNamespace now too?
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.
Updated ReadNamespace
internal/datastore/crdb/tx.go
Outdated
@@ -78,10 +51,9 @@ func executeWithMaxRetries(max int) executeTxRetryFunc { | |||
|
|||
// executeWithResets executes transactionFn and resets the tx when ambiguous crdb errors are encountered. | |||
func executeWithResets(ctx context.Context, conn conn, txOptions pgx.TxOptions, fn transactionFn, maxRetries int) (err error) { | |||
var retries, resets int | |||
var retries int |
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.
Shouldn't this be resets now?
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.
Kept it as retries because the config is named retries so essentially making the resetting an internal implementation detail. I don't feel strongly about it so can change the var name and metric name to use reset.
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.
Whichever, they just should match
9eb9d4f
to
d70383a
Compare
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.
A couple of small things but looks good otherwise
internal/datastore/crdb/tx.go
Outdated
} | ||
|
||
// resetExecution attempts to rollback the given tx, begins a new tx with a new connection, and creates a savepoint. | ||
// resetExecution attempts to rollback the given tx and begins a new tx with a new connection. | ||
func resetExecution(ctx context.Context, conn conn, tx pgx.Tx, txOptions pgx.TxOptions) (newTx pgx.Tx, err error) { | ||
log.Info().Msg("attempting to initialize new tx") |
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 know this here before, but now that it's getting called on revision and namespace reads, shouldn't this be a higher log level than Info
?
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