@@ -69,6 +69,7 @@ import (
69
69
"github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb"
70
70
"github.com/cockroachdb/cockroach/pkg/util/uuid"
71
71
"github.com/cockroachdb/errors"
72
+ "github.com/cockroachdb/logtags"
72
73
"github.com/cockroachdb/redact"
73
74
"github.com/stretchr/testify/require"
74
75
"google.golang.org/grpc"
@@ -5289,6 +5290,7 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5289
5290
ctx := context .Background ()
5290
5291
5291
5292
testutils .RunValues (t , "lease-type" , roachpb .TestingAllLeaseTypes (), func (t * testing.T , leaseType roachpb.LeaseType ) {
5293
+ ctx = logtags .AddTag (ctx , "gotest" , t .Name ())
5292
5294
noopProposalFilter := kvserverbase .ReplicaProposalFilter (func (args kvserverbase.ProposalFilterArgs ) * kvpb.Error {
5293
5295
return nil
5294
5296
})
@@ -5299,6 +5301,7 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5299
5301
}
5300
5302
5301
5303
increment := func (t * testing.T , db * kv.DB , key roachpb.Key , by int64 ) {
5304
+ t .Helper ()
5302
5305
b := & kv.Batch {}
5303
5306
b .AddRawRequest (incrementArgs (key , by ))
5304
5307
require .NoError (t , db .Run (ctx , b ))
@@ -5312,6 +5315,7 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5312
5315
getHardState := func (
5313
5316
t * testing.T , store * kvserver.Store , rangeID roachpb.RangeID ,
5314
5317
) raftpb.HardState {
5318
+ t .Helper ()
5315
5319
hs , err := stateloader .Make (rangeID ).LoadHardState (ctx , store .TODOEngine ())
5316
5320
require .NoError (t , err )
5317
5321
return hs
@@ -5340,6 +5344,7 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5340
5344
var err error
5341
5345
* partRange , err = basePartition .extend (tc , split .RightDesc .RangeID , replDesc .ReplicaID ,
5342
5346
0 /* partitionedNode */ , true /* activated */ , unreliableRaftHandlerFuncs {})
5347
+ log .Infof (ctx , "partition installed before proposing split: %s" , * partRange )
5343
5348
require .NoError (t , err )
5344
5349
proposalFilter .Store (noopProposalFilter )
5345
5350
})
@@ -5432,6 +5437,7 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5432
5437
// Make sure everybody knows about that transfer.
5433
5438
increment (t , db , keyA , 1 )
5434
5439
tc .WaitForValues (t , keyA , []int64 {6 , 6 , 6 })
5440
+ log .Infof (ctx , "activating LHS partition: %s" , lhsPartition )
5435
5441
lhsPartition .activate ()
5436
5442
5437
5443
increment (t , db , keyA , 1 )
@@ -5467,13 +5473,15 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5467
5473
5468
5474
// Remove and re-add the RHS to create a new uninitialized replica at
5469
5475
// a higher replica ID. This will lead to a tombstone being written.
5470
- tc .RemoveVotersOrFatal (t , keyB , tc .Target (0 ))
5476
+ target := tc .Target (0 )
5477
+ log .Infof (ctx , "removing voter: %v" , target )
5478
+ tc .RemoveVotersOrFatal (t , keyB , target )
5471
5479
// Unsuccessful because the RHS will not accept the learner snapshot
5472
5480
// and will be rolled back. Nevertheless it will have learned that it
5473
5481
// has been removed at the old replica ID.
5474
5482
_ , err = tc .Servers [0 ].DB ().AdminChangeReplicas (
5475
5483
ctx , keyB , tc .LookupRangeOrFatal (t , keyB ),
5476
- kvpb .MakeReplicationChanges (roachpb .ADD_VOTER , tc . Target ( 0 ) ),
5484
+ kvpb .MakeReplicationChanges (roachpb .ADD_VOTER , target ),
5477
5485
)
5478
5486
require .True (t , kvserver .IsRetriableReplicationChangeError (err ), err )
5479
5487
@@ -5483,12 +5491,14 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5483
5491
// it will find out about its new replica ID and write a tombstone for the
5484
5492
// old one.
5485
5493
waitForTombstone (t , tc .GetFirstStoreFromServer (t , 0 ).StateEngine (), rhsID )
5494
+ log .Infof (ctx , "deactivating LHS partition: %s" , lhsPartition )
5486
5495
lhsPartition .deactivate ()
5487
5496
tc .WaitForValues (t , keyA , []int64 {8 , 8 , 8 })
5488
5497
hs := getHardState (t , tc .GetFirstStoreFromServer (t , 0 ), rhsID )
5489
5498
require .Equal (t , uint64 (0 ), hs .Commit )
5499
+ log .Infof (ctx , "adding voter: %v" , target )
5490
5500
testutils .SucceedsSoon (t , func () error {
5491
- _ , err := tc .AddVoters (keyB , tc . Target ( 0 ) )
5501
+ _ , err := tc .AddVoters (keyB , target )
5492
5502
return err
5493
5503
})
5494
5504
tc .WaitForValues (t , keyB , []int64 {6 , 6 , 6 })
@@ -5519,13 +5529,15 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5519
5529
5520
5530
// Remove and re-add the RHS to create a new uninitialized replica at
5521
5531
// a higher replica ID. This will lead to a tombstone being written.
5522
- tc .RemoveVotersOrFatal (t , keyB , tc .Target (0 ))
5532
+ target := tc .Target (0 )
5533
+ log .Infof (ctx , "removing voter: %v" , target )
5534
+ tc .RemoveVotersOrFatal (t , keyB , target )
5523
5535
// Unsuccessfuly because the RHS will not accept the learner snapshot
5524
5536
// and will be rolled back. Nevertheless it will have learned that it
5525
5537
// has been removed at the old replica ID.
5526
5538
_ , err = tc .Servers [0 ].DB ().AdminChangeReplicas (
5527
5539
ctx , keyB , tc .LookupRangeOrFatal (t , keyB ),
5528
- kvpb .MakeReplicationChanges (roachpb .ADD_VOTER , tc . Target ( 0 ) ),
5540
+ kvpb .MakeReplicationChanges (roachpb .ADD_VOTER , target ),
5529
5541
)
5530
5542
require .True (t , kvserver .IsRetriableReplicationChangeError (err ), err )
5531
5543
@@ -5549,15 +5561,19 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5549
5561
}
5550
5562
5551
5563
// Restart store 0 so that it forgets about the newer replicaID.
5564
+ log .Infof (ctx , "stopping server 0" )
5552
5565
tc .StopServer (0 )
5566
+ log .Infof (ctx , "deactivating LHS partition: %s" , lhsPartition )
5553
5567
lhsPartition .deactivate ()
5568
+ log .Infof (ctx , "starting server 0" )
5554
5569
require .NoError (t , tc .RestartServer (0 ))
5555
5570
5556
5571
tc .WaitForValues (t , keyA , []int64 {8 , 8 , 8 })
5557
5572
hs := getHardState (t , tc .GetFirstStoreFromServer (t , 0 ), rhsID )
5558
5573
require .Equal (t , uint64 (0 ), hs .Commit )
5574
+ log .Infof (ctx , "adding voter: %v" , target )
5559
5575
testutils .SucceedsSoon (t , func () error {
5560
- _ , err := tc .AddVoters (keyB , tc . Target ( 0 ) )
5576
+ _ , err := tc .AddVoters (keyB , target )
5561
5577
return err
5562
5578
})
5563
5579
tc .WaitForValues (t , keyB , []int64 {curB , curB , curB })
@@ -5592,35 +5608,41 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5592
5608
5593
5609
// Remove and re-add the RHS to create a new uninitialized replica at
5594
5610
// a higher replica ID. This will lead to a tombstone being written.
5595
- tc .RemoveVotersOrFatal (t , keyB , tc .Target (0 ))
5611
+ target := tc .Target (0 )
5612
+ log .Infof (ctx , "removing voter: %v" , target )
5613
+ tc .RemoveVotersOrFatal (t , keyB , target )
5596
5614
// Unsuccessful because the RHS will not accept the learner snapshot and
5597
5615
// will be rolled back. Nevertheless it will have learned that it has been
5598
5616
// removed at the old replica ID. We don't use tc.AddVoters because that
5599
5617
// will retry until it runs out of time, since we're creating a
5600
5618
// retriable-looking situation here that will persist.
5601
5619
_ , err = tc .Servers [0 ].DB ().AdminChangeReplicas (
5602
5620
ctx , keyB , tc .LookupRangeOrFatal (t , keyB ),
5603
- kvpb .MakeReplicationChanges (roachpb .ADD_VOTER , tc . Target ( 0 ) ),
5621
+ kvpb .MakeReplicationChanges (roachpb .ADD_VOTER , target ),
5604
5622
)
5605
5623
require .True (t , kvserver .IsRetriableReplicationChangeError (err ), err )
5606
5624
// Ensure that the replica exists with the higher replica ID.
5607
5625
repl , err := tc .GetFirstStoreFromServer (t , 0 ).GetReplica (rhsInfo .Desc .RangeID )
5608
5626
require .NoError (t , err )
5609
5627
require .Equal (t , repl .ReplicaID (), rhsInfo .Desc .NextReplicaID )
5610
5628
rhsPartition .addReplica (rhsInfo .Desc .NextReplicaID )
5629
+ log .Infof (ctx , "added %d to RHS partition %s" , rhsInfo .Desc .NextReplicaID , rhsPartition )
5611
5630
// Ensure that there's no tombstone.
5612
5631
// The RHS on store 0 never should have heard about its original ID.
5613
5632
ensureNoTombstone (t , tc .GetFirstStoreFromServer (t , 0 ), rhsID )
5633
+ log .Infof (ctx , "deactivating LHS partition: %s" , lhsPartition )
5614
5634
lhsPartition .deactivate ()
5635
+ log .Infof (ctx , "deactivating RHS partition: %s" , rhsPartition )
5615
5636
rhsPartition .deactivate ()
5616
5637
tc .WaitForValues (t , keyA , []int64 {8 , 8 , 8 })
5617
5638
hs := getHardState (t , tc .GetFirstStoreFromServer (t , 0 ), rhsID )
5618
5639
require .Equal (t , uint64 (0 ), hs .Commit )
5619
5640
// Now succeed in adding the RHS. Use SucceedsSoon because in rare cases
5620
5641
// the learner snapshot can fail due to a race with a raft snapshot from
5621
5642
// a raft leader on a different node.
5643
+ log .Infof (ctx , "adding voter: %v" , target )
5622
5644
testutils .SucceedsSoon (t , func () error {
5623
- _ , err := tc .AddVoters (keyB , tc . Target ( 0 ) )
5645
+ _ , err := tc .AddVoters (keyB , target )
5624
5646
return err
5625
5647
})
5626
5648
tc .WaitForValues (t , keyB , []int64 {6 , 6 , 6 })
@@ -5666,7 +5688,9 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5666
5688
5667
5689
// Remove and re-add the RHS to create a new uninitialized replica at
5668
5690
// a higher replica ID. This will lead to a tombstone being written.
5669
- tc .RemoveVotersOrFatal (t , keyB , tc .Target (0 ))
5691
+ target := tc .Target (0 )
5692
+ log .Infof (ctx , "removing voter: %v" , target )
5693
+ tc .RemoveVotersOrFatal (t , keyB , target )
5670
5694
// Unsuccessfuly because the RHS will not accept the learner snapshot
5671
5695
// and will be rolled back. Nevertheless it will have learned that it
5672
5696
// has been removed at the old replica ID.
@@ -5685,6 +5709,7 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5685
5709
// Now, before we deactivate the LHS partition, partition the newer replica
5686
5710
// on the RHS too.
5687
5711
rhsPartition .addReplica (rhsInfo .Desc .NextReplicaID )
5712
+ log .Infof (ctx , "added %d to RHS partition: %s" , rhsInfo .Desc .NextReplicaID , rhsPartition )
5688
5713
5689
5714
// We do all of this incrementing to ensure that nobody will ever
5690
5715
// succeed in sending a message the new RHS replica after we restart
@@ -5698,8 +5723,11 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5698
5723
tc .WaitForValues (t , keyB , []int64 {0 , curB , curB })
5699
5724
}
5700
5725
5726
+ log .Infof (ctx , "stopping server 0" )
5701
5727
tc .StopServer (0 )
5728
+ log .Infof (ctx , "deactivate LHS partition: %s" , lhsPartition )
5702
5729
lhsPartition .deactivate ()
5730
+ log .Infof (ctx , "restarting server 0" )
5703
5731
require .NoError (t , tc .RestartServer (0 ))
5704
5732
5705
5733
tc .WaitForValues (t , keyA , []int64 {8 , 8 , 8 })
@@ -5714,7 +5742,9 @@ func TestProcessSplitAfterRightHandSideHasBeenRemoved(t *testing.T) {
5714
5742
}
5715
5743
return nil
5716
5744
})
5745
+ log .Infof (ctx , "deactivate RHS partition: %s" , rhsPartition )
5717
5746
rhsPartition .deactivate ()
5747
+ log .Infof (ctx , "adding voter: %v" , target )
5718
5748
testutils .SucceedsSoon (t , func () error {
5719
5749
_ , err := tc .AddVoters (keyB , tc .Target (0 ))
5720
5750
return err
0 commit comments