From 04783831e2dabc67e4ec157d6a56f0afe3fa9088 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 6 Mar 2017 09:33:55 +0100 Subject: [PATCH] Correctly close compacted blocks. --- compact.go | 2 ++ db.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/compact.go b/compact.go index 51d4ce0d1..573e9b440 100644 --- a/compact.go +++ b/compact.go @@ -163,6 +163,8 @@ func (c *compactor) Compact(dirs ...string) (err error) { if err != nil { return err } + defer b.Close() + blocks = append(blocks, b) } diff --git a/db.go b/db.go index b1a3a2421..0fd7aa281 100644 --- a/db.go +++ b/db.go @@ -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 }