-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql/contention: add blocking statement to contention event tables #172178
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1925,3 +1925,81 @@ func TestSupportedCRDBInternalTablesNotChanged(t *testing.T) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| func TestBlockingStmtFingerprintIDInContentionEventsTable(t *testing.T) { | ||
| defer leaktest.AfterTest(t)() | ||
| defer log.Scope(t).Close(t) | ||
|
|
||
| ctx := context.Background() | ||
| srv, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{ | ||
| DefaultTestTenant: base.TestIsSpecificToStorageLayerAndNeedsASystemTenant, | ||
| }) | ||
|
Comment on lines
+1934
to
+1936
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: im not sure if this DefaultTestTenant is needed. I think you can just do |
||
| defer srv.Stopper().Stop(ctx) | ||
| s := srv.ApplicationLayer() | ||
|
|
||
| _, err := sqlDB.Exec("SET CLUSTER SETTING sql.contention.event_store.resolution_interval = '10ms'") | ||
| require.NoError(t, err) | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| key string | ||
| blockingStmtFingerprintID uint64 | ||
| expected gosql.NullString | ||
| }{ | ||
| { | ||
| name: "non-null", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: lets name these something like "blocking_stmt_fingerprint_not_exists" and "blocking_stmt_fingerprint_exists" |
||
| key: "/Animals/Cats", | ||
| blockingStmtFingerprintID: 9005, | ||
| expected: gosql.NullString{String: fmt.Sprintf("%016x", uint64(9005)), Valid: true}, | ||
| }, | ||
| { | ||
| name: "null", | ||
| key: "/Animals/Dogs", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| keyEscaped := fmt.Sprintf("\"%s\"", tc.key) | ||
| s.ExecutorConfig().(sql.ExecutorConfig).ContentionRegistry.AddContentionEvent(contentionpb.ExtendedContentionEvent{ | ||
| BlockingEvent: kvpb.ContentionEvent{ | ||
| Key: roachpb.Key(tc.key), | ||
| TxnMeta: enginepb.TxnMeta{ | ||
| Key: roachpb.Key(tc.key), | ||
| ID: uuid.MakeV4(), | ||
| }, | ||
| Duration: 1 * time.Minute, | ||
| BlockingStmtFingerprintID: tc.blockingStmtFingerprintID, | ||
| }, | ||
| BlockingTxnFingerprintID: 9001, | ||
| WaitingTxnID: uuid.MakeV4(), | ||
| WaitingTxnFingerprintID: 9002, | ||
| WaitingStmtID: clusterunique.ID{Uint128: uint128.Uint128{Lo: 9003, Hi: 1004}}, | ||
| WaitingStmtFingerprintID: 9004, | ||
| ContentionType: contentionpb.ContentionType_LOCK_WAIT, | ||
| }) | ||
|
|
||
| // Contention flush can take some time to flush the events. | ||
| testutils.SucceedsSoon(t, func() error { | ||
| row := sqlDB.QueryRow(`SELECT | ||
| encode(blocking_stmt_fingerprint_id, 'hex') | ||
| FROM crdb_internal.transaction_contention_events | ||
| WHERE contending_pretty_key = $1`, keyEscaped) | ||
|
|
||
| var actual gosql.NullString | ||
| err = row.Scan(&actual) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if actual != tc.expected { | ||
| return errors.Newf( | ||
| "unexpected blocking stmt fingerprint id: got %+v, expected %+v", | ||
| actual, | ||
| tc.expected, | ||
| ) | ||
| } | ||
| return nil | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can pull this out into a variable to make the if block a little more readable