Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
133461: rac2: fix TestRangeController testingRCRange.mu lock ordering r=sumeerbhola a=kvoli

This was failing `TestRangeController` under `--deadlock`.

Ensure consistent lock ordering between `testingRCRange.mu` and `ReplicaMutexAsserter.RaftMu`.

Resolves: #133426
Release note: None

133463: kvserver: extend election timeout ticks in TestControlFlowRaftMembers… r=sumeerbhola a=kvoli

…hipV2

The test is susceptible to observing timing issues, such as stream disconnects under CPU exhaustion. This is problematic because the test asserts on the full history of metrics, in that some are counters.

Attempt to paper over these by extending `RaftElectionTimeoutTicks`.

Fixes: #133272
Release note: None

Co-authored-by: Austen McClernon <[email protected]>
  • Loading branch information
craig[bot] and kvoli committed Oct 25, 2024
3 parents 7ee6cd4 + 4530e7b + 04703e7 commit e86550a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pkg/kv/kvserver/flow_control_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3078,6 +3078,11 @@ func TestFlowControlRaftMembershipV2(t *testing.T) {
ReplicationMode: base.ReplicationManual,
ServerArgs: base.TestServerArgs{
Settings: settings,
RaftConfig: base.RaftConfig{
// Suppress timeout-based elections. This test doesn't want to deal
// with leadership changing hands unless intentional.
RaftElectionTimeoutTicks: 1000000,
},
Knobs: base.TestingKnobs{
Store: &kvserver.StoreTestingKnobs{
FlowControlTestingKnobs: &kvflowcontrol.TestingKnobs{
Expand Down
19 changes: 14 additions & 5 deletions pkg/kv/kvserver/kvflowcontrol/rac2/range_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (s *testingRCState) init(t *testing.T, ctx context.Context) {
func sortReplicas(r *testingRCRange) []roachpb.ReplicaDescriptor {
r.mu.Lock()
defer r.mu.Unlock()
return sortReplicasLocked(r)
}

func sortReplicasLocked(r *testingRCRange) []roachpb.ReplicaDescriptor {
return sortReplicaSet(r.mu.r.replicaSet)
}

Expand Down Expand Up @@ -504,7 +508,9 @@ func (r *testingRCRange) startWaitForEval(name string, pri admissionpb.WorkPrior
func (r *testingRCRange) admit(ctx context.Context, storeID roachpb.StoreID, av AdmittedVector) {
r.mu.Lock()
defer r.mu.Unlock()
for _, replica := range r.mu.r.replicaSet {

for _, replDesc := range sortReplicasLocked(r) {
replica := r.mu.r.replicaSet[replDesc.ReplicaID]
if replica.desc.StoreID == storeID {
for _, v := range av.Admitted {
// Ensure that Match doesn't lag behind the highest index in the
Expand Down Expand Up @@ -918,11 +924,14 @@ func (t *testingProbeToCloseTimerScheduler) ScheduleSendStreamCloseRaftMuLocked(
}
timer.MarkRead()
func() {
rc := t.state.ranges[rangeID].rc
rc.opts.ReplicaMutexAsserter.RaftMu.Lock()
defer rc.opts.ReplicaMutexAsserter.RaftMu.Unlock()
r := t.state.ranges[rangeID]
event := r.makeRaftEventWithReplicasState()

r.rc.opts.ReplicaMutexAsserter.RaftMu.Lock()
defer r.rc.opts.ReplicaMutexAsserter.RaftMu.Unlock()

require.NoError(t.state.t,
rc.HandleRaftEventRaftMuLocked(ctx, t.state.ranges[rangeID].makeRaftEventWithReplicasState()))
r.rc.HandleRaftEventRaftMuLocked(ctx, event))
}()
}()
}
Expand Down

0 comments on commit e86550a

Please sign in to comment.