From fa04455cd798d7db0a1dfbd10f2d10b8e09f4fba Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 3 Aug 2017 13:58:11 +0200 Subject: [PATCH] Properly detect compactable heads The fullness of the wrong head was being tracked, causing wrong lists of compactable heads. --- db.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/db.go b/db.go index 298c61243d..928e8e9e97 100644 --- a/db.go +++ b/db.go @@ -360,8 +360,11 @@ func (db *DB) completedHeads() (r []headBlock) { // Add the 2nd last head if the last head is more than 50% filled. // Compacting it early allows us to free its memory before allocating // more for the next block and thus reduces spikes. - if h2 := db.heads[len(db.heads)-2]; headFullness(h2) >= 0.5 && h2.ActiveWriters() == 0 { - r = append(r, h2) + h0 := db.heads[len(db.heads)-1] + h1 := db.heads[len(db.heads)-2] + + if headFullness(h0) >= 0.5 && h1.ActiveWriters() == 0 { + r = append(r, h1) } return r }