Close blocks before overwriting with compacted one

This prevents the meta.json file of a compacted block
to be overwritten with data of the old block.
This commit is contained in:
Fabian Reinartz 2017-02-02 09:32:06 +01:00
parent ac5229e1b4
commit f556036037
1 changed files with 6 additions and 3 deletions

9
db.go
View File

@ -264,6 +264,12 @@ func (db *DB) compact(i, j int) error {
db.mtx.Lock()
defer db.mtx.Unlock()
for _, b := range blocks {
if err := b.Close(); err != nil {
return errors.Wrap(err, "close old block")
}
}
if err := renameDir(tmpdir, dir); err != nil {
return errors.Wrap(err, "rename dir")
}
@ -273,9 +279,6 @@ func (db *DB) compact(i, j int) error {
db.persisted = append(db.persisted, pb)
for i, b := range blocks {
if err := b.Close(); err != nil {
return errors.Wrap(err, "close old block")
}
if i > 0 {
if err := os.RemoveAll(b.Dir()); err != nil {
return errors.Wrap(err, "removing old block")