Skip to content

Commit

Permalink
raft: test TestCannotCommitWithoutNewTermEntry w/ & wo/ store liveness
Browse files Browse the repository at this point in the history
This commit changes TestCannotCommitWithoutNewTermEntry to allow testing
it when store liveness is both enabled and disabled.

References: #132241

Release note: None
  • Loading branch information
iskettaneh committed Oct 28, 2024
1 parent b1a805e commit 00e00b1
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions pkg/raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,19 @@ func TestSingleNodeCommit(t *testing.T) {
// when leader changes, no new proposal comes in and ChangeTerm proposal is
// filtered.
func TestCannotCommitWithoutNewTermEntry(t *testing.T) {
tt := newNetworkWithConfig(fortificationDisabledConfig, nil, nil, nil, nil, nil)
testutils.RunTrueAndFalse(t, "store-liveness-enabled",
func(t *testing.T, storeLivenessEnabled bool) {
testCannotCommitWithoutNewTermEntry(t, storeLivenessEnabled)
})
}

func testCannotCommitWithoutNewTermEntry(t *testing.T, storeLivenessEnabled bool) {
var cfg func(c *Config) = nil
if !storeLivenessEnabled {
cfg = fortificationDisabledConfig
}

tt := newNetworkWithConfig(cfg, nil, nil, nil, nil, nil)
tt.send(pb.Message{From: 1, To: 1, Type: pb.MsgHup})

// 0 cannot reach 2,3,4
Expand All @@ -695,7 +707,17 @@ func TestCannotCommitWithoutNewTermEntry(t *testing.T) {
// avoid committing ChangeTerm proposal
tt.ignore(pb.MsgApp)

// elect 2 as the new leader with term 2
// Elect 2 as the new leader with term 2.
if storeLivenessEnabled {
// We need to withdraw support of the current leader. This will prevent it
// from attempting to refortify the peers.
tt.livenessFabric.WithdrawSupportForPeerFromAllPeers(1)

// Bumping all epochs will make all followers stop supporting the current
// fortified leader.
tt.livenessFabric.BumpAllSupportEpochs()
}

tt.send(pb.Message{From: 2, To: 2, Type: pb.MsgHup})

// no log entries from previous term should be committed
Expand Down Expand Up @@ -4131,7 +4153,8 @@ type network struct {

// msgHook is called for each message sent. It may inspect the
// message and return true to send it or false to drop it.
msgHook func(pb.Message) bool
msgHook func(pb.Message) bool
livenessFabric *raftstoreliveness.LivenessFabric
}

// newNetwork initializes a network from peers.
Expand All @@ -4150,13 +4173,15 @@ func newNetworkWithConfig(configFunc func(*Config), peers ...stateMachine) *netw

npeers := make(map[pb.PeerID]stateMachine, size)
nstorage := make(map[pb.PeerID]*MemoryStorage, size)

livenessFabric := raftstoreliveness.NewLivenessFabric()
for j, p := range peers {
id := peerAddrs[j]
livenessFabric.AddPeer(id)
switch v := p.(type) {
case nil:
nstorage[id] = newTestMemoryStorage(withPeers(peerAddrs...))
cfg := newTestConfig(id, 10, 1, nstorage[id])
cfg := newTestConfig(id, 10, 1, nstorage[id],
withStoreLiveness(livenessFabric.GetStoreLiveness(id)))
if configFunc != nil {
configFunc(cfg)
}
Expand Down Expand Up @@ -4192,10 +4217,11 @@ func newNetworkWithConfig(configFunc func(*Config), peers ...stateMachine) *netw
}
}
return &network{
peers: npeers,
storage: nstorage,
dropm: make(map[connem]float64),
ignorem: make(map[pb.MessageType]bool),
peers: npeers,
storage: nstorage,
dropm: make(map[connem]float64),
ignorem: make(map[pb.MessageType]bool),
livenessFabric: livenessFabric,
}
}

Expand Down

0 comments on commit 00e00b1

Please sign in to comment.