Properly sync moves and removes in compactor
This commit is contained in:
parent
92120448c2
commit
327e07e8d0
11
compact.go
11
compact.go
|
@ -193,6 +193,8 @@ func (c *compactor) write(dir string, blocks ...Block) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Populate chunk and index files into temporary directory with
|
||||||
|
// data of all blocks.
|
||||||
chunkw, err := newChunkWriter(chunkDir(tmp))
|
chunkw, err := newChunkWriter(chunkDir(tmp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "open chunk writer")
|
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")
|
return errors.Wrap(err, "close index writer")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Block successfully written, make visible and remove old ones.
|
||||||
if err := renameFile(tmp, dir); err != nil {
|
if err := renameFile(tmp, dir); err != nil {
|
||||||
return errors.Wrap(err, "rename block dir")
|
return errors.Wrap(err, "rename block dir")
|
||||||
}
|
}
|
||||||
|
@ -225,6 +228,14 @@ func (c *compactor) write(dir string, blocks ...Block) (err error) {
|
||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue