@@ -980,21 +980,22 @@ func testRaftSnapshotsToNonVoters(t *testing.T, drainReceivingNode bool) {
980980 // Manually enqueue the leaseholder replica into its store's raft snapshot
981981 // queue. We expect it to pick up on the fact that the non-voter on its range
982982 // needs a snapshot.
983- ctx , rec := tracing .ContextWithRecordingSpan (ctx , leaseholderStore .GetStoreConfig ().Tracer (), "trace-enqueue" )
983+ ctx , finish := tracing .ContextWithRecordingSpan (ctx , leaseholderStore .GetStoreConfig ().Tracer (), "trace-enqueue" )
984984 pErr , err := leaseholderStore .Enqueue (
985985 ctx ,
986986 "raftsnapshot" ,
987987 leaseholderRepl ,
988988 false , /* skipShouldQueue */
989989 false , /* async */
990990 )
991+ rec := finish ()
991992 if pErr != nil {
992993 return pErr
993994 }
994995 if err != nil {
995996 return err
996997 }
997- matched , err := regexp .MatchString ("streamed snapshot.*to.*NON_VOTER" , rec () .String ())
998+ matched , err := regexp .MatchString ("streamed snapshot.*to.*NON_VOTER" , rec .String ())
998999 if err != nil {
9991000 return err
10001001 }
@@ -1262,10 +1263,11 @@ func TestReplicateQueueSeesLearnerOrJointConfig(t *testing.T) {
12621263 processErr , err := store .Enqueue (
12631264 traceCtx , "replicate" , repl , true /* skipShouldQueue */ , false , /* async */
12641265 )
1266+ rec := finish ()
12651267 require .NoError (t , err )
12661268 require .NoError (t , processErr )
12671269 action := "next replica action: remove learner"
1268- require .NoError (t , testutils .MatchInOrder (finish () .String (), []string {action }... ))
1270+ require .NoError (t , testutils .MatchInOrder (rec .String (), []string {action }... ))
12691271 require .Equal (t , int64 (1 ), getFirstStoreMetric (t , tc .Server (0 ), `queue.replicate.removelearnerreplica` ))
12701272
12711273 testutils .SucceedsSoon (t , func () error {
@@ -1292,10 +1294,12 @@ func TestReplicateQueueSeesLearnerOrJointConfig(t *testing.T) {
12921294 processErr , err := store .Enqueue (
12931295 traceCtx , "replicate" , repl , true /* skipShouldQueue */ , false , /* async */
12941296 )
1297+ rec := finish ()
1298+
12951299 require .NoError (t , err )
12961300 require .NoError (t , processErr )
12971301 action := "next replica action: finalize conf change"
1298- require .NoError (t , testutils .MatchInOrder (finish () .String (), []string {action }... ))
1302+ require .NoError (t , testutils .MatchInOrder (rec .String (), []string {action }... ))
12991303
13001304 testutils .SucceedsSoon (t , func () error {
13011305 desc = tc .LookupRangeOrFatal (t , scratchStartKey )
@@ -1329,14 +1333,15 @@ func TestReplicaGCQueueSeesLearnerOrJointConfig(t *testing.T) {
13291333 // Run the replicaGC queue.
13301334 checkNoGC := func () roachpb.RangeDescriptor {
13311335 store , repl := getFirstStoreReplica (t , tc .Server (1 ), scratchStartKey )
1332- traceCtx , rec := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
1336+ traceCtx , finish := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
13331337 processErr , err := store .Enqueue (
13341338 traceCtx , "replicaGC" , repl , true /* skipShouldQueue */ , false , /* async */
13351339 )
1340+ rec := finish ()
13361341 require .NoError (t , err )
13371342 require .NoError (t , processErr )
13381343 const msg = `not gc'able, replica is still in range descriptor: (n2,s2):`
1339- require .Contains (t , rec () .String (), msg )
1344+ require .Contains (t , rec .String (), msg )
13401345 return tc .LookupRangeOrFatal (t , scratchStartKey )
13411346 }
13421347 desc := checkNoGC ()
@@ -1392,18 +1397,19 @@ func TestRaftSnapshotQueueSeesLearner(t *testing.T) {
13921397 // raft to figure out that the replica needs a snapshot.
13931398 store , repl := getFirstStoreReplica (t , tc .Server (0 ), scratchStartKey )
13941399 testutils .SucceedsSoon (t , func () error {
1395- traceCtx , rec := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
1400+ traceCtx , finish := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
13961401 processErr , err := store .Enqueue (
13971402 traceCtx , "raftsnapshot" , repl , true /* skipShouldQueue */ , false , /* async */
13981403 )
1404+ rec := finish ()
13991405 if err != nil {
14001406 return err
14011407 }
14021408 if processErr != nil {
14031409 return processErr
14041410 }
14051411 const msg = `skipping snapshot; replica is likely a LEARNER in the process of being added: (n2,s2):2LEARNER`
1406- formattedTrace := rec () .String ()
1412+ formattedTrace := rec .String ()
14071413 if ! strings .Contains (formattedTrace , msg ) {
14081414 return errors .Errorf (`expected "%s" in trace got:\n%s` , msg , formattedTrace )
14091415 }
@@ -1545,17 +1551,18 @@ func TestLearnerReplicateQueueRace(t *testing.T) {
15451551 queue1ErrCh := make (chan error , 1 )
15461552 go func () {
15471553 queue1ErrCh <- func () error {
1548- traceCtx , rec := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
1554+ traceCtx , finish := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
15491555 processErr , err := store .Enqueue (
15501556 traceCtx , "replicate" , repl , true /* skipShouldQueue */ , false , /* async */
15511557 )
1558+ rec := finish ()
15521559 if err != nil {
15531560 return err
15541561 }
15551562 if processErr == nil || ! strings .Contains (processErr .Error (), `descriptor changed` ) {
15561563 return errors .Wrap (processErr , `expected "descriptor changed" error got: %+v` )
15571564 }
1558- formattedTrace := rec () .String ()
1565+ formattedTrace := rec .String ()
15591566 expectedMessages := []string {
15601567 `could not promote .*?n3,s3.*? to voter, rolling back:.*?change replicas of r\d+ failed: descriptor changed` ,
15611568 `learner to roll back not found` ,
@@ -2088,13 +2095,14 @@ func TestMergeQueueSeesLearnerOrJointConfig(t *testing.T) {
20882095 })
20892096
20902097 store , repl := getFirstStoreReplica (t , tc .Server (0 ), scratchStartKey )
2091- traceCtx , rec := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
2098+ traceCtx , finish := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
20922099 processErr , err := store .Enqueue (
20932100 traceCtx , "merge" , repl , true /* skipShouldQueue */ , false , /* async */
20942101 )
2102+ rec := finish ()
20952103 require .NoError (t , err )
20962104 require .NoError (t , processErr )
2097- formattedTrace := rec () .String ()
2105+ formattedTrace := rec .String ()
20982106 expectedMessages := []string {
20992107 `removing learner replicas \[n2,s2\]` ,
21002108 `merging to produce range: /Table/Max-/Max` ,
@@ -2126,13 +2134,14 @@ func TestMergeQueueSeesLearnerOrJointConfig(t *testing.T) {
21262134 checkTransitioningOut := func () {
21272135 t .Helper ()
21282136 store , repl := getFirstStoreReplica (t , tc .Server (0 ), scratchStartKey )
2129- traceCtx , rec := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
2137+ traceCtx , finish := tracing .ContextWithRecordingSpan (ctx , store .GetStoreConfig ().Tracer (), "trace-enqueue" )
21302138 processErr , err := store .Enqueue (
21312139 traceCtx , "merge" , repl , true /* skipShouldQueue */ , false , /* async */
21322140 )
2141+ rec := finish ()
21332142 require .NoError (t , err )
21342143 require .NoError (t , processErr )
2135- formattedTrace := rec () .String ()
2144+ formattedTrace := rec .String ()
21362145 expectedMessages := []string {
21372146 `transitioning out of joint configuration` ,
21382147 `merging to produce range: /Table/Max-/Max` ,
0 commit comments