close blocks which will be remove

This commit is contained in:
Your Name 2017-11-02 00:30:19 +08:00
parent 19340a382d
commit 4a4a706234

21
db.go
View file

@ -379,6 +379,27 @@ func (db *DB) compact() (changes bool, err error) {
}
changes = true
// close blocks in plan so that we can remove files.
var blocks []*Block
db.mtx.Lock()
oldBlocks := db.blocks
for _, b := range oldBlocks {
keep := true
for _, pd := range plan {
if pd == b.Dir() {
keep = false
break
}
}
if keep {
blocks = append(blocks, b)
} else {
b.Close()
}
}
db.blocks = blocks
db.mtx.Unlock()
for _, pd := range plan {
if err := os.RemoveAll(pd); err != nil {
return changes, errors.Wrap(err, "delete compacted block")