Skip to content

Commit 750fe8c

Browse files
committed
compression: improve compression stats string
Improve the compression stats string to be shorter and more readable: - `None` instead of `NoCompression`; - remove redundant second number for `None`; - order algorithms according to the definition. We also rename some of the compression constants. We still support the previous format. The previous format is written out by v25.3, but is never read back/parsed by that version.
1 parent 335af5d commit 750fe8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+860
-826
lines changed

internal/compression/adaptive_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestAdaptiveCompressorCompressible(t *testing.T) {
3737
// Test the adaptive compressor with compressible data and make sure it uses
3838
// the slow algorithm.
3939
ac := NewAdaptiveCompressor(AdaptiveCompressorParams{
40-
Fast: None,
40+
Fast: NoCompression,
4141
Slow: ZstdLevel1,
4242
ReductionCutoff: 0.6,
4343
SampleEvery: 10,

internal/compression/compression.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
type Algorithm uint8
2020

2121
const (
22-
NoCompression Algorithm = iota
23-
SnappyAlgorithm
24-
Zstd
22+
NoAlgorithm Algorithm = iota
23+
Snappy
2524
MinLZ
25+
Zstd
2626

2727
NumAlgorithms
2828

@@ -33,9 +33,9 @@ const (
3333
// compression algorithm.
3434
func (a Algorithm) String() string {
3535
switch a {
36-
case NoCompression:
37-
return "NoCompression"
38-
case SnappyAlgorithm:
36+
case NoAlgorithm:
37+
return "None"
38+
case Snappy:
3939
return "Snappy"
4040
case Zstd:
4141
return "ZSTD"
@@ -86,8 +86,8 @@ func ParseSetting(s string) (_ Setting, ok bool) {
8686

8787
// Setting presets.
8888
var (
89-
None = makePreset(NoCompression, 0)
90-
Snappy = makePreset(SnappyAlgorithm, 0)
89+
NoCompression = makePreset(NoAlgorithm, 0)
90+
SnappySetting = makePreset(Snappy, 0)
9191
MinLZFastest = makePreset(MinLZ, minlz.LevelFastest)
9292
MinLZBalanced = makePreset(MinLZ, minlz.LevelBalanced)
9393
ZstdLevel1 = makePreset(Zstd, 1)
@@ -110,9 +110,9 @@ type Compressor interface {
110110

111111
func GetCompressor(s Setting) Compressor {
112112
switch s.Algorithm {
113-
case NoCompression:
113+
case NoAlgorithm:
114114
return noopCompressor{}
115-
case SnappyAlgorithm:
115+
case Snappy:
116116
return snappyCompressor{}
117117
case Zstd:
118118
return getZstdCompressor(int(s.Level))
@@ -143,9 +143,9 @@ type Decompressor interface {
143143

144144
func GetDecompressor(a Algorithm) Decompressor {
145145
switch a {
146-
case NoCompression:
146+
case NoAlgorithm:
147147
return noopDecompressor{}
148-
case SnappyAlgorithm:
148+
case Snappy:
149149
return snappyDecompressor{}
150150
case Zstd:
151151
return getZstdDecompressor()

internal/compression/noop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type noopCompressor struct{}
99
var _ Compressor = noopCompressor{}
1010

1111
func (noopCompressor) Compress(dst, src []byte) ([]byte, Setting) {
12-
return append(dst[:0], src...), None
12+
return append(dst[:0], src...), NoCompression
1313
}
1414
func (noopCompressor) Close() {}
1515

internal/compression/snappy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ type snappyCompressor struct{}
1414

1515
var _ Compressor = snappyCompressor{}
1616

17-
func (snappyCompressor) Algorithm() Algorithm { return SnappyAlgorithm }
17+
func (snappyCompressor) Algorithm() Algorithm { return Snappy }
1818

1919
func (snappyCompressor) Compress(dst, src []byte) ([]byte, Setting) {
2020
dst = dst[:cap(dst):cap(dst)]
21-
return snappy.Encode(dst, src), Snappy
21+
return snappy.Encode(dst, src), SnappySetting
2222
}
2323

2424
func (snappyCompressor) Close() {}

metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,9 @@ type CompressionStatsForSetting = block.CompressionStatsForSetting
509509
func (cm *CompressionMetrics) Add(stats *block.CompressionStats) {
510510
for s, cs := range stats.All() {
511511
switch s.Algorithm {
512-
case compression.NoCompression:
512+
case compression.NoAlgorithm:
513513
cm.NoCompressionBytes += cs.UncompressedBytes
514-
case compression.SnappyAlgorithm:
514+
case compression.Snappy:
515515
cm.Snappy.Add(cs)
516516
case compression.MinLZ:
517517
cm.MinLZ.Add(cs)

replay/testdata/corpus/simple_ingest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ simple_ingest/MANIFEST-000008:
101101
size: 209
102102
simple_ingest/MANIFEST-000010: stat simple_ingest/MANIFEST-000010: file does not exist
103103
simple_ingest/000007.sst:
104-
size: 770
105-
simple_ingest/000009.sst:
106104
size: 765
105+
simple_ingest/000009.sst:
106+
size: 759

replay/testdata/corpus/simple_val_sep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ stat simple_val_sep/MANIFEST-000013 simple_val_sep/000015.sst simple_val_sep/000
103103
simple_val_sep/MANIFEST-000013:
104104
size: 250
105105
simple_val_sep/000015.sst:
106-
size: 878
106+
size: 873
107107
simple_val_sep/000016.blob:
108108
size: 97

replay/testdata/replay_ingest

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ tree
66
/
77
build/
88
36 000002.log
9-
770 000005.sst
10-
770 000007.sst
11-
765 000009.sst
9+
765 000005.sst
10+
765 000007.sst
11+
759 000009.sst
1212
0 LOCK
1313
172 MANIFEST-000001
1414
209 MANIFEST-000008
1515
2800 OPTIONS-000003
1616
0 marker.format-version.000012.025
1717
0 marker.manifest.000002.MANIFEST-000008
1818
simple_ingest/
19-
770 000007.sst
20-
765 000009.sst
19+
765 000007.sst
20+
759 000009.sst
2121
172 MANIFEST-000001
2222
209 MANIFEST-000008
2323
checkpoint/
2424
25 000002.log
25-
787 000004.sst
26-
770 000005.sst
25+
782 000004.sst
26+
765 000005.sst
2727
172 MANIFEST-000001
2828
2800 OPTIONS-000003
2929
0 marker.format-version.000001.025

replay/testdata/replay_val_sep

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ tree
55
----
66
/
77
build/
8-
906 000005.sst
8+
900 000005.sst
99
101 000006.blob
10-
884 000008.sst
10+
879 000008.sst
1111
97 000009.blob
1212
92 000011.log
13-
769 000012.sst
13+
764 000012.sst
1414
63 000014.log
15-
878 000015.sst
15+
873 000015.sst
1616
97 000016.blob
1717
0 LOCK
1818
152 MANIFEST-000010
@@ -21,16 +21,16 @@ tree
2121
0 marker.format-version.000011.024
2222
0 marker.manifest.000003.MANIFEST-000013
2323
simple_val_sep/
24-
878 000015.sst
24+
873 000015.sst
2525
97 000016.blob
2626
250 MANIFEST-000013
2727
checkpoint/
28-
906 000005.sst
28+
900 000005.sst
2929
101 000006.blob
30-
884 000008.sst
30+
879 000008.sst
3131
97 000009.blob
3232
64 000011.log
33-
769 000012.sst
33+
764 000012.sst
3434
187 MANIFEST-000013
3535
2936 OPTIONS-000003
3636
0 marker.format-version.000001.024

sstable/block/compression.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ func (p *CompressionProfile) UsesMinLZ() bool {
5555
}
5656

5757
var (
58-
NoCompression = simpleCompressionProfile("NoCompression", compression.None)
59-
SnappyCompression = simpleCompressionProfile("Snappy", compression.Snappy)
58+
NoCompression = simpleCompressionProfile("NoCompression", compression.NoCompression)
59+
SnappyCompression = simpleCompressionProfile("Snappy", compression.SnappySetting)
6060
ZstdCompression = simpleCompressionProfile("ZSTD", compression.ZstdLevel3)
6161
MinLZCompression = simpleCompressionProfile("MinLZ", compression.MinLZFastest)
6262

@@ -95,7 +95,7 @@ var fastestCompression = func() compression.Setting {
9595
if runtime.GOARCH == "arm64" {
9696
// MinLZ is generally faster and better than Snappy except for arm64: Snappy
9797
// has an arm64 assembly implementation and MinLZ does not.
98-
return compression.Snappy
98+
return compression.SnappySetting
9999
}
100100
return compression.MinLZFastest
101101
}()
@@ -190,9 +190,9 @@ func (i CompressionIndicator) String() string {
190190
func (i CompressionIndicator) Algorithm() compression.Algorithm {
191191
switch i {
192192
case NoCompressionIndicator:
193-
return compression.NoCompression
193+
return compression.NoAlgorithm
194194
case SnappyCompressionIndicator:
195-
return compression.SnappyAlgorithm
195+
return compression.Snappy
196196
case ZstdCompressionIndicator:
197197
return compression.Zstd
198198
case MinLZCompressionIndicator:
@@ -204,9 +204,9 @@ func (i CompressionIndicator) Algorithm() compression.Algorithm {
204204

205205
func compressionIndicatorFromAlgorithm(algo compression.Algorithm) CompressionIndicator {
206206
switch algo {
207-
case compression.NoCompression:
207+
case compression.NoAlgorithm:
208208
return NoCompressionIndicator
209-
case compression.SnappyAlgorithm:
209+
case compression.Snappy:
210210
return SnappyCompressionIndicator
211211
case compression.Zstd:
212212
return ZstdCompressionIndicator

0 commit comments

Comments
 (0)