Correctly close compacted blocks.

This commit is contained in:
Fabian Reinartz 2017-03-06 09:33:55 +01:00
parent 55a9b5428a
commit 04783831e2
2 changed files with 10 additions and 5 deletions

View file

@ -163,6 +163,8 @@ func (c *compactor) Compact(dirs ...string) (err error) {
if err != nil {
return err
}
defer b.Close()
blocks = append(blocks, b)
}

13
db.go
View file

@ -334,6 +334,9 @@ func (db *DB) reloadBlocks() error {
db.mtx.Lock()
defer db.mtx.Unlock()
db.headmtx.Lock()
defer db.headmtx.Unlock()
dirs, err := blockDirs(db.dir)
if err != nil {
return errors.Wrap(err, "find blocks")
@ -355,17 +358,17 @@ func (db *DB) reloadBlocks() error {
for i, meta := range metas {
b, ok := db.seqBlocks[meta.Sequence]
if !ok {
return errors.Errorf("missing block for sequence %d", meta.Sequence)
}
// if !ok {
// return errors.Errorf("missing block for sequence %d", meta.Sequence)
// }
if meta.Compaction.Generation == 0 {
if meta.ULID != b.Meta().ULID {
if ok && meta.ULID != b.Meta().ULID {
return errors.Errorf("head block ULID changed unexpectedly")
}
heads = append(heads, b.(*headBlock))
} else {
if meta.ULID != b.Meta().ULID {
if ok && meta.ULID != b.Meta().ULID {
if err := b.Close(); err != nil {
return err
}