Skip to content

Commit

Permalink
kvserver: reject proposals in TestRaftPreVote
Browse files Browse the repository at this point in the history
This test has occasionally been seen to flake with a spurious command
appended to the Raft log, despite write requests being blocked. This
patch instead blocks Raft proposals, which should presumably prevent
this flake.

Epic: none
Release note: None
  • Loading branch information
erikgrinaker committed Sep 19, 2023
1 parent 7e884bd commit 4d22a67
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions pkg/kv/kvserver/client_raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6127,16 +6127,14 @@ func TestRaftPreVote(t *testing.T) {

// We don't want any writes to the range, to avoid the follower from
// falling behind on the log and failing prevotes only because of that.
// We install a request filter which rejects writes to the range during
// the partition (typically txn record cleanup via GC requests).
//
// We reject requests, not proposals, because we don't want to mess too
// much with the Raft machinery and mask other issues.
// We install a proposal filter which rejects proposals to the range
// during the partition (typically txn record cleanup via GC requests,
// but also e.g. lease extensions).
var partitioned atomic.Bool
var rangeID roachpb.RangeID
reqFilter := func(ctx context.Context, ba *kvpb.BatchRequest) *kvpb.Error {
if partitioned.Load() && ba.IsWrite() && ba.RangeID == rangeID {
t.Logf("r%d write rejected: %s", rangeID, ba)
propFilter := func(args kvserverbase.ProposalFilterArgs) *kvpb.Error {
if partitioned.Load() && args.Req.RangeID == rangeID {
t.Logf("r%d proposal rejected: %s", rangeID, args.Req)
return kvpb.NewError(errors.New("rejected"))
}
return nil
Expand All @@ -6160,7 +6158,7 @@ func TestRaftPreVote(t *testing.T) {
Knobs: base.TestingKnobs{
Store: &kvserver.StoreTestingKnobs{
DisableQuiescence: !quiesce,
TestingRequestFilter: reqFilter,
TestingProposalFilter: propFilter,
DisableAutomaticLeaseRenewal: true,
},
},
Expand Down

0 comments on commit 4d22a67

Please sign in to comment.