Skip to content

Commit

Permalink
Merge pull request #7282 from heyitsanthony/fix-write-snap-2.3
Browse files Browse the repository at this point in the history
snap: fix write snap
  • Loading branch information
xiang90 authored Feb 9, 2017
2 parents 97dd451 + d1ba8ee commit aaf0ac9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion snap/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"
"time"

pioutil "github.com/coreos/etcd/pkg/ioutil"
"github.com/coreos/etcd/pkg/pbutil"
"github.com/coreos/etcd/raft"
"github.com/coreos/etcd/raft/raftpb"
Expand Down Expand Up @@ -78,9 +79,14 @@ func (s *Snapshotter) save(snapshot *raftpb.Snapshot) error {
marshallingDurations.Observe(float64(time.Since(start)) / float64(time.Second))
}

err = ioutil.WriteFile(path.Join(s.dir, fname), d, 0666)
err = pioutil.WriteAndSyncFile(path.Join(s.dir, fname), d, 0666)
if err == nil {
saveDurations.Observe(float64(time.Since(start)) / float64(time.Second))
} else {
err1 := os.Remove(path.Join(s.dir, fname))
if err1 != nil {
plog.Errorf("failed to remove broken snapshot file %s", path.Join(s.dir, fname))
}
}
return err
}
Expand Down

0 comments on commit aaf0ac9

Please sign in to comment.