Skip to content

Commit 5a3aa66

Browse files
committed
sstable: remove CommonProperties
Fold back `sstable.CommonProperties` into `sstable.Properties`; we no longer need this (somewhat artificial) separation.
1 parent 6c81480 commit 5a3aa66

File tree

7 files changed

+60
-106
lines changed

7 files changed

+60
-106
lines changed

compaction_picker_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ func parseTableMeta(t *testing.T, s string, opts *Options) (*manifest.TableMetad
160160
return nil, err
161161
}
162162
m.TableBacking.PopulateProperties(&sstable.Properties{
163-
CommonProperties: sstable.CommonProperties{
164-
NumDeletions: 1, // At least one range del responsible for the deletion bytes.
165-
},
163+
NumDeletions: 1, // At least one range del responsible for the deletion bytes.
166164
})
167165
m.PopulateStats(&manifest.TableStats{
168166
RangeDeletionsBytesEstimate: uint64(v),

compaction_test.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,12 +3424,10 @@ func TestTombstoneDensityCompactionMoveOptimization(t *testing.T) {
34243424
}
34253425
meta.InitPhysicalBacking()
34263426
meta.TableBacking.PopulateProperties(&sstable.Properties{
3427-
CommonProperties: sstable.CommonProperties{
3428-
NumEntries: 10,
3429-
NumDeletions: 8,
3430-
NumDataBlocks: 100,
3431-
NumTombstoneDenseBlocks: 90, // Above threshold
3432-
},
3427+
NumEntries: 10,
3428+
NumDeletions: 8,
3429+
NumDataBlocks: 100,
3430+
NumTombstoneDenseBlocks: 90, // Above threshold
34333431
})
34343432
meta.PopulateStats(&manifest.TableStats{})
34353433
meta.ExtendPointKeyBounds(opts.Comparer.Compare,
@@ -3526,13 +3524,11 @@ func TestTombstoneDensityCompactionMoveOptimization_NoMoveWithOverlap(t *testing
35263524
}
35273525
metaL4.InitPhysicalBacking()
35283526
metaL4.TableBacking.PopulateProperties(&sstable.Properties{
3529-
CommonProperties: sstable.CommonProperties{
3530-
NumEntries: 10,
3531-
NumDeletions: 8,
3527+
NumEntries: 10,
3528+
NumDeletions: 8,
35323529

3533-
NumDataBlocks: 100,
3534-
NumTombstoneDenseBlocks: 90, // Above threshold
3535-
},
3530+
NumDataBlocks: 100,
3531+
NumTombstoneDenseBlocks: 90, // Above threshold
35363532
})
35373533
metaL4.PopulateStats(&manifest.TableStats{})
35383534
metaL4.ExtendPointKeyBounds(opts.Comparer.Compare,
@@ -3610,13 +3606,11 @@ func TestTombstoneDensityCompactionMoveOptimization_GrandparentOverlapTooLarge(t
36103606
}
36113607
metaL4.InitPhysicalBacking()
36123608
metaL4.TableBacking.PopulateProperties(&sstable.Properties{
3613-
CommonProperties: sstable.CommonProperties{
3614-
NumEntries: 10,
3615-
NumDeletions: 8,
3609+
NumEntries: 10,
3610+
NumDeletions: 8,
36163611

3617-
NumDataBlocks: 100,
3618-
NumTombstoneDenseBlocks: 90,
3619-
},
3612+
NumDataBlocks: 100,
3613+
NumTombstoneDenseBlocks: 90,
36203614
})
36213615
metaL4.PopulateStats(&manifest.TableStats{})
36223616
metaL4.ExtendPointKeyBounds(opts.Comparer.Compare,
@@ -3677,13 +3671,11 @@ func TestTombstoneDensityCompactionMoveOptimization_BelowDensityThreshold(t *tes
36773671
}
36783672
meta.InitPhysicalBacking()
36793673
meta.TableBacking.PopulateProperties(&sstable.Properties{
3680-
CommonProperties: sstable.CommonProperties{
3681-
NumEntries: 10,
3682-
NumDeletions: 5,
3674+
NumEntries: 10,
3675+
NumDeletions: 5,
36833676

3684-
NumDataBlocks: 100,
3685-
NumTombstoneDenseBlocks: 50, // Below threshold
3686-
},
3677+
NumDataBlocks: 100,
3678+
NumTombstoneDenseBlocks: 50, // Below threshold
36873679
})
36883680
meta.PopulateStats(&manifest.TableStats{})
36893681
meta.ExtendPointKeyBounds(opts.Comparer.Compare,

ingest_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,9 @@ func TestIngestLoadRand(t *testing.T) {
234234
expected[i].Size = meta.Size
235235
expected[i].InitPhysicalBacking()
236236
expected[i].TableBacking.PopulateProperties(&sstable.Properties{
237-
CommonProperties: sstable.CommonProperties{
238-
RawKeySize: rawKeySize,
239-
NumEntries: count,
240-
NumDataBlocks: 1,
241-
},
237+
RawKeySize: rawKeySize,
238+
NumEntries: count,
239+
NumDataBlocks: 1,
242240
})
243241
}()
244242
}

sstable/internal/genprops/gen_props.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ func main() {
198198
continue
199199
}
200200
qname := pkg.Types.Path() + "." + ts.Name.Name
201-
if qname != "github.com/cockroachdb/pebble/sstable.Properties" &&
202-
qname != "github.com/cockroachdb/pebble/sstable.CommonProperties" {
201+
if qname != "github.com/cockroachdb/pebble/sstable.Properties" {
203202
continue
204203
}
205204
for _, f := range st.Fields.List {

sstable/properties.go

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"slices"
1212
"unsafe"
1313

14-
"github.com/cockroachdb/pebble/internal/invariants"
1514
"github.com/cockroachdb/pebble/sstable/colblk"
1615
"github.com/cockroachdb/pebble/sstable/rowblk"
1716
)
@@ -20,14 +19,10 @@ import (
2019

2120
const propertiesBlockRestartInterval = math.MaxInt32
2221

23-
// CommonProperties holds properties for either a virtual or a physical sstable. This
24-
// can be used by code which doesn't care to make the distinction between physical
25-
// and virtual sstables properties.
26-
//
27-
// NB: The values of these properties can affect correctness. For example,
28-
// if NumRangeKeySets == 0, but the sstable actually contains range keys, then
29-
// the iterators will behave incorrectly.
30-
type CommonProperties struct {
22+
// Properties holds the sstable property values. The properties are
23+
// automatically populated during sstable creation and load from the properties
24+
// meta block when an sstable is opened.
25+
type Properties struct {
3126
// The number of entries in this table.
3227
NumEntries uint64 `prop:"rocksdb.num.entries" options:"encodeempty"`
3328
// Total raw key size.
@@ -71,30 +66,6 @@ type CommonProperties struct {
7166
// This statistic is used to determine eligibility for a tombstone density
7267
// compaction.
7368
NumTombstoneDenseBlocks uint64 `prop:"pebble.num.tombstone-dense-blocks"`
74-
}
75-
76-
// String is only used for testing purposes.
77-
func (c *CommonProperties) String() string {
78-
p := Properties{
79-
CommonProperties: *c,
80-
}
81-
return p.String()
82-
}
83-
84-
// NumPointDeletions is the number of point deletions in the sstable. For virtual
85-
// sstables, this is an estimate.
86-
func (c *CommonProperties) NumPointDeletions() uint64 {
87-
return invariants.SafeSub(c.NumDeletions, c.NumRangeDeletions)
88-
}
89-
90-
// Properties holds the sstable property values. The properties are
91-
// automatically populated during sstable creation and load from the properties
92-
// meta block when an sstable is opened.
93-
type Properties struct {
94-
// CommonProperties needs to be at the top of the Properties struct so that the
95-
// offsets of the fields in CommonProperties match the offsets of the embedded
96-
// fields of CommonProperties in Properties.
97-
CommonProperties `prop:"pebble.embbeded_common_properties"`
9869

9970
// The name of the comparer used in this table.
10071
ComparerName string `prop:"rocksdb.comparator" options:"encodeempty,intern"`

sstable/properties_test.go

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ import (
2525
func TestPropertiesLoad(t *testing.T) {
2626
defer leaktest.AfterTest(t)()
2727
expected := Properties{
28-
CommonProperties: CommonProperties{
29-
NumEntries: 1727,
30-
NumDeletions: 17,
31-
NumRangeDeletions: 17,
32-
RawKeySize: 23938,
33-
RawValueSize: 1912,
34-
NumDataBlocks: 14,
35-
},
28+
NumEntries: 1727,
29+
NumDeletions: 17,
30+
NumRangeDeletions: 17,
31+
RawKeySize: 23938,
32+
RawValueSize: 1912,
33+
NumDataBlocks: 14,
3634
ComparerName: "leveldb.BytewiseComparator",
3735
DataSize: 13913,
3836
IndexSize: 325,
@@ -63,35 +61,33 @@ func TestPropertiesLoad(t *testing.T) {
6361
}
6462

6563
var testProps = Properties{
66-
CommonProperties: CommonProperties{
67-
NumDeletions: 15,
68-
NumEntries: 16,
69-
NumRangeDeletions: 18,
70-
NumRangeKeyDels: 19,
71-
NumRangeKeySets: 20,
72-
RawKeySize: 25,
73-
RawValueSize: 26,
74-
NumDataBlocks: 14,
75-
NumTombstoneDenseBlocks: 2,
76-
},
77-
ComparerName: "comparator name",
78-
DataSize: 3,
79-
FilterPolicyName: "filter policy name",
80-
FilterSize: 5,
81-
IndexPartitions: 10,
82-
IndexSize: 11,
83-
IndexType: 12,
84-
IsStrictObsolete: true,
85-
KeySchemaName: "key schema name",
86-
MergerName: "merge operator name",
87-
NumMergeOperands: 17,
88-
NumRangeKeyUnsets: 21,
89-
NumValueBlocks: 22,
90-
NumValuesInValueBlocks: 23,
91-
PropertyCollectorNames: "prefix collector names",
92-
TopLevelIndexSize: 27,
93-
CompressionName: "compression name",
94-
CompressionStats: "Snappy:1024/2048",
64+
NumDeletions: 15,
65+
NumEntries: 16,
66+
NumRangeDeletions: 18,
67+
NumRangeKeyDels: 19,
68+
NumRangeKeySets: 20,
69+
RawKeySize: 25,
70+
RawValueSize: 26,
71+
NumDataBlocks: 14,
72+
NumTombstoneDenseBlocks: 2,
73+
ComparerName: "comparator name",
74+
DataSize: 3,
75+
FilterPolicyName: "filter policy name",
76+
FilterSize: 5,
77+
IndexPartitions: 10,
78+
IndexSize: 11,
79+
IndexType: 12,
80+
IsStrictObsolete: true,
81+
KeySchemaName: "key schema name",
82+
MergerName: "merge operator name",
83+
NumMergeOperands: 17,
84+
NumRangeKeyUnsets: 21,
85+
NumValueBlocks: 22,
86+
NumValuesInValueBlocks: 23,
87+
PropertyCollectorNames: "prefix collector names",
88+
TopLevelIndexSize: 27,
89+
CompressionName: "compression name",
90+
CompressionStats: "Snappy:1024/2048",
9591
UserProperties: map[string]string{
9692
"user-prop-a": "1",
9793
"user-prop-b": "2",

table_stats.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ func maybeSetStatsFromProperties(
729729
// doesn't require any additional IO and since the number of point
730730
// deletions in the file is low, the error introduced by this crude
731731
// estimate is expected to be small.
732-
avgValSize, compressionRatio := estimatePhysicalSizes(meta, &props.CommonProperties)
732+
avgValSize, compressionRatio := estimatePhysicalSizes(meta, props)
733733
pointEstimate = pointDeletionsBytesEstimate(backingProps, avgValSize, compressionRatio)
734734
}
735735

@@ -833,7 +833,7 @@ func pointDeletionsBytesEstimate(
833833
}
834834

835835
func estimatePhysicalSizes(
836-
tableMeta *manifest.TableMetadata, props *sstable.CommonProperties,
836+
tableMeta *manifest.TableMetadata, props *sstable.Properties,
837837
) (avgValLogicalSize, compressionRatio float64) {
838838
// RawKeySize and RawValueSize are uncompressed totals. Scale according to
839839
// the data size to account for compression, index blocks and metadata

0 commit comments

Comments
 (0)