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

sql: v21.2.5: SET TRANSACTION AS OF SYSTEM TIME should have a nice error if reads were already performed #77265

Closed
cockroach-teamcity opened this issue Mar 2, 2022 · 2 comments · Fixed by #79090
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sentry Originated from an in-the-wild panic report. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@cockroach-teamcity
Copy link
Member

cockroach-teamcity commented Mar 2, 2022

This issue was autofiled by Sentry. It represents a crash or reported error on a live cluster with telemetry enabled.

Sentry link: https://sentry.io/organizations/cockroach-labs/issues/3059755899/?referrer=webhooks_plugin

Panic message:

txn_coord_sender.go:1047: cannot set fixed timestamp, txn "sql txn" meta={id=8ee478ca pri=0.00459305 epo=0 ts=1646203224.865911984,0 min=1646203224.865911984,0 seq=0} lock=false stat=PENDING rts=1646203224.865911984,0 wto=false gul=1646203224.865911984,0 already performed reads
--
*errutil.leafError: cannot set fixed timestamp, txn "sql txn" meta={id=8ee478ca pri=0.00459305 epo=0 ts=1646203224.865911984,0 min=1646203224.865911984,0 seq=0} lock=false stat=PENDING rts=1646203224.865911984,0 wto=false gul=1646203224.865911984,0 already performed reads (1)
txn_coord_sender.go:1047: *withstack.withStack (top exception)
*assert.withAssertionFailure
*contexttags.withContext: n1 (2)
(check the extra data payloads)

Stacktrace (expand for inline code snippets):

