Skip to content

Commit

Permalink
db: fix compaction bounds expansion to avoid empty key comparisons
Browse files Browse the repository at this point in the history
Fix #3837.
  • Loading branch information
jbowens committed Aug 12, 2024
1 parent 9a4f0c8 commit 5627daf
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions compaction_picker.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,23 +374,16 @@ func (pc *pickedCompaction) clone() *pickedCompaction {
return newPC
}

// maybeExpandedBounds is a helper function for setupInputs which ensures the
// maybeExpandBounds is a helper function for setupInputs which ensures the
// pickedCompaction's smallest and largest internal keys are updated iff
// the candidate keys expand the key span. This avoids a bug for multi-level
// compactions: during the second call to setupInputs, the picked compaction's
// smallest and largest keys should not decrease the key span.
func (pc *pickedCompaction) maybeExpandBounds(smallest InternalKey, largest InternalKey) {
emptyKey := InternalKey{}
if base.InternalCompare(pc.cmp, smallest, emptyKey) == 0 {
if base.InternalCompare(pc.cmp, largest, emptyKey) != 0 {
panic("either both candidate keys are empty or neither are empty")
}
if len(smallest.UserKey) == 0 && len(largest.UserKey) == 0 {
return
}
if base.InternalCompare(pc.cmp, pc.smallest, emptyKey) == 0 {
if base.InternalCompare(pc.cmp, pc.largest, emptyKey) != 0 {
panic("either both pc keys are empty or neither are empty")
}
if len(pc.smallest.UserKey) == 0 && len(pc.largest.UserKey) == 0 {
pc.smallest = smallest
pc.largest = largest
return
Expand Down

0 comments on commit 5627daf

Please sign in to comment.