@@ -41,11 +41,10 @@ const (
41
41
defaultLevelMultiplier = 10
42
42
)
43
43
44
- // Compression exports the base.Compression type.
45
- type Compression = block.Compression
44
+ type CompressionProfile = block.CompressionProfile
46
45
47
46
// Exported Compression constants.
48
- const (
47
+ var (
49
48
DefaultCompression = block .DefaultCompression
50
49
NoCompression = block .NoCompression
51
50
SnappyCompression = block .SnappyCompression
@@ -417,9 +416,9 @@ type LevelOptions struct {
417
416
418
417
// Compression defines the per-block compression to use.
419
418
//
420
- // The default value is DefaultCompression (which uses Snappy) for L0, or the
421
- // function from the previous level for all other levels.
422
- Compression func () Compression
419
+ // The default value is Snappy for L0, or the function from the previous level
420
+ // for all other levels.
421
+ Compression func () * CompressionProfile
423
422
424
423
// FilterPolicy defines a filter algorithm (such as a Bloom filter) that can
425
424
// reduce disk reads for Get calls.
@@ -467,7 +466,7 @@ func (o *LevelOptions) EnsureL0Defaults() {
467
466
o .BlockSizeThreshold = base .DefaultBlockSizeThreshold
468
467
}
469
468
if o .Compression == nil {
470
- o .Compression = func () Compression { return DefaultCompression }
469
+ o .Compression = func () * CompressionProfile { return SnappyCompression }
471
470
}
472
471
if o .FilterPolicy == nil {
473
472
o .FilterPolicy = NoFilterPolicy
@@ -1614,7 +1613,7 @@ func (o *Options) String() string {
1614
1613
fmt .Fprintf (& buf , " block_restart_interval=%d\n " , l .BlockRestartInterval )
1615
1614
fmt .Fprintf (& buf , " block_size=%d\n " , l .BlockSize )
1616
1615
fmt .Fprintf (& buf , " block_size_threshold=%d\n " , l .BlockSizeThreshold )
1617
- fmt .Fprintf (& buf , " compression=%s\n " , resolveDefaultCompression ( l .Compression ()) )
1616
+ fmt .Fprintf (& buf , " compression=%s\n " , l .Compression (). Name )
1618
1617
fmt .Fprintf (& buf , " filter_policy=%s\n " , l .FilterPolicy .Name ())
1619
1618
fmt .Fprintf (& buf , " filter_type=%s\n " , l .FilterType )
1620
1619
fmt .Fprintf (& buf , " index_block_size=%d\n " , l .IndexBlockSize )
@@ -2084,20 +2083,11 @@ func (o *Options) Parse(s string, hooks *ParseHooks) error {
2084
2083
case "block_size_threshold" :
2085
2084
l .BlockSizeThreshold , err = strconv .Atoi (value )
2086
2085
case "compression" :
2087
- switch value {
2088
- case "Default" :
2089
- l .Compression = func () Compression { return DefaultCompression }
2090
- case "NoCompression" :
2091
- l .Compression = func () Compression { return NoCompression }
2092
- case "Snappy" :
2093
- l .Compression = func () Compression { return SnappyCompression }
2094
- case "ZSTD" :
2095
- l .Compression = func () Compression { return ZstdCompression }
2096
- case "MinLZ" :
2097
- l .Compression = func () Compression { return MinLZCompression }
2098
- default :
2086
+ profile := block .CompressionProfileByName (value )
2087
+ if profile == nil {
2099
2088
return errors .Errorf ("pebble: unknown compression: %q" , errors .Safe (value ))
2100
2089
}
2090
+ l .Compression = func () * CompressionProfile { return profile }
2101
2091
case "filter_policy" :
2102
2092
if hooks != nil && hooks .NewFilterPolicy != nil {
2103
2093
l .FilterPolicy , err = hooks .NewFilterPolicy (value )
@@ -2335,7 +2325,7 @@ func (o *Options) MakeWriterOptions(level int, format sstable.TableFormat) sstab
2335
2325
writerOpts .BlockRestartInterval = levelOpts .BlockRestartInterval
2336
2326
writerOpts .BlockSize = levelOpts .BlockSize
2337
2327
writerOpts .BlockSizeThreshold = levelOpts .BlockSizeThreshold
2338
- writerOpts .Compression = resolveDefaultCompression ( levelOpts .Compression () )
2328
+ writerOpts .Compression = levelOpts .Compression ()
2339
2329
writerOpts .FilterPolicy = levelOpts .FilterPolicy
2340
2330
writerOpts .FilterType = levelOpts .FilterType
2341
2331
writerOpts .IndexBlockSize = levelOpts .IndexBlockSize
@@ -2357,7 +2347,7 @@ func (o *Options) MakeWriterOptions(level int, format sstable.TableFormat) sstab
2357
2347
func (o * Options ) MakeBlobWriterOptions (level int ) blob.FileWriterOptions {
2358
2348
lo := o .Levels [level ]
2359
2349
return blob.FileWriterOptions {
2360
- Compression : resolveDefaultCompression ( lo .Compression () ),
2350
+ Compression : lo .Compression (),
2361
2351
ChecksumType : block .ChecksumTypeCRC32c ,
2362
2352
FlushGovernor : block .MakeFlushGovernor (
2363
2353
lo .BlockSize ,
@@ -2368,13 +2358,6 @@ func (o *Options) MakeBlobWriterOptions(level int) blob.FileWriterOptions {
2368
2358
}
2369
2359
}
2370
2360
2371
- func resolveDefaultCompression (c Compression ) Compression {
2372
- if c <= DefaultCompression || c >= block .NCompression {
2373
- c = SnappyCompression
2374
- }
2375
- return c
2376
- }
2377
-
2378
2361
func (o * Options ) MakeObjStorageProviderSettings (dirname string ) objstorageprovider.Settings {
2379
2362
s := objstorageprovider.Settings {
2380
2363
Logger : o .Logger ,
0 commit comments