Skip to content

Commit efae0d2

Browse files
committed
refactor Etcdserver.snapshot to extract compaction into a separate method
Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
1 parent c86c93c commit efae0d2

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

server/etcdserver/server.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) {
12071207
s.forceSnapshot = false
12081208

12091209
s.snapshot(ep.appliedi, ep.confState)
1210+
s.compactRaftLog(ep.appliedi)
12101211
ep.snapi = ep.appliedi
12111212
}
12121213

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

2175+
}
2176+
2177+
func (s *EtcdServer) compactRaftLog(snapi uint64) {
2178+
lg := s.Logger()
2179+
21742180
// When sending a snapshot, etcd will pause compaction.
21752181
// After receives a snapshot, the slow follower needs to get all the entries right after
21762182
// the snapshot sent to catch up. If we do not pause compaction, the log entries right after
@@ -2187,7 +2193,7 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
21872193
compacti = snapi - s.Cfg.SnapshotCatchUpEntries
21882194
}
21892195

2190-
err = s.r.raftStorage.Compact(compacti)
2196+
err := s.r.raftStorage.Compact(compacti)
21912197
if err != nil {
21922198
// the compaction was done asynchronously with the progress of raft.
21932199
// raft log might already been compact.

0 commit comments

Comments
 (0)