Skip to content

Commit 414f75b

Browse files
committed
Cleanup triggerSnapshot function and rename it to snapshotIfNeededAndCompactRaftLog
Signed-off-by: Marek Siarkowicz <[email protected]>
1 parent 8eadac8 commit 414f75b

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

server/etcdserver/server.go

+12-15
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ func (s *EtcdServer) applyAll(ep *etcdProgress, apply *toApply) {
981981
// storage, since the raft routine might be slower than toApply routine.
982982
<-apply.notifyc
983983

984-
s.triggerSnapshot(ep)
984+
s.snapshotIfNeededAndCompactRaftLog(ep)
985985
select {
986986
// snapshot requested via send()
987987
case m := <-s.r.msgSnapC:
@@ -1194,21 +1194,10 @@ func (s *EtcdServer) ForceSnapshot() {
11941194
s.forceDiskSnapshot = true
11951195
}
11961196

1197-
func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) {
1197+
func (s *EtcdServer) snapshotIfNeededAndCompactRaftLog(ep *etcdProgress) {
11981198
if !s.shouldSnapshot(ep) {
11991199
return
12001200
}
1201-
lg := s.Logger()
1202-
lg.Info(
1203-
"triggering snapshot",
1204-
zap.String("local-member-id", s.MemberID().String()),
1205-
zap.Uint64("local-member-applied-index", ep.appliedi),
1206-
zap.Uint64("local-member-snapshot-index", ep.diskSnapshotIndex),
1207-
zap.Uint64("local-member-snapshot-count", s.Cfg.SnapshotCount),
1208-
zap.Bool("snapshot-forced", s.forceDiskSnapshot),
1209-
)
1210-
s.forceDiskSnapshot = false
1211-
12121201
s.snapshot(ep)
12131202
s.compactRaftLog(ep.appliedi)
12141203
}
@@ -2131,6 +2120,16 @@ func (s *EtcdServer) applyConfChange(cc raftpb.ConfChange, confState *raftpb.Con
21312120

21322121
// TODO: non-blocking snapshot
21332122
func (s *EtcdServer) snapshot(ep *etcdProgress) {
2123+
lg := s.Logger()
2124+
lg.Info(
2125+
"triggering snapshot",
2126+
zap.String("local-member-id", s.MemberID().String()),
2127+
zap.Uint64("local-member-applied-index", ep.appliedi),
2128+
zap.Uint64("local-member-snapshot-index", ep.diskSnapshotIndex),
2129+
zap.Uint64("local-member-snapshot-count", s.Cfg.SnapshotCount),
2130+
zap.Bool("snapshot-forced", s.forceDiskSnapshot),
2131+
)
2132+
s.forceDiskSnapshot = false
21342133
d := GetMembershipInfoInV2Format(s.Logger(), s.cluster)
21352134
// commit kv to write metadata (for example: consistent index) to disk.
21362135
//
@@ -2143,8 +2142,6 @@ func (s *EtcdServer) snapshot(ep *etcdProgress) {
21432142
// the go routine created below.
21442143
s.KV().Commit()
21452144

2146-
lg := s.Logger()
2147-
21482145
// For backward compatibility, generate v2 snapshot from v3 state.
21492146
snap, err := s.r.raftStorage.CreateSnapshot(ep.appliedi, &ep.confState, d)
21502147
if err != nil {

0 commit comments

Comments
 (0)