Skip to content

Commit

Permalink
sstable: add range keys to sstable.Layout
Browse files Browse the repository at this point in the history
The `sstable.Layout` struct contains information pertaining to the
layout of an sstable. Add the range key block to the layout.

Related to #1339.
  • Loading branch information
nicktrav committed Dec 16, 2021
1 parent cccd12f commit bcd4c82
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sstable/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ type Properties struct {
// Total raw key size.
RawKeySize uint64 `prop:"rocksdb.raw.key.size"`
// Total raw rangekey key size.
RawRangeKeyKeySize uint64 `prop:"pebble.raw.rangekey.key.size"`
RawRangeKeyKeySize uint64 `prop:"pebble.raw.range-key.key.size"`
// Total raw rangekey value size.
RawRangeKeyValueSize uint64 `prop:"pebble.raw.rangekey.value.size"`
RawRangeKeyValueSize uint64 `prop:"pebble.raw.range-key.value.size"`
// Total raw value size.
RawValueSize uint64 `prop:"rocksdb.raw.value.size"`
// Size of the top-level index if kTwoLevelIndexSearch is used.
Expand Down
9 changes: 7 additions & 2 deletions sstable/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,7 @@ func (r *Reader) Layout() (*Layout, error) {
Data: make([]BlockHandle, 0, r.Properties.NumDataBlocks),
Filter: r.filterBH,
RangeDel: r.rangeDelBH,
RangeKey: r.rangeKeyBH,
Properties: r.propertiesBH,
MetaIndex: r.metaIndexBH,
Footer: r.footerBH,
Expand Down Expand Up @@ -2478,7 +2479,7 @@ func (r *Reader) ValidateBlockChecksums() error {
var blocks []BlockHandle
blocks = append(blocks, l.Data...)
blocks = append(blocks, l.Index...)
blocks = append(blocks, l.TopIndex, l.Filter, l.RangeDel, l.Properties, l.MetaIndex)
blocks = append(blocks, l.TopIndex, l.Filter, l.RangeDel, l.RangeKey, l.Properties, l.MetaIndex)

// Sorting by offset ensures we are performing a sequential scan of the
// file.
Expand Down Expand Up @@ -2719,6 +2720,7 @@ type Layout struct {
TopIndex BlockHandle
Filter BlockHandle
RangeDel BlockHandle
RangeKey BlockHandle
Properties BlockHandle
MetaIndex BlockHandle
Footer BlockHandle
Expand Down Expand Up @@ -2750,6 +2752,9 @@ func (l *Layout) Describe(
if l.RangeDel.Length != 0 {
blocks = append(blocks, block{l.RangeDel, "range-del"})
}
if l.RangeKey.Length != 0 {
blocks = append(blocks, block{l.RangeKey, "range-key"})
}
if l.Properties.Length != 0 {
blocks = append(blocks, block{l.Properties, "properties"})
}
Expand Down Expand Up @@ -2861,7 +2866,7 @@ func (l *Layout) Describe(

var lastKey InternalKey
switch b.name {
case "data", "range-del":
case "data", "range-del", "range-key":
iter, _ := newBlockIter(r.Compare, h.Get())
for key, value := iter.First(); key != nil; key, value = iter.Next() {
ptr := unsafe.Pointer(uintptr(iter.ptr) + uintptr(iter.offset))
Expand Down
22 changes: 22 additions & 0 deletions sstable/testdata/writer
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,25 @@ layout
813 meta-index (33)
851 leveldb-footer (48)
899 EOF

# Range keys, if present, are shown in the layout.

build
a.RANGEKEYSET.3:b [(@t3=foo)]
b.RANGEKEYSET.2:c [(@t2=bar)]
c.RANGEKEYSET.1:d [(@t1=baz)]
----
point: [#0,0,#0,0]
rangedel: [#0,0,#0,0]
rangekey: [a#3,21,d#72057594037927935,21]
seqnums: [1,3]

layout
----
0 data (8)
13 index (21)
39 range-key (82)
126 properties (765)
896 meta-index (57)
958 footer (53)
1011 EOF

0 comments on commit bcd4c82

Please sign in to comment.