From bcd4c82e65058aa4555b74eb8d38bf81783bd696 Mon Sep 17 00:00:00 2001 From: Nick Travers Date: Tue, 14 Dec 2021 11:24:10 -0800 Subject: [PATCH] sstable: add range keys to sstable.Layout The `sstable.Layout` struct contains information pertaining to the layout of an sstable. Add the range key block to the layout. Related to #1339. --- sstable/properties.go | 4 ++-- sstable/reader.go | 9 +++++++-- sstable/testdata/writer | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/sstable/properties.go b/sstable/properties.go index 7ebb9835b9..083480ae75 100644 --- a/sstable/properties.go +++ b/sstable/properties.go @@ -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. diff --git a/sstable/reader.go b/sstable/reader.go index 4fefb768b2..27b5ea7393 100644 --- a/sstable/reader.go +++ b/sstable/reader.go @@ -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, @@ -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. @@ -2719,6 +2720,7 @@ type Layout struct { TopIndex BlockHandle Filter BlockHandle RangeDel BlockHandle + RangeKey BlockHandle Properties BlockHandle MetaIndex BlockHandle Footer BlockHandle @@ -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"}) } @@ -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)) diff --git a/sstable/testdata/writer b/sstable/testdata/writer index 3742e8a5cb..d08a4365bf 100644 --- a/sstable/testdata/writer +++ b/sstable/testdata/writer @@ -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