Browse Source

Merge pull request #5694 from xiang90/comp

etcdserver: only pause compaction when sending snapshot
Xiang Li 9 years ago
parent
commit
5f5c3c8f82
1 changed files with 10 additions and 9 deletions
  1. 10 9
      etcdserver/server.go

+ 10 - 9
etcdserver/server.go

@@ -743,15 +743,6 @@ func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) {
 		return
 		return
 	}
 	}
 
 
-	// 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
-	// the snapshot sent might already be compacted. It happens when the snapshot takes long time
-	// to send and save. Pausing compaction avoids triggering a snapshot sending cycle.
-	if atomic.LoadInt64(&s.inflightSnapshots) != 0 {
-		return
-	}
-
 	plog.Infof("start to snapshot (applied: %d, lastsnap: %d)", ep.appliedi, ep.snapi)
 	plog.Infof("start to snapshot (applied: %d, lastsnap: %d)", ep.appliedi, ep.snapi)
 	s.snapshot(ep.appliedi, ep.confState)
 	s.snapshot(ep.appliedi, ep.confState)
 	ep.snapi = ep.appliedi
 	ep.snapi = ep.appliedi
@@ -1170,6 +1161,16 @@ func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) {
 		}
 		}
 		plog.Infof("saved snapshot at index %d", snap.Metadata.Index)
 		plog.Infof("saved snapshot at index %d", snap.Metadata.Index)
 
 
+		// 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
+		// the snapshot sent might already be compacted. It happens when the snapshot takes long time
+		// to send and save. Pausing compaction avoids triggering a snapshot sending cycle.
+		if atomic.LoadInt64(&s.inflightSnapshots) != 0 {
+			plog.Infof("skip compaction since there is an inflight snapshot")
+			return
+		}
+
 		// keep some in memory log entries for slow followers.
 		// keep some in memory log entries for slow followers.
 		compacti := uint64(1)
 		compacti := uint64(1)
 		if snapi > numberOfCatchUpEntries {
 		if snapi > numberOfCatchUpEntries {