Skip to content

Commit c3e2217

Browse files
craig[bot]kyle-a-wong
andcommitted
154197: log: remove global log functions r=kyle-a-wong a=kyle-a-wong Removes global functions from the log package. These functions were wrappers around log.Dev.<func> and were previously deprecated. Also replaces and remaining uses with log.Dev.<func> Epic: CRDB-53410 Resolves: CRDB-53943 Release note: None 154494: sql: allow transaction diagnostics to work with non-fingerprinted sta… r=kyle-a-wong a=kyle-a-wong …tements Certain statements can be executed within a transaction, but are not recorded as part of the transaction fingerprint. In these cases, the transaction diagnostics recorded should record these statements and continue with with the diagnostics collection instead of resetting the instrumentation helper. As part of this fix, the transaction diagnostics collector now has more states it could be in, including NotStarted, InProgress, ReadyToFinalize, and Aborted. These states make it easier to allow or dissalllow certain actions, such as continuing diagnostics, adding statement bundles, finalizing a diagnostics collection, and starting a diagnostics collection. Epic: CRDB-53541 Release note: None Co-authored-by: Kyle Wong <[email protected]>
3 parents 7635297 + 8eafa02 + f7bdf08 commit c3e2217

20 files changed

+368
-736
lines changed

pkg/sql/conn_executor.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,12 +3499,6 @@ func isCommit(stmt tree.Statement) bool {
34993499
return ok
35003500
}
35013501

3502-
// isRollback returns true if stmt is a "ROLLBACK" statement.
3503-
func isRollback(stmt tree.Statement) bool {
3504-
_, ok := stmt.(*tree.RollbackTransaction)
3505-
return ok
3506-
}
3507-
35083502
var retryableMinTimestampBoundUnsatisfiableError = errors.Newf(
35093503
"retryable MinTimestampBoundUnsatisfiableError",
35103504
)

pkg/sql/instrumentation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ func (ih *instrumentationHelper) Finish(
736736
payloadErr, retErr, &p.extendedEvalCtx.Settings.SV, ih.inFlightTraceCollector,
737737
)
738738

739-
if !txnHelper.DiagnosticsInProgress() {
739+
if !txnHelper.diagnosticsCollector.InProgress() {
740740
// Include all non-critical errors as warnings. Note that these
741741
// error strings might contain PII, but the warnings are only shown
742742
// to the current user and aren't included into the bundle.
@@ -749,7 +749,7 @@ func (ih *instrumentationHelper) Finish(
749749
}
750750
}
751751

752-
if txnHelper.DiagnosticsInProgress() {
752+
if txnHelper.diagnosticsCollector.InProgress() {
753753
// If we're collecting a transaction bundle, add the statement to the
754754
// current txn diagnostic bundle. These will be persisted at the end
755755
// of the transaction if the transaction matches the request.

pkg/sql/stmtdiagnostics/statement_diagnostics_test.go

Lines changed: 104 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,110 @@ LIMIT 1`)
845845
}
846846

847847
registry := tc.Server(0).ExecutorConfig().(sql.ExecutorConfig).TxnDiagnosticsRecorder
848+
t.Run("diagnostics", func(t *testing.T) {
849+
for _, testCase := range []struct {
850+
name string
851+
statements []string
852+
}{
853+
{
854+
name: "regular request",
855+
statements: txnStatements,
856+
},
857+
{
858+
name: "with savepoint cockroach_restart",
859+
statements: []string{
860+
"SAVEPOINT cockroach_restart",
861+
"SELECT 'aaaaaa', 'bbbbbb'",
862+
"SELECT 'aaaaaa', 'bbbbbb', 'ccccc' UNION select 'ddddd', 'eeeee', 'fffff'",
863+
"RELEASE SAVEPOINT cockroach_restart",
864+
},
865+
},
866+
{
867+
name: "with savepoint",
868+
statements: []string{
869+
"SAVEPOINT my_savepoint",
870+
"SELECT 'aaaaaa', 'bbbbbb'",
871+
"SELECT 'aaaaaa', 'bbbbbb', 'ccccc' UNION select 'ddddd', 'eeeee', 'fffff'",
872+
"RELEASE SAVEPOINT my_savepoint",
873+
},
874+
},
875+
{
876+
name: "with savepoint rollback",
877+
statements: []string{
878+
"SAVEPOINT my_savepoint",
879+
"SELECT 'aaaaaa', 'bbbbbb'",
880+
"SELECT 'aaaaaa', 'bbbbbb', 'ccccc' UNION select 'ddddd', 'eeeee', 'fffff'",
881+
"ROLLBACK TO SAVEPOINT my_savepoint",
882+
},
883+
},
884+
{
885+
name: "with cockroach_restart and regular savepoint",
886+
statements: []string{
887+
"SAVEPOINT cockroach_restart",
888+
"SAVEPOINT my_savepoint",
889+
"SELECT 'aaaaaa', 'bbbbbb'",
890+
"RELEASE SAVEPOINT my_savepoint",
891+
"SELECT 'aaaaaa', 'bbbbbb', 'ccccc' UNION select 'ddddd', 'eeeee', 'fffff'",
892+
"RELEASE SAVEPOINT cockroach_restart",
893+
},
894+
},
895+
{
896+
name: "with cockroach_restart and regular savepoint and rollback",
897+
statements: []string{
898+
"SAVEPOINT cockroach_restart",
899+
"SELECT 'aaaaaa', 'bbbbbb'",
900+
"SAVEPOINT my_savepoint",
901+
"ROLLBACK TO SAVEPOINT my_savepoint",
902+
"SELECT 'aaaaaa', 'bbbbbb', 'ccccc' UNION select 'ddddd', 'eeeee', 'fffff'",
903+
"SHOW SAVEPOINT STATUS",
904+
"RELEASE SAVEPOINT cockroach_restart",
905+
},
906+
},
907+
{
908+
name: "with show commit timestamp",
909+
statements: []string{
910+
"SELECT 'aaaaaa', 'bbbbbb'",
911+
"SELECT 'aaaaaa', 'bbbbbb', 'ccccc' UNION select 'ddddd', 'eeeee', 'fffff'",
912+
"SHOW COMMIT TIMESTAMP",
913+
},
914+
},
915+
} {
916+
t.Run(testCase.name, func(t *testing.T) {
917+
// Insert a request for the transaction fingerprint
918+
reqId, err := registry.InsertTxnRequestInternal(
919+
ctx,
920+
txnFingerprintId,
921+
statementFingerprintIds,
922+
"testuser",
923+
0,
924+
0,
925+
0,
926+
false,
927+
)
928+
require.NoError(t, err)
848929

849-
t.Run("txn diagnostic request", func(t *testing.T) {
850-
// Insert a request for the transaction fingerprint
930+
// Ensure that the request shows up in the system.transaction_diagnostics_requests table
931+
var count int
932+
sqlConn.QueryRow(t, "SELECT count(*) FROM system.transaction_diagnostics_requests WHERE completed=false and id=$1", reqId).Scan(&count)
933+
require.Equal(t, 1, count)
934+
935+
// Execute the transaction until the request is marked as complete.
936+
// We use a connection to a different server than the diagnostics request
937+
// was made on to ensure that the request is properly gossiped.
938+
runTxnUntilDiagnosticsCollected(t, tc, sqlutils.MakeSQLRunner(tc.ServerConn(1)), testCase.statements, reqId)
939+
})
940+
}
941+
})
942+
943+
t.Run("diagnostics with prepared statement", func(t *testing.T) {
944+
// Since you can't create the same named prepared statement, we have this
945+
// in a separate test that is guaranteed to complete on the first try
946+
// by using the same node the request was made on.
947+
statements := []string{
948+
"PREPARE my_statement as SELECT 'aaaaaa', 'bbbbbb'",
949+
"EXECUTE my_statement",
950+
"SELECT 'aaaaaa', 'bbbbbb', 'ccccc' UNION select 'ddddd', 'eeeee', 'fffff'",
951+
}
851952
reqId, err := registry.InsertTxnRequestInternal(
852953
ctx,
853954
txnFingerprintId,
@@ -859,19 +960,8 @@ LIMIT 1`)
859960
false,
860961
)
861962
require.NoError(t, err)
862-
863-
// Ensure that the request shows up in the system.transaction_diagnostics_requests table
864-
var count int
865-
sqlConn.QueryRow(t, "SELECT count(*) FROM system.transaction_diagnostics_requests WHERE completed=false and id=$1", reqId).Scan(&count)
866-
require.Equal(t, 1, count)
867-
868-
// Execute the transaction until the request is marked as complete.
869-
// We use a connection to a different server than the diagnostics request
870-
// was made on to ensure that the request is properly gossiped.
871-
runTxnUntilDiagnosticsCollected(t, tc, sqlutils.MakeSQLRunner(tc.ServerConn(1)), txnStatements, reqId)
872-
963+
runTxnUntilDiagnosticsCollected(t, tc, sqlConn, statements, reqId)
873964
})
874-
875965
t.Run("txn diagnostic with statement diagnostic request", func(t *testing.T) {
876966

877967
stmtReqId, err := registry.StmtRegistry.InsertRequestInternal(

0 commit comments

Comments
 (0)