From 216288341449f1e36ac7254fe9497a59d7061c8d Mon Sep 17 00:00:00 2001 From: Max Englander Date: Thu, 25 Jan 2024 13:14:11 -0500 Subject: [PATCH] vtgate: increment vtgate_warnings counter for non atomic commits (#15010) Signed-off-by: Max Englander --- go/vt/vtgate/tx_conn.go | 1 + go/vt/vtgate/tx_conn_test.go | 9 +++++++++ go/vt/vtgate/vtgate.go | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/go/vt/vtgate/tx_conn.go b/go/vt/vtgate/tx_conn.go index 246140b3711..f21686d01d8 100644 --- a/go/vt/vtgate/tx_conn.go +++ b/go/vt/vtgate/tx_conn.go @@ -158,6 +158,7 @@ func (txc *TxConn) commitNormal(ctx context.Context, session *SafeSession) error Code: uint32(sqlerror.ERNonAtomicCommit), Message: fmt.Sprintf("multi-db commit failed after committing to %d shards: %s", i, strings.Join(sNames, ", ")), }) + warnings.Add("NonAtomicCommit", 1) } _ = txc.Release(ctx, session) return err diff --git a/go/vt/vtgate/tx_conn_test.go b/go/vt/vtgate/tx_conn_test.go index 6ce863603f8..4d77ea16c92 100644 --- a/go/vt/vtgate/tx_conn_test.go +++ b/go/vt/vtgate/tx_conn_test.go @@ -72,6 +72,7 @@ func TestTxConnCommitFailure(t *testing.T) { sc, sbcs, rssm, rssa := newTestTxConnEnvNShards(t, ctx, "TestTxConn", 3) sc.txConn.mode = vtgatepb.TransactionMode_MULTI + nonAtomicCommitCount := warnings.Counts()["NonAtomicCommit"] // Sequence the executes to ensure commit order @@ -163,6 +164,8 @@ func TestTxConnCommitFailure(t *testing.T) { } utils.MustMatch(t, &wantSession, session.Session, "Session") assert.EqualValues(t, 1, sbcs[0].CommitCount.Load(), "sbc0.CommitCount") + + require.Equal(t, nonAtomicCommitCount+1, warnings.Counts()["NonAtomicCommit"]) } func TestTxConnCommitFailureAfterNonAtomicCommitMaxShards(t *testing.T) { @@ -170,6 +173,7 @@ func TestTxConnCommitFailureAfterNonAtomicCommitMaxShards(t *testing.T) { sc, sbcs, rssm, _ := newTestTxConnEnvNShards(t, ctx, "TestTxConn", 18) sc.txConn.mode = vtgatepb.TransactionMode_MULTI + nonAtomicCommitCount := warnings.Counts()["NonAtomicCommit"] // Sequence the executes to ensure commit order @@ -214,6 +218,8 @@ func TestTxConnCommitFailureAfterNonAtomicCommitMaxShards(t *testing.T) { for i := 0; i < 17; i++ { assert.EqualValues(t, 1, sbcs[i].CommitCount.Load(), fmt.Sprintf("sbc%d.CommitCount", i)) } + + require.Equal(t, nonAtomicCommitCount+1, warnings.Counts()["NonAtomicCommit"]) } func TestTxConnCommitFailureBeforeNonAtomicCommitMaxShards(t *testing.T) { @@ -221,6 +227,7 @@ func TestTxConnCommitFailureBeforeNonAtomicCommitMaxShards(t *testing.T) { sc, sbcs, rssm, _ := newTestTxConnEnvNShards(t, ctx, "TestTxConn", 17) sc.txConn.mode = vtgatepb.TransactionMode_MULTI + nonAtomicCommitCount := warnings.Counts()["NonAtomicCommit"] // Sequence the executes to ensure commit order @@ -265,6 +272,8 @@ func TestTxConnCommitFailureBeforeNonAtomicCommitMaxShards(t *testing.T) { for i := 0; i < 16; i++ { assert.EqualValues(t, 1, sbcs[i].CommitCount.Load(), fmt.Sprintf("sbc%d.CommitCount", i)) } + + require.Equal(t, nonAtomicCommitCount+1, warnings.Counts()["NonAtomicCommit"]) } func TestTxConnCommitSuccess(t *testing.T) { diff --git a/go/vt/vtgate/vtgate.go b/go/vt/vtgate/vtgate.go index 0a28220a796..c8c0df217af 100644 --- a/go/vt/vtgate/vtgate.go +++ b/go/vt/vtgate/vtgate.go @@ -187,7 +187,7 @@ var ( // Error counters should be global so they can be set from anywhere errorCounts = stats.NewCountersWithMultiLabels("VtgateApiErrorCounts", "Vtgate API error counts per error type", []string{"Operation", "Keyspace", "DbType", "Code"}) - warnings = stats.NewCountersWithSingleLabel("VtGateWarnings", "Vtgate warnings", "type", "IgnoredSet", "ResultsExceeded", "WarnPayloadSizeExceeded") + warnings = stats.NewCountersWithSingleLabel("VtGateWarnings", "Vtgate warnings", "type", "IgnoredSet", "ResultsExceeded", "WarnPayloadSizeExceeded", "NonAtomicCommit") vstreamSkewDelayCount = stats.NewCounter("VStreamEventsDelayedBySkewAlignment", "Number of events that had to wait because the skew across shards was too high")