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

release-20.2: sql,metrics: do not increment ROLLBACK counter if in CommitWait #60250

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pkg/server/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,44 @@ func TestStatusVars(t *testing.T) {
}
}

// TestStatusVarsTxnMetrics verifies that the metrics from the /_status/vars
// endpoint for txns and the special cockroach_restart savepoint are correct.
func TestStatusVarsTxnMetrics(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer db.Close()
defer s.Stopper().Stop(context.Background())

if _, err := db.Exec("BEGIN;" +
"SAVEPOINT cockroach_restart;" +
"SELECT 1;" +
"RELEASE SAVEPOINT cockroach_restart;" +
"ROLLBACK;"); err != nil {
t.Fatal(err)
}

body, err := getText(s, s.AdminURL()+statusPrefix+"vars")
if err != nil {
t.Fatal(err)
}
if !bytes.Contains(body, []byte("sql_txn_begin_count 1")) {
t.Errorf("expected `sql_txn_begin_count 1`, got: %s", body)
}
if !bytes.Contains(body, []byte("sql_restart_savepoint_count 1")) {
t.Errorf("expected `sql_restart_savepoint_count 1`, got: %s", body)
}
if !bytes.Contains(body, []byte("sql_restart_savepoint_release_count 1")) {
t.Errorf("expected `sql_restart_savepoint_release_count 1`, got: %s", body)
}
if !bytes.Contains(body, []byte("sql_txn_commit_count 1")) {
t.Errorf("expected `sql_txn_commit_count 1`, got: %s", body)
}
if !bytes.Contains(body, []byte("sql_txn_rollback_count 0")) {
t.Errorf("expected `sql_txn_rollback_count 0`, got: %s", body)
}
}

func TestSpanStatsResponse(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
Expand Down
8 changes: 7 additions & 1 deletion pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,13 @@ func (sc *StatementCounters) incrementCount(ex *connExecutor, stmt tree.Statemen
case *tree.CommitTransaction:
sc.TxnCommitCount.Inc()
case *tree.RollbackTransaction:
sc.TxnRollbackCount.Inc()
// The CommitWait state means that the transaction has already committed
// after a specially handled `RELEASE SAVEPOINT cockroach_restart` command.
if ex.getTransactionState() == CommitWaitStateStr {
sc.TxnCommitCount.Inc()
} else {
sc.TxnRollbackCount.Inc()
}
case *tree.Savepoint:
if ex.isCommitOnReleaseSavepoint(t.Name) {
sc.RestartSavepointCount.Inc()
Expand Down