Browse Source

Merge pull request #4059 from xiang90/snap_log

rafthttp: better snapshot sending logging
Xiang Li 10 years ago
parent
commit
d07a9cd893
1 changed files with 6 additions and 6 deletions
  1. 6 6
      rafthttp/snapshot_sender.go

+ 6 - 6
rafthttp/snapshot_sender.go

@@ -73,14 +73,19 @@ func (s *snapshotSender) send(merged snap.Message) {
 	u := s.picker.pick()
 	u := s.picker.pick()
 	req := createPostRequest(u, RaftSnapshotPrefix, body, "application/octet-stream", s.from, s.cid)
 	req := createPostRequest(u, RaftSnapshotPrefix, body, "application/octet-stream", s.from, s.cid)
 
 
+	plog.Infof("start to send database snapshot [index: %d, to %s]...", m.Snapshot.Metadata.Index, types.ID(m.To))
+
 	err := s.post(req)
 	err := s.post(req)
 	defer merged.CloseWithError(err)
 	defer merged.CloseWithError(err)
 	if err != nil {
 	if err != nil {
+		plog.Warningf("database snapshot [index: %d, to: %s] failed to be sent out (%v)", m.Snapshot.Metadata.Index, types.ID(m.To), err)
+
 		// errMemberRemoved is a critical error since a removed member should
 		// errMemberRemoved is a critical error since a removed member should
 		// always be stopped. So we use reportCriticalError to report it to errorc.
 		// always be stopped. So we use reportCriticalError to report it to errorc.
 		if err == errMemberRemoved {
 		if err == errMemberRemoved {
 			reportCriticalError(err, s.errorc)
 			reportCriticalError(err, s.errorc)
 		}
 		}
+
 		s.picker.unreachable(u)
 		s.picker.unreachable(u)
 		reportSentFailure(sendSnap, m)
 		reportSentFailure(sendSnap, m)
 		s.status.deactivate(failureType{source: sendSnap, action: "post"}, err.Error())
 		s.status.deactivate(failureType{source: sendSnap, action: "post"}, err.Error())
@@ -89,17 +94,12 @@ func (s *snapshotSender) send(merged snap.Message) {
 		// machine knows about it, it would pause a while and retry sending
 		// machine knows about it, it would pause a while and retry sending
 		// new snapshot message.
 		// new snapshot message.
 		s.r.ReportSnapshot(m.To, raft.SnapshotFailure)
 		s.r.ReportSnapshot(m.To, raft.SnapshotFailure)
-		if s.status.isActive() {
-			plog.Warningf("snapshot [index: %d, to: %s] failed to be sent out (%v)", m.Snapshot.Metadata.Index, types.ID(m.To), err)
-		} else {
-			plog.Debugf("snapshot [index: %d, to: %s] failed to be sent out (%v)", m.Snapshot.Metadata.Index, types.ID(m.To), err)
-		}
 		return
 		return
 	}
 	}
 	reportSentDuration(sendSnap, m, time.Since(start))
 	reportSentDuration(sendSnap, m, time.Since(start))
 	s.status.activate()
 	s.status.activate()
 	s.r.ReportSnapshot(m.To, raft.SnapshotFinish)
 	s.r.ReportSnapshot(m.To, raft.SnapshotFinish)
-	plog.Infof("snapshot [index: %d, to: %s] sent out successfully", m.Snapshot.Metadata.Index, types.ID(m.To))
+	plog.Infof("database snapshot [index: %d, to: %s] sent out successfully", m.Snapshot.Metadata.Index, types.ID(m.To))
 }
 }
 
 
 // post posts the given request.
 // post posts the given request.