tsdb: sync temporary checkpoint directory before rename
@@ -249,6 +249,20 @@ func Checkpoint(logger log.Logger, w *WAL, from, to int, keep func(id uint64) bo
if err := cp.Close(); err != nil {
return nil, errors.Wrap(err, "close checkpoint")
}
+
+ // Sync temporary directory before rename.
+ df, err := fileutil.OpenDir(cpdirtmp)
+ if err != nil {
+ return nil, errors.Wrap(err, "open temporary checkpoint directory")
+ }
+ if err := df.Sync(); err != nil {
+ df.Close()
+ return nil, errors.Wrap(err, "sync temporary checkpoint directory")
+ }
+ if err = df.Close(); err != nil {
+ return nil, errors.Wrap(err, "close temporary checkpoint directory")
+ }
+
if err := fileutil.Replace(cpdirtmp, cpdir); err != nil {
return nil, errors.Wrap(err, "rename checkpoint directory")
}
