From 327e07e8d03ade52a67e9a4f5e2fca5854881c32 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 2 Mar 2017 14:35:06 +0100 Subject: [PATCH] Properly sync moves and removes in compactor --- compact.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compact.go b/compact.go index fe34174a7..18c16ace2 100644 --- a/compact.go +++ b/compact.go @@ -193,6 +193,8 @@ func (c *compactor) write(dir string, blocks ...Block) (err error) { return err } + // Populate chunk and index files into temporary directory with + // data of all blocks. chunkw, err := newChunkWriter(chunkDir(tmp)) if err != nil { return errors.Wrap(err, "open chunk writer") @@ -217,6 +219,7 @@ func (c *compactor) write(dir string, blocks ...Block) (err error) { return errors.Wrap(err, "close index writer") } + // Block successfully written, make visible and remove old ones. if err := renameFile(tmp, dir); err != nil { return errors.Wrap(err, "rename block dir") } @@ -225,6 +228,14 @@ func (c *compactor) write(dir string, blocks ...Block) (err error) { return err } } + // Properly sync parent dir to ensure changes are visible. + df, err := fileutil.OpenDir(dir) + if err != nil { + return errors.Wrap(err, "sync block dir") + } + if err := fileutil.Fsync(df); err != nil { + return errors.Wrap(err, "sync block dir") + } return nil }