Skip to content

Commit

Permalink
fix(compaction): Set base level correctly after stream (#1631)
Browse files Browse the repository at this point in the history
When we use stream writer, all the data is written to the last level. On the restart, 
badger will try to figure out the correct base level. This computation of base level
is incorrect right now because of which we pick the baseLevel which has levels
below it that are empty.
  • Loading branch information
Ibrahim Jarif authored Jan 20, 2021
1 parent 63f09c3 commit d1125c4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,22 @@ func (s *levelsController) levelTargets() targets {
t.fileSz[i] = tsz
}
}

// Bring the base level down to the last empty level.
for i := t.baseLevel + 1; i < len(s.levels)-1; i++ {
if s.levels[i].getTotalSize() > 0 {
break
}
t.baseLevel = i
}

// If the base level is empty and the next level size is less than the
// target size, pick the next level as the base level.
b := t.baseLevel
lvl := s.levels
if b < len(lvl)-1 && lvl[b].getTotalSize() == 0 && lvl[b+1].getTotalSize() < t.targetSz[b+1] {
t.baseLevel++
}
return t
}

Expand Down

0 comments on commit d1125c4

Please sign in to comment.