if !tc.interceptorAlloc.txnSpanRefresher.refreshFootprint.empty() {
return errors.WithContextTags(errors.AssertionFailedf(
"cannot set fixed timestamp, txn %s already performed reads", tc.mu.txn), ctx)
in pkg/kv/kvclient/kvcoord.(*TxnCoordSender).SetFixedTimestamp

cockroach/pkg/kv/txn.go

Lines 1390 to 1392 in 5afb632

defer txn.mu.Unlock()
return txn.mu.sender.SetFixedTimestamp(ctx, ts)
}
in pkg/kv.(*Txn).SetFixedTimestamp
defer ts.mu.Unlock()
if err := ts.mu.txn.SetFixedTimestamp(ctx, historicalTimestamp); err != nil {
return err
in pkg/sql.(*txnState).setHistoricalTimestamp
if !asOfTs.IsEmpty() {
if err := ex.state.setHistoricalTimestamp(ex.Ctx(), asOfTs); err != nil {
return err
in pkg/sql.(*connExecutor).setTransactionModes
if err := p.extendedEvalCtx.TxnModesSetter.setTransactionModes(n.Modes, asOfTs); err != nil {
return nil, err
in pkg/sql.(*planner).SetTransaction

cockroach/pkg/sql/opaque.go

Lines 191 to 193 in 5afb632

case *tree.SetTransaction:
return p.SetTransaction(ctx, n)
case *tree.SetSessionAuthorizationDefault:
in pkg/sql.planOpaque
var err error
plan, err = planOpaque(ctx, p, stmt)
if err != nil {
in pkg/sql.buildOpaque
}
obj, err := info.buildFn(b.ctx, b.semaCtx, b.evalCtx, stmt)
if err != nil {
in pkg/sql/opt/optbuilder.(*Builder).tryBuildOpaque
// See if we have an opaque handler registered for this statement type.
if outScope := b.tryBuildOpaque(stmt, inScope); outScope != nil {
// The opaque handler may resolve objects; we don't care about caching
in pkg/sql/opt/optbuilder.(*Builder).buildStmt
b.ctes = nil
outScope = b.buildStmt(stmt, desiredTypes, inScope)
// Build With operators for any CTEs hoisted to the top level.
in pkg/sql/opt/optbuilder.(*Builder).buildStmtAtRoot
// and physical properties.
outScope := b.buildStmtAtRoot(b.stmt, nil /* desiredTypes */)
in pkg/sql/opt/optbuilder.(*Builder).Build
bld := optbuilder.New(ctx, &p.semaCtx, p.EvalContext(), &opc.catalog, f, opc.p.stmt.AST)
if err := bld.Build(); err != nil {
return nil, err
in pkg/sql.(*optPlanningCtx).buildExecMemo
execMemo, err := opc.buildExecMemo(ctx)
if err != nil {
in pkg/sql.(*planner).makeOptimizerPlan
func (ex *connExecutor) makeExecPlan(ctx context.Context, planner *planner) error {
if err := planner.makeOptimizerPlan(ctx); err != nil {
log.VEventf(ctx, 1, "optimizer plan failed: %v", err)
in pkg/sql.(*connExecutor).makeExecPlan
// between here and there needs to happen even if there's an error.
err := ex.makeExecPlan(ctx, planner)
// We'll be closing the plan manually below after execution; this
in pkg/sql.(*connExecutor).dispatchToExecutionEngine
if err := ex.dispatchToExecutionEngine(ctx, p, res); err != nil {
stmtThresholdSpan.Finish()
in pkg/sql.(*connExecutor).execStmtInOpenState
} else {
ev, payload, err = ex.execStmtInOpenState(ctx, parserStmt, prepared, pinfo, res)
}
in pkg/sql.(*connExecutor).execStmt
}
ev, payload, err = ex.execStmt(ctx, portal.Stmt.Statement, portal.Stmt, pinfo, stmtRes)
// Portal suspension is supported via a "side" state machine
in pkg/sql.(*connExecutor).execPortal
res = stmtRes
ev, payload, err = ex.execPortal(ctx, portal, portalName, stmtRes, pinfo)
return err
in pkg/sql.(*connExecutor).execCmd.func2
return err
}()
// Note: we write to ex.statsCollector.phaseTimes, instead of ex.phaseTimes,
in pkg/sql.(*connExecutor).execCmd
var err error
if err = ex.execCmd(ex.Ctx()); err != nil {
if errors.IsAny(err, io.EOF, errDrainingComplete) {
in pkg/sql.(*connExecutor).run
}()
return h.ex.run(ctx, s.pool, reserved, cancel)
}
in pkg/sql.(*Server).ServeConn
reservedOwned = false // We're about to pass ownership away.
retErr = sqlServer.ServeConn(ctx, connHandler, reserved, cancelConn)
}()
in pkg/sql/pgwire.(*conn).processCommandsAsync.func1
/usr/local/go/src/runtime/asm_amd64.s#L1370-L1372 in runtime.goexit

pkg/kv/kvclient/kvcoord/txn_coord_sender.go in pkg/kv/kvclient/kvcoord.(*TxnCoordSender).SetFixedTimestamp at line 1047
pkg/kv/txn.go in pkg/kv.(*Txn).SetFixedTimestamp at line 1391
pkg/sql/txn_state.go in pkg/sql.(*txnState).setHistoricalTimestamp at line 272
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).setTransactionModes at line 2333
pkg/sql/set_transaction.go in pkg/sql.(*planner).SetTransaction at line 37
pkg/sql/opaque.go in pkg/sql.planOpaque at line 192
pkg/sql/opaque.go in pkg/sql.buildOpaque at line 61
pkg/sql/opt/optbuilder/opaque.go in pkg/sql/opt/optbuilder.(*Builder).tryBuildOpaque at line 69
pkg/sql/opt/optbuilder/builder.go in pkg/sql/opt/optbuilder.(*Builder).buildStmt at line 374
pkg/sql/opt/optbuilder/builder.go in pkg/sql/opt/optbuilder.(*Builder).buildStmtAtRoot at line 241
pkg/sql/opt/optbuilder/builder.go in pkg/sql/opt/optbuilder.(*Builder).Build at line 215
pkg/sql/plan_opt.go in pkg/sql.(*optPlanningCtx).buildExecMemo at line 521
pkg/sql/plan_opt.go in pkg/sql.(*planner).makeOptimizerPlan at line 194
pkg/sql/conn_executor_exec.go in pkg/sql.(*connExecutor).makeExecPlan at line 1260
pkg/sql/conn_executor_exec.go in pkg/sql.(*connExecutor).dispatchToExecutionEngine at line 972
pkg/sql/conn_executor_exec.go in pkg/sql.(*connExecutor).execStmtInOpenState at line 709
pkg/sql/conn_executor_exec.go in pkg/sql.(*connExecutor).execStmt at line 129
pkg/sql/conn_executor_exec.go in pkg/sql.(*connExecutor).execPortal at line 216
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).execCmd.func2 at line 1773
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).execCmd at line 1775
pkg/sql/conn_executor.go in pkg/sql.(*connExecutor).run at line 1629
pkg/sql/conn_executor.go in pkg/sql.(*Server).ServeConn at line 668
pkg/sql/pgwire/conn.go in pkg/sql/pgwire.(*conn).processCommandsAsync.func1 at line 648
/usr/local/go/src/runtime/asm_amd64.s in runtime.goexit at line 1371
Tag Value
Cockroach Release v21.2.5
Cockroach SHA: 5afb632
Platform linux amd64
Distribution CCL
Environment development
Command start-single-node
Go Version ``
# of CPUs
# of Goroutines

Jira issue: CRDB-13565

@cockroach-teamcity cockroach-teamcity added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sentry Originated from an in-the-wild panic report. labels Mar 2, 2022
@blathers-crl blathers-crl bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label Mar 4, 2022
@jordanlewis jordanlewis changed the title sentry: txn_coord_sender.go:1047: cannot set fixed timestamp, txn "sql txn" meta={id=8ee478ca pri=0.00459305 epo=0 ts=1646203224.865911984,0 min=1646203224.865911984,0 seq=0} lock=false stat=PENDING rts=1646203224.865911984,0 wto=false gul=1646203224.865911984,0 already performed reads -- *errutil.leafError: cannot set fixed timestamp, txn "sql txn" meta={id=8ee478ca pri=0.00459305 epo=0 ts=1646203224.865911984,0 min=1646203224.865911984,0 seq=0} lock=false stat=PENDING rts=1646203224.865911984,0 wto=false gul=1646203224.865911984,0 already performed reads (1) txn_coord_sender.go:1047: *withstack.withStack (top exception) *assert.withAssertionFailure *contexttags.withContext: n1 (2) (check the extra data payloads) sentry: setHistoricalTimestamp from optBuilder after txn has already performed reads? Mar 4, 2022
@jordanlewis
Copy link
Member

Tagging @cockroachdb/sql-experience because I'm thinking that it's unexpected that a txn has been able to perform reads before setting a historical timestamp.

@rafiss rafiss changed the title sentry: setHistoricalTimestamp from optBuilder after txn has already performed reads? sql: v21.2.5: setHistoricalTimestamp from optBuilder after txn has already performed reads? Mar 7, 2022
@rafiss
Copy link
Collaborator

rafiss commented Mar 7, 2022

I think this is a case of an unhandled error case that definitely should be handled. Here's a repro:

root@:26257/defaultdb> begin;
BEGIN

root@:26257/defaultdb  OPEN> select * from a;
  a
-----
  1
(1 row)


root@:26257/defaultdb  OPEN> set transaction as of system time '-1s';
ERROR: internal error: cannot set fixed timestamp, txn "sql txn" meta={id=2e2c6e5b pri=0.00246419 epo=0 ts=1646672419.172919000,0 min=1646672419.172919000,0 seq=0} lock=false stat=PENDING rts=1646672419.172919000,0 wto=false gul=1646672419.672919000,0 already performed reads
SQLSTATE: XX000
DETAIL: stack trace:
/go/src/github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_coord_sender.go:1047: SetFixedTimestamp()
/go/src/github.com/cockroachdb/cockroach/pkg/kv/txn.go:1391: SetFixedTimestamp()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/txn_state.go:272: setHistoricalTimestamp()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:2333: setTransactionModes()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/set_transaction.go:37: SetTransaction()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/opaque.go:192: planOpaque()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/opaque.go:61: buildOpaque()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/opaque.go:69: tryBuildOpaque()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:374: buildStmt()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:241: buildStmtAtRoot()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:215: Build()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:521: buildExecMemo()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/plan_opt.go:194: makeOptimizerPlan()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:1260: makeExecPlan()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:972: dispatchToExecutionEngine()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:709: execStmtInOpenState()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:129: execStmt()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1705: func1()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1707: execCmd()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1629: run()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:668: ServeConn()
/go/src/github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:648: func1()
/usr/local/go/src/runtime/asm_amd64.s:1371: goexit()

HINT: You have encountered an unexpected error.

Please check the public issue tracker to check whether this problem is
already tracked. If you cannot find it there, please report the error
with details by creating a new issue.

If you would rather not post publicly, please contact us directly
using the support form.

We appreciate your feedback.

@rafiss rafiss changed the title sql: v21.2.5: setHistoricalTimestamp from optBuilder after txn has already performed reads? sql: v21.2.5: SET TRANSACTION AS OF SYSTEM TIME should have a nice error if reads were already performed Mar 7, 2022
@e-mbrown e-mbrown self-assigned this Mar 29, 2022
@craig craig bot closed this as completed in fd26d19 Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-sentry Originated from an in-the-wild panic report. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants