Skip to content

Commit a4a4349

Browse files
committed
db: move compression profile reexports to sstable
Profiles apply to individual sstables, not an entire database. We will introduce db-wide compression settings; the existing CompressionProfile aliases in pebble will lead to confusion. This commit moves the aliases to sstable.
1 parent e1f48f9 commit a4a4349

File tree

8 files changed

+33
-32
lines changed

8 files changed

+33
-32
lines changed

checkpoint_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/cockroachdb/datadriven"
2020
"github.com/cockroachdb/pebble/internal/base"
2121
"github.com/cockroachdb/pebble/objstorage/remote"
22+
"github.com/cockroachdb/pebble/sstable"
2223
"github.com/cockroachdb/pebble/vfs"
2324
"github.com/stretchr/testify/require"
2425
)
@@ -434,7 +435,7 @@ func TestCheckpointManyFiles(t *testing.T) {
434435
// Disable compression to speed up the test.
435436
opts.EnsureDefaults()
436437
for i := range opts.Levels {
437-
opts.Levels[i].Compression = func() *CompressionProfile { return NoCompression }
438+
opts.Levels[i].Compression = func() *sstable.CompressionProfile { return sstable.NoCompression }
438439
}
439440

440441
d, err := Open("", opts)

ingest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2957,7 +2957,7 @@ func TestIngestValidation(t *testing.T) {
29572957
w := sstable.NewWriter(objstorageprovider.NewFileWritable(f), sstable.WriterOptions{
29582958
BlockSize: blockSize, // Create many smaller blocks.
29592959
Comparer: opts.Comparer,
2960-
Compression: NoCompression, // For simpler debugging.
2960+
Compression: sstable.NoCompression, // For simpler debugging.
29612961
KeySchema: opts.KeySchemas[opts.KeySchema],
29622962
})
29632963
for _, kv := range keyVals {

level_iter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ func buildLevelIterTables(
530530
writers[i] = sstable.NewRawWriter(objstorageprovider.NewFileWritable(files[i]), sstable.WriterOptions{
531531
BlockRestartInterval: restartInterval,
532532
BlockSize: blockSize,
533-
Compression: NoCompression,
533+
Compression: sstable.NoCompression,
534534
})
535535
}
536536

merging_iter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func buildMergingIterTables(
350350
writers[i] = sstable.NewRawWriter(objstorageprovider.NewFileWritable(files[i]), sstable.WriterOptions{
351351
BlockRestartInterval: restartInterval,
352352
BlockSize: blockSize,
353-
Compression: NoCompression,
353+
Compression: sstable.NoCompression,
354354
})
355355
}
356356

@@ -567,7 +567,7 @@ func buildLevelsForMergingIterSeqSeek(
567567
writerOptions := sstable.WriterOptions{
568568
BlockRestartInterval: restartInterval,
569569
BlockSize: blockSize,
570-
Compression: NoCompression,
570+
Compression: sstable.NoCompression,
571571
}
572572
if writeBloomFilters {
573573
writerOptions.FilterPolicy = filterPolicy

metamorphic/options.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,13 +801,13 @@ func RandomOptions(
801801

802802
switch rng.IntN(4) {
803803
case 0:
804-
lopts.Compression = func() *block.CompressionProfile { return pebble.NoCompression }
804+
lopts.Compression = func() *block.CompressionProfile { return sstable.NoCompression }
805805
case 1:
806-
lopts.Compression = func() *block.CompressionProfile { return pebble.ZstdCompression }
806+
lopts.Compression = func() *block.CompressionProfile { return sstable.ZstdCompression }
807807
case 2:
808-
lopts.Compression = func() *block.CompressionProfile { return pebble.SnappyCompression }
808+
lopts.Compression = func() *block.CompressionProfile { return sstable.SnappyCompression }
809809
default:
810-
lopts.Compression = func() *block.CompressionProfile { return pebble.MinLZCompression }
810+
lopts.Compression = func() *block.CompressionProfile { return sstable.MinLZCompression }
811811
}
812812
opts.Levels[0] = lopts
813813

options.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,6 @@ const (
4141
defaultLevelMultiplier = 10
4242
)
4343

44-
type CompressionProfile = block.CompressionProfile
45-
46-
// Exported Compression constants.
47-
var (
48-
DefaultCompression = block.DefaultCompression
49-
NoCompression = block.NoCompression
50-
SnappyCompression = block.SnappyCompression
51-
ZstdCompression = block.ZstdCompression
52-
// MinLZCompression is only supported with table formats v6+. Older formats
53-
// fall back to snappy.
54-
MinLZCompression = block.MinLZCompression
55-
FastestCompression = block.FastestCompression
56-
)
57-
5844
// FilterType exports the base.FilterType type.
5945
type FilterType = base.FilterType
6046

@@ -419,7 +405,7 @@ type LevelOptions struct {
419405
//
420406
// The default value is Snappy for L0, or the function from the previous level
421407
// for all other levels.
422-
Compression func() *CompressionProfile
408+
Compression func() *sstable.CompressionProfile
423409

424410
// FilterPolicy defines a filter algorithm (such as a Bloom filter) that can
425411
// reduce disk reads for Get calls.
@@ -467,7 +453,7 @@ func (o *LevelOptions) EnsureL0Defaults() {
467453
o.BlockSizeThreshold = base.DefaultBlockSizeThreshold
468454
}
469455
if o.Compression == nil {
470-
o.Compression = func() *CompressionProfile { return SnappyCompression }
456+
o.Compression = func() *sstable.CompressionProfile { return sstable.SnappyCompression }
471457
}
472458
if o.FilterPolicy == nil {
473459
o.FilterPolicy = NoFilterPolicy
@@ -2115,7 +2101,7 @@ func (o *Options) Parse(s string, hooks *ParseHooks) error {
21152101
if profile == nil {
21162102
return errors.Errorf("pebble: unknown compression: %q", errors.Safe(value))
21172103
}
2118-
l.Compression = func() *CompressionProfile { return profile }
2104+
l.Compression = func() *sstable.CompressionProfile { return profile }
21192105
case "filter_policy":
21202106
if hooks != nil && hooks.NewFilterPolicy != nil {
21212107
l.FilterPolicy, err = hooks.NewFilterPolicy(value)

sstable/options.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ func (o ReaderOptions) ensureDefaults() ReaderOptions {
128128
var defaultKeySchema = colblk.DefaultKeySchema(base.DefaultComparer, 16)
129129
var defaultKeySchemas = MakeKeySchemas(&defaultKeySchema)
130130

131+
type CompressionProfile = block.CompressionProfile
132+
133+
// Exported CompressionProfile constants.
134+
var (
135+
DefaultCompression = block.DefaultCompression
136+
NoCompression = block.NoCompression
137+
SnappyCompression = block.SnappyCompression
138+
ZstdCompression = block.ZstdCompression
139+
// MinLZCompression is only supported with table formats v6+. Older formats
140+
// fall back to snappy.
141+
MinLZCompression = block.MinLZCompression
142+
FastestCompression = block.FastestCompression
143+
)
144+
131145
// WriterOptions holds the parameters used to control building an sstable.
132146
type WriterOptions struct {
133147
// BlockRestartInterval is the number of keys between restart points
@@ -166,7 +180,7 @@ type WriterOptions struct {
166180
// Compression defines the per-block compression to use.
167181
//
168182
// The default value uses snappy compression.
169-
Compression *block.CompressionProfile
183+
Compression *CompressionProfile
170184

171185
// FilterPolicy defines a filter algorithm (such as a Bloom filter) that can
172186
// reduce disk reads for Get calls.
@@ -353,7 +367,7 @@ func (o WriterOptions) ensureDefaults() WriterOptions {
353367
return o
354368
}
355369

356-
func tableFormatSupportsCompressionProfile(tf TableFormat, profile *block.CompressionProfile) bool {
370+
func tableFormatSupportsCompressionProfile(tf TableFormat, profile *CompressionProfile) bool {
357371
// MinLZ is only supported in TableFormatPebblev6 and higher.
358372
if tf < TableFormatPebblev6 && profile.UsesMinLZ() {
359373
return false

table_stats.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,13 +1131,13 @@ func (a compressionTypeAggregator) Accumulate(
11311131
f *manifest.TableMetadata, dst *compressionTypes,
11321132
) (v *compressionTypes, cacheOK bool) {
11331133
switch f.Stats.CompressionType {
1134-
case SnappyCompression:
1134+
case sstable.SnappyCompression:
11351135
dst.snappy++
1136-
case ZstdCompression:
1136+
case sstable.ZstdCompression:
11371137
dst.zstd++
1138-
case MinLZCompression:
1138+
case sstable.MinLZCompression:
11391139
dst.minlz++
1140-
case NoCompression:
1140+
case sstable.NoCompression:
11411141
dst.none++
11421142
default:
11431143
dst.unknown++

0 commit comments

Comments
 (0)