Properly sync moves and removes in compactor

This commit is contained in:
Fabian Reinartz 2017-03-02 14:35:06 +01:00
parent 92120448c2
commit 327e07e8d0
1 changed files with 11 additions and 0 deletions

View File

@ -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
}