Skip to content

Commit abf8da2

Browse files
committed
sstable: save UserProperties from Properties on sstable reader
To support removing the `Properties` field from the reader, we should save at least the UserProperties to support checking the intersection of filters when creating RangeKey and Point iterators. Part of: #4383
1 parent 0b20388 commit abf8da2

11 files changed

+30
-28
lines changed

file_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ func checkAndIntersectFilters(
511511
filterer, err = sstable.IntersectsTable(
512512
blockPropertyFilters,
513513
boundLimitedFilter,
514-
r.Properties.UserProperties,
514+
r.UserProperties,
515515
syntheticSuffix,
516516
)
517517
// NB: IntersectsTable will return a nil filterer if the table-level

metamorphic/options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func TestBlockPropertiesParse(t *testing.T) {
217217
if err != nil {
218218
return errors.CombineErrors(err, readable.Close())
219219
}
220-
_, ok := r.Properties.UserProperties[opts.Opts.BlockPropertyCollectors[0]().Name()]
220+
_, ok := r.UserProperties[opts.Opts.BlockPropertyCollectors[0]().Name()]
221221
foundTableBlockProperty = foundTableBlockProperty || ok
222222
return r.Close()
223223
}))

sstable/block_property_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ func TestBlockProperties(t *testing.T) {
892892
buf.WriteString("points: ")
893893
if len(points) > 0 {
894894
f = newBlockPropertiesFilterer(points, nil, syntheticSuffix)
895-
ok, err := f.intersectsUserPropsAndFinishInit(r.Properties.UserProperties)
895+
ok, err := f.intersectsUserPropsAndFinishInit(r.UserProperties)
896896
if err != nil {
897897
return err.Error()
898898
}
@@ -949,7 +949,7 @@ func TestBlockProperties(t *testing.T) {
949949
buf.WriteString("ranges: ")
950950
if len(ranges) > 0 {
951951
f := newBlockPropertiesFilterer(ranges, nil, nil)
952-
ok, err := f.intersectsUserPropsAndFinishInit(r.Properties.UserProperties)
952+
ok, err := f.intersectsUserPropsAndFinishInit(r.UserProperties)
953953
if err != nil {
954954
return err.Error()
955955
}
@@ -980,7 +980,7 @@ func TestBlockProperties(t *testing.T) {
980980
}
981981
}
982982
filterer := newBlockPropertiesFilterer(filters, nil, nil)
983-
ok, err := filterer.intersectsUserPropsAndFinishInit(r.Properties.UserProperties)
983+
ok, err := filterer.intersectsUserPropsAndFinishInit(r.UserProperties)
984984
if err != nil {
985985
return err.Error()
986986
} else if !ok {
@@ -1070,7 +1070,7 @@ func TestBlockProperties_BoundLimited(t *testing.T) {
10701070
}
10711071

10721072
filterer := newBlockPropertiesFilterer(nil, &filter, syntheticSuffix)
1073-
ok, err := filterer.intersectsUserPropsAndFinishInit(r.Properties.UserProperties)
1073+
ok, err := filterer.intersectsUserPropsAndFinishInit(r.UserProperties)
10741074
if err != nil {
10751075
return err.Error()
10761076
} else if !ok {
@@ -1193,7 +1193,7 @@ func parseIntervalFilter(cmd datadriven.CmdArg) (BlockPropertyFilter, error) {
11931193

11941194
func runCollectorsCmd(r *Reader, td *datadriven.TestData) string {
11951195
var lines []string
1196-
for k, v := range r.Properties.UserProperties {
1196+
for k, v := range r.UserProperties {
11971197
lines = append(lines, fmt.Sprintf("%d: %s", v[0], k))
11981198
}
11991199
linesSorted := sort.StringSlice(lines)
@@ -1203,7 +1203,7 @@ func runCollectorsCmd(r *Reader, td *datadriven.TestData) string {
12031203

12041204
func runTablePropsCmd(r *Reader, td *datadriven.TestData) string {
12051205
var lines []string
1206-
for _, val := range r.Properties.UserProperties {
1206+
for _, val := range r.UserProperties {
12071207
id := shortID(val[0])
12081208
i, err := decodeBlockInterval([]byte(val[1:]))
12091209
if err != nil {

sstable/reader.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ type Reader struct {
6565
metaindexBH block.Handle
6666
footerBH block.Handle
6767

68-
Properties Properties
69-
tableFormat TableFormat
70-
Attributes Attributes
68+
Properties Properties
69+
tableFormat TableFormat
70+
Attributes Attributes
71+
UserProperties map[string]string
7172
}
7273

7374
type ReadEnv struct {
@@ -486,6 +487,7 @@ func (r *Reader) readMetaindex(
486487
if err != nil {
487488
return err
488489
}
490+
r.UserProperties = r.Properties.UserProperties
489491
} else {
490492
return errors.New("did not read any value for the properties block in the meta index")
491493
}
@@ -549,11 +551,11 @@ var propertiesBlockBufPools = sync.Pool{
549551
},
550552
}
551553

552-
// ReadPropertiesBlock reads the properties block from the table.
553-
// We always read the properties block into a buffer pool instead
554-
// of the block cache.
554+
// ReadPropertiesBlock reads the properties block
555+
// from the table. We always read the properties block into a buffer pool
556+
// instead of the block cache.
555557
func (r *Reader) ReadPropertiesBlock(
556-
ctx context.Context, bufferPool *block.BufferPool, deniedUserProperties map[string]struct{},
558+
ctx context.Context, bufferPool *block.BufferPool,
557559
) (Properties, error) {
558560
return r.readPropertiesBlockInternal(ctx, bufferPool, noReadHandle)
559561
}

sstable/reader_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ func runTestReader(t *testing.T, o WriterOptions, dir string, r *Reader, printVa
778778
if len(bpfs) > 0 {
779779
filterer = newBlockPropertiesFilterer(bpfs, nil, nil)
780780
intersects, err :=
781-
filterer.intersectsUserPropsAndFinishInit(r.Properties.UserProperties)
781+
filterer.intersectsUserPropsAndFinishInit(r.UserProperties)
782782
if err != nil {
783783
return err.Error()
784784
}
@@ -2512,7 +2512,7 @@ func BenchmarkIteratorScanObsolete(b *testing.B) {
25122512
filterer = newBlockPropertiesFilterer(
25132513
[]BlockPropertyFilter{obsoleteKeyBlockPropertyFilter{}}, nil, nil)
25142514
intersects, err :=
2515-
filterer.intersectsUserPropsAndFinishInit(r.Properties.UserProperties)
2515+
filterer.intersectsUserPropsAndFinishInit(r.UserProperties)
25162516
if err != nil {
25172517
b.Fatalf("%s", err.Error())
25182518
}

sstable/suffix_rewriter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func getShortIDs(
270270
shortIDs[i] = invalidShortID
271271
}
272272
for i, p := range collectors {
273-
prop, ok := r.Properties.UserProperties[p.Name()]
273+
prop, ok := r.UserProperties[p.Name()]
274274
if !ok {
275275
return nil, 0, errors.Errorf("sstable does not contain property %s", p.Name())
276276
}

sstable/suffix_rewriter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestRewriteSuffixProps(t *testing.T) {
112112
defer rRewritten.Close()
113113

114114
foundValues := make(map[string][]byte)
115-
for k, v := range rRewritten.Properties.UserProperties {
115+
for k, v := range rRewritten.UserProperties {
116116
if k == "obsolete-key" {
117117
continue
118118
}

testdata/ingest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Local tables size: 569B
5555
Compression types: snappy: 1
5656
Table stats: all loaded
5757
Block cache: 3 entries (1.1KB) hit rate: 18.2%
58-
Table cache: 1 entries (832B) hit rate: 50.0%
58+
Table cache: 1 entries (840B) hit rate: 50.0%
5959
Range key sets: 0 Tombstones: 0 Total missized tombstones encountered: 0
6060
Snapshots: 0 earliest seq num: 0
6161
Table iters: 0

testdata/metrics

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Local tables size: 755B
7878
Compression types: snappy: 1
7979
Table stats: all loaded
8080
Block cache: 2 entries (795B) hit rate: 0.0%
81-
Table cache: 1 entries (832B) hit rate: 0.0%
81+
Table cache: 1 entries (840B) hit rate: 0.0%
8282
Range key sets: 0 Tombstones: 0 Total missized tombstones encountered: 0
8383
Snapshots: 0 earliest seq num: 0
8484
Table iters: 1
@@ -236,7 +236,7 @@ Local tables size: 1.5KB
236236
Compression types: snappy: 2
237237
Table stats: all loaded
238238
Block cache: 2 entries (795B) hit rate: 33.3%
239-
Table cache: 1 entries (832B) hit rate: 66.7%
239+
Table cache: 1 entries (840B) hit rate: 66.7%
240240
Range key sets: 0 Tombstones: 0 Total missized tombstones encountered: 0
241241
Snapshots: 0 earliest seq num: 0
242242
Table iters: 1

tool/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ func (d *dbT) addProps(objProvider objstorage.Provider, m *manifest.TableMetadat
10141014
return errors.CombineErrors(err, f.Close())
10151015
}
10161016

1017-
properties, err := r.ReadPropertiesBlock(context.TODO(), nil /* buffer pool */, opts.DeniedUserProperties)
1017+
properties, err := r.ReadPropertiesBlock(context.TODO(), nil /* buffer pool */)
10181018
if err != nil {
10191019
return errors.CombineErrors(err, r.Close())
10201020
}

tool/sstable.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,14 @@ func (s *sstableT) runProperties(cmd *cobra.Command, args []string) {
319319
fmt.Fprintf(tw, " options\t%s\n", props.CompressionOptions)
320320
fmt.Fprintf(tw, "user properties\t\n")
321321
fmt.Fprintf(tw, " collectors\t%s\n", props.PropertyCollectorNames)
322-
keys := make([]string, 0, len(props.UserProperties))
323-
for key := range props.UserProperties {
322+
// Read UserProperties directly from reader.
323+
keys := make([]string, 0, len(r.UserProperties))
324+
for key := range r.UserProperties {
324325
keys = append(keys, key)
325326
}
326327
slices.Sort(keys)
327328
for _, key := range keys {
328-
fmt.Fprintf(tw, " %s\t%s\n", key, props.UserProperties[key])
329+
fmt.Fprintf(tw, " %s\t%s\n", key, r.UserProperties[key])
329330
}
330331
_ = tw.Flush()
331332
})
@@ -584,8 +585,7 @@ func (s *sstableT) foreachSstable(
584585
}
585586
defer func() { _ = r.Close() }()
586587

587-
deniedUserProps := s.opts.MakeReaderOptions().DeniedUserProperties
588-
props, err := r.ReadPropertiesBlock(context.Background(), nil /* buffer pool */, deniedUserProps)
588+
props, err := r.ReadPropertiesBlock(context.Background(), nil /* buffer pool */)
589589
if err != nil {
590590
fmt.Fprintf(stderr, "%s\n", err)
591591
return

0 commit comments

Comments
 (0)