diff --git a/db.go b/db.go index 2901b3943a..fb3fdc9691 100644 --- a/db.go +++ b/db.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "strconv" "strings" "sync" @@ -285,6 +286,7 @@ func (db *DB) compact() (changes bool, err error) { return changes, errors.Wrap(err, "persist head block") } changes = true + runtime.GC() } // Check for compactions of multiple blocks. @@ -293,6 +295,9 @@ func (db *DB) compact() (changes bool, err error) { if err != nil { return changes, errors.Wrap(err, "plan compaction") } + if len(plans) == 0 { + break + } select { case <-db.stopc: @@ -309,10 +314,7 @@ func (db *DB) compact() (changes bool, err error) { return changes, errors.Wrapf(err, "compact %s", p) } changes = true - } - // If we didn't compact anything, there's nothing left to do. - if len(plans) == 0 { - break + runtime.GC() } }