Skip to content

Commit 3824650

Browse files
committed
Refactor processAppendEntry()
Add recoverAppendEntry() to handle append entries during recovery. This is to separate the normal path from recovery path. Signed-off-by: Daniele Sciascia <[email protected]>
1 parent a108bdd commit 3824650

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

server/raft.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ func (s *Server) initRaftNode(accName string, cfg *RaftConfig, labels pprofLabel
514514
truncateAndErr(index - 1)
515515
break
516516
}
517-
n.processAppendEntry(ae, nil)
517+
n.recoverAppendEntry(ae)
518518
// Check how much we have queued up so far to determine if we should pause.
519519
for _, e := range ae.entries {
520520
qsz += len(e.Data)
@@ -3444,9 +3444,19 @@ func (n *raft) updateLeader(newLeader string) {
34443444
}
34453445
}
34463446

3447-
// processAppendEntry will process an appendEntry. This is called either
3448-
// during recovery or from processAppendEntries when there are new entries
3449-
// to be committed.
3447+
// recoverAppendEntry will process an appendEntry for recovery
3448+
func (n *raft) recoverAppendEntry(ae *appendEntry) {
3449+
n.Lock()
3450+
defer n.Unlock()
3451+
3452+
n.pterm = ae.term
3453+
n.pindex = ae.pindex + 1
3454+
3455+
n.processEntriesAndCommit(ae, false)
3456+
}
3457+
3458+
// processAppendEntry will process an appendEntry. This is called from
3459+
// processAppendEntries when there are new entries to be committed.
34503460
func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) {
34513461
// Make a copy of the reply subject, as ae may return
34523462
// to its pool as part of processAppendEntryLocked

server/raft_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ func TestNRGCandidateDoesntRevertTermAfterOldAE(t *testing.T) {
807807
// the term. Give it to the follower in candidate state.
808808
ae := newAppendEntry(leader.id, 6, leader.commit, leader.pterm, leader.pindex, nil)
809809
follower.switchToCandidate()
810-
follower.processAppendEntry(ae, nil)
810+
follower.processAppendEntry(ae, follower.aesub)
811811

812812
// The candidate must not have reverted back to term 6.
813813
require_NotEqual(t, follower.term, 6)

0 commit comments

Comments
 (0)