Skip to content

Commit 0ee2a61

Browse files
authored
fix(blooms): Fix findGaps when ownership goes to MaxUInt64 and that is covered by existing meta (#12558)
1 parent 2f24b67 commit 0ee2a61

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

‎pkg/bloomcompactor/controller.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"math"
78
"sort"
89
"sync"
910

@@ -735,7 +736,11 @@ func findGaps(ownershipRange v1.FingerprintBounds, metas []v1.FingerprintBounds)
735736

736737
searchRange := ownershipRange.Slice(leftBound, clippedMeta.Max)
737738
// update the left bound for the next iteration
738-
leftBound = min(clippedMeta.Max+1, ownershipRange.Max+1)
739+
// We do the max to prevent the max bound to overflow from MaxUInt64 to 0
740+
leftBound = min(
741+
max(clippedMeta.Max+1, clippedMeta.Max),
742+
max(ownershipRange.Max+1, ownershipRange.Max),
743+
)
739744

740745
// since we've already ensured that the meta is within the ownership range,
741746
// we know the xor will be of length zero (when the meta is equal to the ownership range)
@@ -750,8 +755,11 @@ func findGaps(ownershipRange v1.FingerprintBounds, metas []v1.FingerprintBounds)
750755
gaps = append(gaps, xors[0])
751756
}
752757

753-
if leftBound <= ownershipRange.Max {
754-
// There is a gap between the last meta and the end of the ownership range.
758+
// If the leftBound is less than the ownership range max, and it's smaller than MaxUInt64,
759+
// There is a gap between the last meta and the end of the ownership range.
760+
// Note: we check `leftBound < math.MaxUint64` since in the loop above we clamp the
761+
// leftBound to MaxUint64 to prevent an overflow to 0: `max(clippedMeta.Max+1, clippedMeta.Max)`
762+
if leftBound < math.MaxUint64 && leftBound <= ownershipRange.Max {
755763
gaps = append(gaps, v1.NewBounds(leftBound, ownershipRange.Max))
756764
}
757765

‎pkg/bloomcompactor/controller_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bloomcompactor
22

33
import (
44
"fmt"
5+
"math"
56
"testing"
67
"time"
78

@@ -103,6 +104,27 @@ func Test_findGaps(t *testing.T) {
103104
v1.NewBounds(6, 7),
104105
},
105106
},
107+
{
108+
desc: "full ownership range with single meta",
109+
err: false,
110+
exp: nil,
111+
ownershipRange: v1.NewBounds(0, math.MaxUint64),
112+
metas: []v1.FingerprintBounds{
113+
v1.NewBounds(0, math.MaxUint64),
114+
},
115+
},
116+
{
117+
desc: "full ownership range with multiple metas",
118+
err: false,
119+
exp: nil,
120+
ownershipRange: v1.NewBounds(0, math.MaxUint64),
121+
// Three metas covering the whole 0 - MaxUint64
122+
metas: []v1.FingerprintBounds{
123+
v1.NewBounds(0, math.MaxUint64/3),
124+
v1.NewBounds(math.MaxUint64/3+1, math.MaxUint64/2),
125+
v1.NewBounds(math.MaxUint64/2+1, math.MaxUint64),
126+
},
127+
},
106128
} {
107129
t.Run(tc.desc, func(t *testing.T) {
108130
gaps, err := findGaps(tc.ownershipRange, tc.metas)

0 commit comments

Comments
 (0)