Skip to content

Commit

Permalink
sql: step the sql transaction before commit
Browse files Browse the repository at this point in the history
In cockroachdb#86153 we added logic to step the transaction before auto-commit. This was
insufficient to resolve cockroachdb#86132 because we did not step the transaction before
committing an explicit transaction. This PR addresses that by moving the step
logic to a shared code path. It also adds a test which previously failed.

Fixes cockroachdb#86132

Release justification: bug fix

Release note: None
  • Loading branch information
ajwerner committed Aug 19, 2022
1 parent 99e2941 commit bffad12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/sql/conn_executor_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,18 @@ func (ex *connExecutor) commitSQLTransactionInternal(ctx context.Context) error
ctx, sp := tracing.EnsureChildSpan(ctx, ex.server.cfg.AmbientCtx.Tracer, "commit sql txn")
defer sp.Finish()

// We need to step the transaction before committing if it has stepping
// enabled. If it doesn't have stepping enabled, then we just set the
// stepping mode back to what it was.
prevSteppingMode := ex.state.mu.txn.ConfigureStepping(ctx, kv.SteppingEnabled)
if prevSteppingMode == kv.SteppingEnabled {
if err := ex.state.mu.txn.Step(ctx); err != nil {
return err
}
} else {
ex.state.mu.txn.ConfigureStepping(ctx, prevSteppingMode)
}

if err := ex.createJobs(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -2096,10 +2108,6 @@ func (ex *connExecutor) handleAutoCommit(
if err != nil {
return ex.makeErrEvent(err, stmt)
}
if err = ex.state.mu.txn.Step(ctx); err != nil {
log.VEventf(ctx, 2, "AutoCommit. err: %v", err)
return ex.makeErrEvent(err, stmt)
}
ev, payload := ex.commitSQLTransaction(ctx, stmt, ex.commitSQLTransactionInternal)
if perr, ok := payload.(payloadWithError); ok {
err = perr.errorCause()
Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/schema
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,14 @@ CREATE SCHEMA sc
statement ok
DROP SCHEMA sc

statement ok
BEGIN;
CREATE SCHEMA sc;
COMMIT

statement ok
DROP SCHEMA sc

statement ok
SET CLUSTER SETTING server.eventlog.enabled = false

0 comments on commit bffad12

Please sign in to comment.