Skip to content

Commit

Permalink
refactor Etcdserver.snapshot to extract compaction into a separate me…
Browse files Browse the repository at this point in the history
…thod

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Sep 27, 2024
1 parent c86c93c commit efae0d2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) {
s.forceSnapshot = false

s.snapshot(ep.appliedi, ep.confState)
s.compactRaftLog(ep.appliedi)
ep.snapi = ep.appliedi
}

Expand Down Expand Up @@ -2171,6 +2172,11 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
zap.Uint64("snapshot-index", snap.Metadata.Index),
)

}

func (s *EtcdServer) compactRaftLog(snapi uint64) {
lg := s.Logger()

// When sending a snapshot, etcd will pause compaction.
// After receives a snapshot, the slow follower needs to get all the entries right after
// the snapshot sent to catch up. If we do not pause compaction, the log entries right after
Expand All @@ -2187,7 +2193,7 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
compacti = snapi - s.Cfg.SnapshotCatchUpEntries
}

err = s.r.raftStorage.Compact(compacti)
err := s.r.raftStorage.Compact(compacti)
if err != nil {
// the compaction was done asynchronously with the progress of raft.
// raft log might already been compact.
Expand Down

0 comments on commit efae0d2

Please sign in to comment.