Skip to content

Commit 1b27ef9

Browse files
craig[bot]tbg
andcommitted
Merge #142972
142972: kvserver: deflake TestPromoteNonVoterInAddVoter r=tbg a=tbg It was checking the rangelog for LEARNER additions, however it could accidentally pick up changes from starting the cluster that had no relation to the recent zone config change the test wanted to learn the effects of. Clear the rangelog before changing the zone config to avoid this. Also, make the explanation of the test correct - it really threw me off because it suggested voter and non-voter counts that really did not match up at all with the reality of the test. Fixes #142956. Epic: none Release note: none Co-authored-by: Tobias Grieger <[email protected]>
2 parents c29b195 + e4c9c84 commit 1b27ef9

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

pkg/kv/kvserver/replicate_queue_test.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,17 +2126,17 @@ func iterateOverAllStores(
21262126
//
21272127
// ZONE survival configuration:
21282128
// Region 1: 3 of [n1 (voter) n2 (voter) n3 (voter)]
2129-
// Region 2: 1 of [n4 (non-voter) n5 (non-voter)]
2130-
// Region 3: 1 of [n6 (non-voter) n7 (non-voter)]
2129+
// Region 2: 1 of [n4 or n5 (non-voter)]
2130+
// Region 3: 1 of [n6 or n7 (non-voter)]
21312131
// to REGION survival configuration:
2132-
// Region 1: 2 of [n1 (voter) n2 (voter) n3 (voter)]
2133-
// Region 2: 2 of [n4 (voter) n5 (voter)]
2134-
// Region 3: 1 of [n6 (voter) n7 (voter)]
2132+
// Region 1: 2 of [two of n1-n3 (voter)]
2133+
// Region 2: 2 of [n4 (voter) and n5 (voter)]
2134+
// Region 3: 1 of [n6 or n7 (voter)]
21352135
//
21362136
// Here we have 7 stores: 3 in Region 1, 2 in Region 2, and 2 in Region 3.
21372137
//
2138-
// The expected behaviour is that there should not be any add voter events in
2139-
// the range log where the added replica type is a LEARNER.
2138+
// What the test wants to see is that when we switch from ZONE to REGION,
2139+
// the non-voters in Region 2 and Region 3 are promoted to voters.
21402140
func TestPromoteNonVoterInAddVoter(t *testing.T) {
21412141
defer leaktest.AfterTest(t)()
21422142
scope := log.Scope(t)
@@ -2196,18 +2196,18 @@ func TestPromoteNonVoterInAddVoter(t *testing.T) {
21962196
if err := forceScanOnAllReplicationQueues(tc); err != nil {
21972197
return err
21982198
}
2199-
rangeCount := -1
2200-
allEqualRangeCount := true
2201-
iterateOverAllStores(t, tc, func(s *kvserver.Store) error {
2202-
if rangeCount == -1 {
2203-
rangeCount = s.ReplicaCount()
2204-
} else if rangeCount != s.ReplicaCount() {
2205-
allEqualRangeCount = false
2206-
}
2207-
return nil
2208-
})
2209-
if !allEqualRangeCount {
2210-
return errors.New("Range counts are not all equal")
2199+
s, err := sqlutils.RowsToDataDrivenOutput(sqlutils.MakeSQLRunner(tc.Conns[0]).Query(t, `
2200+
SELECT * FROM (
2201+
SELECT
2202+
range_id,
2203+
array_length(voting_replicas, 1) AS vc,
2204+
COALESCE(array_length(non_voting_replicas, 1), 0) AS nvc
2205+
FROM crdb_internal.ranges_no_leases
2206+
) WHERE vc != 7 OR nvc > 0 ORDER BY range_id ASC LIMIT 1
2207+
`))
2208+
require.NoError(t, err)
2209+
if len(s) > 0 {
2210+
return errors.Errorf("still upreplicating:\n%s", s)
22112211
}
22122212
return nil
22132213
})
@@ -2216,6 +2216,7 @@ func TestPromoteNonVoterInAddVoter(t *testing.T) {
22162216
_, err := db.Exec("CREATE TABLE t (i INT PRIMARY KEY, s STRING)")
22172217
require.NoError(t, err)
22182218

2219+
log.Infof(ctx, "test setting ZONE survival configuration")
22192220
// ZONE survival configuration.
22202221
setConstraintFn("TABLE t", 5, 3,
22212222
", constraints = '{\"+region=2\": 1, \"+region=3\": 1}', voter_constraints = '{\"+region=1\": 3}'")
@@ -2260,6 +2261,11 @@ func TestPromoteNonVoterInAddVoter(t *testing.T) {
22602261
})
22612262

22622263
// REGION survival configuration.
2264+
log.Infof(ctx, "test setting REGION survival configuration")
2265+
// Clear the rangelog so that we can rest assured to only pick up events
2266+
// resulting from the zone config change.
2267+
_, err = tc.Conns[0].ExecContext(ctx, `DELETE FROM system.rangelog WHERE TRUE`)
2268+
require.NoError(t, err)
22632269
setConstraintFn("TABLE t", 5, 5,
22642270
", constraints = '{}', voter_constraints = '{\"+region=1\": 2, \"+region=2\": 2, \"+region=3\": 1}'")
22652271
require.NoError(t, err)

0 commit comments

Comments
 (0)