Skip to content

Commit

Permalink
storage: use block-property filters for MVCC range tomstone masking
Browse files Browse the repository at this point in the history
Use block-property filters to aid in skipping keys that are deleted by a
MVCC range tombstone.

Release note: None
  • Loading branch information
jbowens committed Aug 9, 2022
1 parent 8bcd0cd commit 3a0e0e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/storage/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,27 @@ func (tc *pebbleDataBlockMVCCTimeIntervalCollector) UpdateKeySuffixes(

const mvccWallTimeIntervalCollector = "MVCCTimeInterval"

var _ pebble.BlockPropertyFilterMask = (*mvccWallTimeIntervalRangeKeyMask)(nil)

type mvccWallTimeIntervalRangeKeyMask struct {
sstable.BlockIntervalFilter
}

// SetSuffix implements the pebble.BlockPropertyFilterMask interface.
func (m *mvccWallTimeIntervalRangeKeyMask) SetSuffix(suffix []byte) error {
if len(suffix) == 0 {
// This is currently impossible, because the only range key Cockroach
// writes today is the MVCC Delete Range that's always suffixed.
return nil
}
ts, err := DecodeMVCCTimestampSuffix(suffix)
if err != nil {
return err
}
m.BlockIntervalFilter.SetInterval(uint64(ts.WallTime), math.MaxUint64)
return nil
}

// PebbleBlockPropertyCollectors is the list of functions to construct
// BlockPropertyCollectors.
var PebbleBlockPropertyCollectors = []func() pebble.BlockPropertyCollector{
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/pebble_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type pebbleIterator struct {
lowerBoundBuf []byte
upperBoundBuf []byte
rangeKeyMaskingBuf []byte
// Filter to use if masking is enabled.
maskFilter mvccWallTimeIntervalRangeKeyMask

// True if the iterator's underlying reader supports range keys.
//
Expand Down Expand Up @@ -223,6 +225,8 @@ func (p *pebbleIterator) setOptions(opts IterOptions, durability DurabilityRequi
p.rangeKeyMaskingBuf = encodeMVCCTimestampSuffixToBuf(
p.rangeKeyMaskingBuf, opts.RangeKeyMaskingBelow)
p.options.RangeKeyMasking.Suffix = p.rangeKeyMaskingBuf
p.maskFilter.BlockIntervalFilter.Init(mvccWallTimeIntervalCollector, 0, math.MaxUint64)
p.options.RangeKeyMasking.Filter = &p.maskFilter
}

if opts.MaxTimestampHint.IsSet() {
Expand Down

0 comments on commit 3a0e0e0

Please sign in to comment.