@@ -981,7 +981,7 @@ func (s *EtcdServer) applyAll(ep *etcdProgress, apply *toApply) {
981
981
// storage, since the raft routine might be slower than toApply routine.
982
982
<- apply .notifyc
983
983
984
- s .triggerSnapshot (ep )
984
+ s .snapshotIfNeededAndCompactRaftLog (ep )
985
985
select {
986
986
// snapshot requested via send()
987
987
case m := <- s .r .msgSnapC :
@@ -1194,21 +1194,10 @@ func (s *EtcdServer) ForceSnapshot() {
1194
1194
s .forceDiskSnapshot = true
1195
1195
}
1196
1196
1197
- func (s * EtcdServer ) triggerSnapshot (ep * etcdProgress ) {
1197
+ func (s * EtcdServer ) snapshotIfNeededAndCompactRaftLog (ep * etcdProgress ) {
1198
1198
if ! s .shouldSnapshot (ep ) {
1199
1199
return
1200
1200
}
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
-
1212
1201
s .snapshot (ep )
1213
1202
s .compactRaftLog (ep .appliedi )
1214
1203
}
@@ -2131,6 +2120,16 @@ func (s *EtcdServer) applyConfChange(cc raftpb.ConfChange, confState *raftpb.Con
2131
2120
2132
2121
// TODO: non-blocking snapshot
2133
2122
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
2134
2133
d := GetMembershipInfoInV2Format (s .Logger (), s .cluster )
2135
2134
// commit kv to write metadata (for example: consistent index) to disk.
2136
2135
//
@@ -2143,8 +2142,6 @@ func (s *EtcdServer) snapshot(ep *etcdProgress) {
2143
2142
// the go routine created below.
2144
2143
s .KV ().Commit ()
2145
2144
2146
- lg := s .Logger ()
2147
-
2148
2145
// For backward compatibility, generate v2 snapshot from v3 state.
2149
2146
snap , err := s .r .raftStorage .CreateSnapshot (ep .appliedi , & ep .confState , d )
2150
2147
if err != nil {
0 commit comments