*: record the number of bytes of snapshot sent/received

This commit is contained in:
Xiang Li 2016-02-16 16:05:20 -08:00
parent 82c3600cfa
commit 994333e720
2 changed files with 9 additions and 2 deletions

View File

@ -60,7 +60,10 @@ func (s *EtcdServer) createMergedSnapshotMessage(m raftpb.Message, snapi uint64,
func newSnapshotReaderCloser(snapshot backend.Snapshot) io.ReadCloser {
pr, pw := io.Pipe()
go func() {
_, err := snapshot.WriteTo(pw)
n, err := snapshot.WriteTo(pw)
if err == nil {
plog.Infof("wrote database snapshot out [total bytes: %d]", n)
}
pw.CloseWithError(err)
snapshot.Close()
}()

View File

@ -31,7 +31,8 @@ func (s *Snapshotter) SaveDBFrom(r io.Reader, id uint64) error {
if err != nil {
return err
}
_, err = io.Copy(f, r)
var n int64
n, err = io.Copy(f, r)
if err == nil {
err = f.Sync()
}
@ -50,6 +51,9 @@ func (s *Snapshotter) SaveDBFrom(r io.Reader, id uint64) error {
os.Remove(f.Name())
return err
}
plog.Infof("saved database snapshot to disk [total bytes: %d]", n)
return nil
}