Skip to content
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

Merged
merged 1 commit into from
Mar 28, 2022
Merged

Conversation

samkim
Copy link
Member

@samkim samkim commented Mar 9, 2022

  • Remove crdb tx savepoint usage
  • Update remaining crdb tx to use datatstore execute

@github-actions github-actions bot added area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Mar 9, 2022
@samkim samkim changed the title Make unexpected EOF a resetable tx error Consolidate crdb tx retry and reset Mar 18, 2022
@samkim samkim marked this pull request as draft March 18, 2022 07:55
@samkim samkim force-pushed the tx-retry-err branch 2 times, most recently from eab0307 to 2e67d2b Compare March 21, 2022 15:08
@samkim samkim marked this pull request as ready for review March 21, 2022 15:10
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 {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated ReadNamespace

@@ -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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Contributor

@ecordell ecordell left a 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

}

// 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")
Copy link
Contributor

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?

internal/datastore/crdb/tx.go Show resolved Hide resolved
Copy link
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@samkim samkim merged commit b445a27 into authzed:main Mar 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants