@@ -845,9 +845,110 @@ LIMIT 1`)
845
845
}
846
846
847
847
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 )
848
929
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
+ }
851
952
reqId , err := registry .InsertTxnRequestInternal (
852
953
ctx ,
853
954
txnFingerprintId ,
@@ -859,19 +960,8 @@ LIMIT 1`)
859
960
false ,
860
961
)
861
962
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 )
873
964
})
874
-
875
965
t .Run ("txn diagnostic with statement diagnostic request" , func (t * testing.T ) {
876
966
877
967
stmtReqId , err := registry .StmtRegistry .InsertRequestInternal (
0 commit comments