From 5ea6bdca1f4731fb095d37714c268159213f2b10 Mon Sep 17 00:00:00 2001 From: zhulongcheng Date: Mon, 7 Sep 2020 22:34:49 +0800 Subject: [PATCH] tsdb: sync temporary checkpoint directory before rename (#7004) Signed-off-by: zhulongcheng --- tsdb/wal/checkpoint.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tsdb/wal/checkpoint.go b/tsdb/wal/checkpoint.go index e8aa4326d..0b5a4747b 100644 --- a/tsdb/wal/checkpoint.go +++ b/tsdb/wal/checkpoint.go @@ -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") }