Properly detect compactable heads

The fullness of the wrong head was being tracked, causing wrong
lists of compactable heads.
This commit is contained in:
Fabian Reinartz 2017-08-03 13:58:11 +02:00
parent 15baaa5677
commit fa04455cd7
1 changed files with 5 additions and 2 deletions

7
db.go
View File

@ -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
}