Skip to content

Commit 1a45921

Browse files
committedAug 30, 2023
sstable: use simple user keys in BoundLimitedBlockPropertyFilter
The BoundLimitedBlockPropertyFilter interface previously unnecessarily accepted InternalKeys for bounds. Index block internal keys always have identical, unmeaningful trailers.
1 parent 74d4bb6 commit 1a45921

6 files changed

+23
-23
lines changed
 

‎range_keys.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -370,24 +370,24 @@ func (m *rangeKeyMasking) Intersects(prop []byte) (bool, error) {
370370
// KeyIsWithinLowerBound implements the limitedBlockPropertyFilter interface
371371
// defined in the sstable package. It's used to restrict the masking block
372372
// property filter to only applying within the bounds of the active range key.
373-
func (m *rangeKeyMasking) KeyIsWithinLowerBound(ik *InternalKey) bool {
373+
func (m *rangeKeyMasking) KeyIsWithinLowerBound(key []byte) bool {
374374
// Invariant: m.maskSpan != nil
375375
//
376-
// The provided `ik` is an inclusive lower bound of the block we're
376+
// The provided `key` is an inclusive lower bound of the block we're
377377
// considering skipping.
378-
return m.cmp(m.maskSpan.Start, ik.UserKey) <= 0
378+
return m.cmp(m.maskSpan.Start, key) <= 0
379379
}
380380

381381
// KeyIsWithinUpperBound implements the limitedBlockPropertyFilter interface
382382
// defined in the sstable package. It's used to restrict the masking block
383383
// property filter to only applying within the bounds of the active range key.
384-
func (m *rangeKeyMasking) KeyIsWithinUpperBound(ik *InternalKey) bool {
384+
func (m *rangeKeyMasking) KeyIsWithinUpperBound(key []byte) bool {
385385
// Invariant: m.maskSpan != nil
386386
//
387-
// The provided `ik` is an *inclusive* upper bound of the block we're
387+
// The provided `key` is an *inclusive* upper bound of the block we're
388388
// considering skipping, so the range key's end must be strictly greater
389389
// than the block bound for the block to be within bounds.
390-
return m.cmp(m.maskSpan.End, ik.UserKey) > 0
390+
return m.cmp(m.maskSpan.End, key) > 0
391391
}
392392

393393
// lazyCombinedIter implements the internalIterator interface, wrapping a

‎sstable/block_property.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ type BoundLimitedBlockPropertyFilter interface {
189189
// indicates that the filter may be used to filter blocks that exclusively
190190
// contain keys ≥ `key`, so long as the blocks' keys also satisfy the upper
191191
// bound.
192-
KeyIsWithinLowerBound(key *InternalKey) bool
192+
KeyIsWithinLowerBound(key []byte) bool
193193
// KeyIsWithinUpperBound tests whether the provided internal key falls
194194
// within the current upper bound of the filter. A true return value
195195
// indicates that the filter may be used to filter blocks that exclusively
196196
// contain keys ≤ `key`, so long as the blocks' keys also satisfy the lower
197197
// bound.
198-
KeyIsWithinUpperBound(key *InternalKey) bool
198+
KeyIsWithinUpperBound(key []byte) bool
199199
}
200200

201201
// BlockIntervalCollector is a helper implementation of BlockPropertyCollector

‎sstable/block_property_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1135,23 +1135,23 @@ func (bl *boundLimitedWrapper) Intersects(prop []byte) (bool, error) {
11351135
return v, err
11361136
}
11371137

1138-
func (bl *boundLimitedWrapper) KeyIsWithinLowerBound(key *InternalKey) (ret bool) {
1138+
func (bl *boundLimitedWrapper) KeyIsWithinLowerBound(key []byte) (ret bool) {
11391139
if bl.lower == nil {
11401140
ret = true
11411141
} else {
1142-
ret = base.InternalCompare(bl.cmp, *key, *bl.lower) >= 0
1142+
ret = bl.cmp(key, bl.lower.UserKey) >= 0
11431143
}
11441144
if bl.w != nil {
11451145
fmt.Fprintf(bl.w, " filter.KeyIsWithinLowerBound(%s) = %t\n", key, ret)
11461146
}
11471147
return ret
11481148
}
11491149

1150-
func (bl *boundLimitedWrapper) KeyIsWithinUpperBound(key *InternalKey) (ret bool) {
1150+
func (bl *boundLimitedWrapper) KeyIsWithinUpperBound(key []byte) (ret bool) {
11511151
if bl.upper == nil {
11521152
ret = true
11531153
} else {
1154-
ret = base.InternalCompare(bl.cmp, *key, *bl.upper) <= 0
1154+
ret = bl.cmp(key, bl.upper.UserKey) <= 0
11551155
}
11561156
if bl.w != nil {
11571157
fmt.Fprintf(bl.w, " filter.KeyIsWithinUpperBound(%s) = %t\n", key, ret)

‎sstable/reader_iter_single_lvl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func (i *singleLevelIterator) resolveMaybeExcluded(dir int8) intersectsResult {
446446
// need.
447447
if dir > 0 {
448448
// Forward iteration.
449-
if i.bpfs.boundLimitedFilter.KeyIsWithinUpperBound(i.index.Key()) {
449+
if i.bpfs.boundLimitedFilter.KeyIsWithinUpperBound(i.index.Key().UserKey) {
450450
return blockExcluded
451451
}
452452
return blockIntersects
@@ -475,7 +475,7 @@ func (i *singleLevelIterator) resolveMaybeExcluded(dir int8) intersectsResult {
475475
// there's a two-level index, it could potentially provide a lower
476476
// bound, but the code refactoring necessary to read it doesn't seem
477477
// worth the payoff. We fall through to loading the block.
478-
} else if i.bpfs.boundLimitedFilter.KeyIsWithinLowerBound(peekKey) {
478+
} else if i.bpfs.boundLimitedFilter.KeyIsWithinLowerBound(peekKey.UserKey) {
479479
// The lower-bound on the original block falls within the filter's
480480
// bounds, and we can skip the block (after restoring our current index
481481
// position).

‎sstable/reader_iter_two_lvl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (i *twoLevelIterator) resolveMaybeExcluded(dir int8) intersectsResult {
9494
// are ≤ topLevelIndex.Key(). For forward iteration, this is all we need.
9595
if dir > 0 {
9696
// Forward iteration.
97-
if i.bpfs.boundLimitedFilter.KeyIsWithinUpperBound(i.topLevelIndex.Key()) {
97+
if i.bpfs.boundLimitedFilter.KeyIsWithinUpperBound(i.topLevelIndex.Key().UserKey) {
9898
return blockExcluded
9999
}
100100
return blockIntersects
@@ -123,7 +123,7 @@ func (i *twoLevelIterator) resolveMaybeExcluded(dir int8) intersectsResult {
123123
// we knew the lower bound for the entire table, it could provide a
124124
// lower bound, but the code refactoring necessary to read it doesn't
125125
// seem worth the payoff. We fall through to loading the block.
126-
} else if i.bpfs.boundLimitedFilter.KeyIsWithinLowerBound(peekKey) {
126+
} else if i.bpfs.boundLimitedFilter.KeyIsWithinLowerBound(peekKey.UserKey) {
127127
// The lower-bound on the original index block falls within the filter's
128128
// bounds, and we can skip the block (after restoring our current
129129
// top-level index position).

‎sstable/testdata/block_properties_boundlimited

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ next
7979
<c@9:3> MaybeFilteredKeys()=false
8080
<d@3:4> MaybeFilteredKeys()=false
8181
filter.Intersects([0, 3)) = (false, <nil>)
82-
filter.KeyIsWithinUpperBound(g#72057594037927935,17) = true
82+
filter.KeyIsWithinUpperBound(g) = true
8383
filter.Intersects([3, 9)) = (true, <nil>)
8484
<g@8:7> MaybeFilteredKeys()=true
8585
<h@3:8> MaybeFilteredKeys()=false
@@ -106,7 +106,7 @@ next
106106
<c@9:3> MaybeFilteredKeys()=false
107107
<d@3:4> MaybeFilteredKeys()=false
108108
filter.Intersects([0, 3)) = (false, <nil>)
109-
filter.KeyIsWithinUpperBound(g#72057594037927935,17) = false
109+
filter.KeyIsWithinUpperBound(g) = false
110110
<e@2:5> MaybeFilteredKeys()=false
111111
<f@0:6> MaybeFilteredKeys()=false
112112
filter.Intersects([3, 9)) = (true, <nil>)
@@ -126,14 +126,14 @@ next
126126
next
127127
----
128128
filter.Intersects([2, 6)) = (false, <nil>)
129-
filter.KeyIsWithinUpperBound(c#72057594037927935,17) = true
129+
filter.KeyIsWithinUpperBound(c) = true
130130
filter.Intersects([3, 10)) = (false, <nil>)
131-
filter.KeyIsWithinUpperBound(e#72057594037927935,17) = true
131+
filter.KeyIsWithinUpperBound(e) = true
132132
filter.Intersects([0, 3)) = (true, <nil>)
133133
<e@2:5> MaybeFilteredKeys()=true
134134
<f@0:6> MaybeFilteredKeys()=false
135135
filter.Intersects([3, 9)) = (false, <nil>)
136-
filter.KeyIsWithinUpperBound(i#72057594037927935,17) = false
136+
filter.KeyIsWithinUpperBound(i) = false
137137
<g@8:7> MaybeFilteredKeys()=false
138138
<h@3:8> MaybeFilteredKeys()=false
139139
. MaybeFilteredKeys()=false
@@ -152,9 +152,9 @@ prev
152152
prev
153153
----
154154
filter.Intersects([3, 9)) = (false, <nil>)
155-
filter.KeyIsWithinLowerBound(g#72057594037927935,17) = true
155+
filter.KeyIsWithinLowerBound(g) = true
156156
filter.Intersects([0, 3)) = (false, <nil>)
157-
filter.KeyIsWithinLowerBound(e#72057594037927935,17) = true
157+
filter.KeyIsWithinLowerBound(e) = true
158158
filter.Intersects([3, 10)) = (true, <nil>)
159159
<d@3:4> MaybeFilteredKeys()=true
160160
<c@9:3> MaybeFilteredKeys()=false

0 commit comments

Comments
 (0)
Please sign in to comment.