Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -3215,7 +3215,7 @@ func (n *raft) truncateWAL(term, index uint64) {
}
}
// Set after we know we have truncated properly.
n.term, n.pterm, n.pindex = term, term, index
n.pterm, n.pindex = term, index
}

// Reset our WAL. This is equivalent to truncating all data from the log.
Expand Down
41 changes: 41 additions & 0 deletions server/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,3 +1007,44 @@ func TestNRGWALEntryWithoutQuorumMustTruncate(t *testing.T) {
return nil
})
}

func TestNRGTermNoDecreaseAfterWALReset(t *testing.T) {
c := createJetStreamClusterExplicit(t, "R3S", 3)
defer c.shutdown()

rg := c.createRaftGroup("TEST", 3, newStateAdder)
rg.waitOnLeader()

l := rg.leader().node().(*raft)
l.Lock()
l.term = 20
l.Unlock()

esm := encodeStreamMsgAllowCompress("foo", "_INBOX.foo", nil, nil, 0, 0, true)
entries := []*Entry{newEntry(EntryNormal, esm)}
l.Lock()
ae := l.buildAppendEntry(entries)
l.Unlock()

for _, f := range rg {
if f.node().ID() != l.ID() {
fn := f.node().(*raft)
fn.processAppendEntry(ae, fn.aesub)
require_Equal(t, fn.term, 20) // Follower's term gets upped as expected.
}
}

// Lower the term, simulating the followers receiving a message from an old term/leader.
ae.term = 3
for _, f := range rg {
if f.node().ID() != l.ID() {
fn := f.node().(*raft)
fn.processAppendEntry(ae, fn.aesub)
require_Equal(t, fn.term, 20) // Follower should reject and the term stays the same.

fn.resetWAL()
fn.processAppendEntry(ae, fn.aesub)
require_Equal(t, fn.term, 20) // Follower should reject again, even after reset, term stays the same.
}
}
}