Skip to content

Commit 6195a2c

Browse files
committed
*: allow compression type to be inferred from initial stats load
Currently, the compression type for a table is known when the SST is new \- i.e. flushed, compacted, ingested. However, when opening an existing DB, the compression types will show as "unknown". Allow the async, background stats loading job that runs on DB open to infer the compression type of existing tables by lifting the compression field from `sstable.Properties` up into `sstable.CommonProperties`. This allows `loadTableStats` to use the field and populate the `manifest.TableStats` struct.
1 parent 30d2cf6 commit 6195a2c

File tree

7 files changed

+43
-30
lines changed

7 files changed

+43
-30
lines changed

metrics_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ func TestMetrics(t *testing.T) {
163163
if createOnSharedLower {
164164
require.NoError(t, d.SetCreatorID(1))
165165
}
166+
if reopen {
167+
// Stats population is eventually consistent, and happens in the
168+
// background when a DB is re-opened. To avoid races, wait synchronously
169+
// for all tables to have their stats fully populated, which requires
170+
// opening each SST.
171+
d.mu.Lock()
172+
for !d.mu.tableStats.loadedInitial {
173+
d.mu.tableStats.cond.Wait()
174+
}
175+
d.mu.Unlock()
176+
}
166177
iters = make(map[string]*Iterator)
167178
closeFunc = func() {
168179
for _, i := range iters {

sstable/properties.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ type CommonProperties struct {
9999
NumRangeKeySets uint64 `prop:"pebble.num.range-key-sets"`
100100
// Total size of value blocks and value index block. Only serialized if > 0.
101101
ValueBlocksSize uint64 `prop:"pebble.value-blocks.size"`
102+
// The compression algorithm used to compress blocks.
103+
CompressionName string `prop:"rocksdb.compression"`
104+
// The compression options used to compress blocks.
105+
CompressionOptions string `prop:"rocksdb.compression_options"`
102106
}
103107

104108
// String is only used for testing purposes.
@@ -127,10 +131,6 @@ type Properties struct {
127131

128132
// The name of the comparer used in this table.
129133
ComparerName string `prop:"rocksdb.comparator"`
130-
// The compression algorithm used to compress blocks.
131-
CompressionName string `prop:"rocksdb.compression"`
132-
// The compression options used to compress blocks.
133-
CompressionOptions string `prop:"rocksdb.compression_options"`
134134
// The total size of all data blocks.
135135
DataSize uint64 `prop:"rocksdb.data.size"`
136136
// The name of the filter policy used in this table. Empty if no filter

sstable/properties_test.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import (
2121
func TestPropertiesLoad(t *testing.T) {
2222
expected := Properties{
2323
CommonProperties: CommonProperties{
24-
NumEntries: 1727,
25-
NumDeletions: 17,
26-
NumRangeDeletions: 17,
27-
RawKeySize: 23938,
28-
RawValueSize: 1912,
24+
NumEntries: 1727,
25+
NumDeletions: 17,
26+
NumRangeDeletions: 17,
27+
RawKeySize: 23938,
28+
RawValueSize: 1912,
29+
CompressionName: "Snappy",
30+
CompressionOptions: "window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0; ",
2931
},
3032
ComparerName: "leveldb.BytewiseComparator",
31-
CompressionName: "Snappy",
32-
CompressionOptions: "window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0; ",
3333
DataSize: 13913,
3434
IndexSize: 325,
3535
MergerName: "nullptr",
@@ -57,17 +57,17 @@ func TestPropertiesLoad(t *testing.T) {
5757

5858
var testProps = Properties{
5959
CommonProperties: CommonProperties{
60-
NumDeletions: 15,
61-
NumEntries: 16,
62-
NumRangeDeletions: 18,
63-
NumRangeKeyDels: 19,
64-
NumRangeKeySets: 20,
65-
RawKeySize: 25,
66-
RawValueSize: 26,
60+
NumDeletions: 15,
61+
NumEntries: 16,
62+
NumRangeDeletions: 18,
63+
NumRangeKeyDels: 19,
64+
NumRangeKeySets: 20,
65+
RawKeySize: 25,
66+
RawValueSize: 26,
67+
CompressionName: "compression name",
68+
CompressionOptions: "compression option",
6769
},
6870
ComparerName: "comparator name",
69-
CompressionName: "compression name",
70-
CompressionOptions: "compression option",
7171
DataSize: 3,
7272
FilterPolicyName: "filter policy name",
7373
FilterSize: 5,
@@ -93,16 +93,16 @@ func TestPropertiesSave(t *testing.T) {
9393
expected := &Properties{}
9494
*expected = testProps
9595

96-
check1 := func(expected *Properties) {
96+
check1 := func(e *Properties) {
9797
// Check that we can save properties and read them back.
9898
var w rawBlockWriter
9999
w.restartInterval = propertiesBlockRestartInterval
100-
expected.save(TableFormatPebblev2, &w)
100+
e.save(TableFormatPebblev2, &w)
101101
var props Properties
102102

103103
require.NoError(t, props.load(w.finish(), 0, make(map[string]struct{})))
104104
props.Loaded = nil
105-
if diff := pretty.Diff(*expected, props); diff != nil {
105+
if diff := pretty.Diff(*e, props); diff != nil {
106106
t.Fatalf("%s", strings.Join(diff, "\n"))
107107
}
108108
}
@@ -116,6 +116,7 @@ func TestPropertiesSave(t *testing.T) {
116116
if props.IndexPartitions == 0 {
117117
props.TopLevelIndexSize = 0
118118
}
119+
props.Loaded = nil
119120
check1(&props)
120121
}
121122
}

table_stats.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func (d *DB) loadTableStats(
323323
// picking.
324324
stats.NumRangeKeySets = props.NumRangeKeySets
325325
stats.ValueBlocksSize = props.ValueBlocksSize
326+
stats.CompressionType = sstable.CompressionFromString(props.CompressionName)
326327
return
327328
})
328329
if err != nil {

testdata/metrics

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ Zombie tables: 0 (0B, local: 0B)
820820
Backing tables: 0 (0B)
821821
Virtual tables: 0 (0B)
822822
Local tables size: 0B
823-
Compression types: unknown: 1
823+
Compression types: snappy: 1
824824
Block cache: 1 entries (440B) hit rate: 0.0%
825825
Table cache: 1 entries (760B) hit rate: 0.0%
826826
Secondary cache: 0 entries (0B) hit rate: 0.0%
@@ -867,7 +867,7 @@ Zombie tables: 0 (0B, local: 0B)
867867
Backing tables: 0 (0B)
868868
Virtual tables: 0 (0B)
869869
Local tables size: 0B
870-
Compression types: snappy: 1 unknown: 1
870+
Compression types: snappy: 2
871871
Block cache: 6 entries (996B) hit rate: 0.0%
872872
Table cache: 1 entries (760B) hit rate: 50.0%
873873
Secondary cache: 0 entries (0B) hit rate: 0.0%
@@ -915,7 +915,7 @@ Zombie tables: 0 (0B, local: 0B)
915915
Backing tables: 0 (0B)
916916
Virtual tables: 0 (0B)
917917
Local tables size: 589B
918-
Compression types: snappy: 2 unknown: 1
918+
Compression types: snappy: 3
919919
Block cache: 6 entries (996B) hit rate: 0.0%
920920
Table cache: 1 entries (760B) hit rate: 50.0%
921921
Secondary cache: 0 entries (0B) hit rate: 0.0%
@@ -954,7 +954,7 @@ Zombie tables: 0 (0B, local: 0B)
954954
Backing tables: 0 (0B)
955955
Virtual tables: 0 (0B)
956956
Local tables size: 589B
957-
Compression types: unknown: 3
957+
Compression types: snappy: 3
958958
Block cache: 0 entries (0B) hit rate: 0.0%
959959
Table cache: 0 entries (0B) hit rate: 0.0%
960960
Secondary cache: 0 entries (0B) hit rate: 0.0%

testdata/table_stats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,9 @@ rocksdb:
602602
rocksdb.raw.value.size: 2
603603
rocksdb.deleted.keys: 1
604604
rocksdb.num.range-deletions: 0
605-
rocksdb.comparator: pebble.internal.testkeys
606605
rocksdb.compression: Snappy
607606
rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;
607+
rocksdb.comparator: pebble.internal.testkeys
608608
rocksdb.data.size: 53
609609
rocksdb.filter.size: 0
610610
rocksdb.index.size: 27
@@ -710,9 +710,9 @@ rocksdb:
710710
rocksdb.raw.value.size: 3
711711
rocksdb.deleted.keys: 0
712712
rocksdb.num.range-deletions: 0
713-
rocksdb.comparator: pebble.internal.testkeys
714713
rocksdb.compression: Snappy
715714
rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;
715+
rocksdb.comparator: pebble.internal.testkeys
716716
rocksdb.data.size: 47
717717
rocksdb.filter.size: 0
718718
rocksdb.index.size: 27
@@ -832,9 +832,9 @@ rocksdb:
832832
rocksdb.raw.value.size: 1
833833
rocksdb.deleted.keys: 1
834834
rocksdb.num.range-deletions: 1
835-
rocksdb.comparator: pebble.internal.testkeys
836835
rocksdb.compression: Snappy
837836
rocksdb.compression_options: window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;
837+
rocksdb.comparator: pebble.internal.testkeys
838838
rocksdb.data.size: 13
839839
rocksdb.filter.size: 0
840840
rocksdb.index.size: 29

tool/testdata/sstable_properties

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)