[#1715] blobstor: Allow to specify custom compression level
Change-Id: I140c39b9dceaaeb58767061b131777af22242b19 Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
2d1232ce6d
commit
98308d0cad
13 changed files with 74 additions and 4 deletions
|
@ -4,15 +4,26 @@ import (
|
|||
"bytes"
|
||||
"strings"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
|
||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
"github.com/klauspost/compress"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
)
|
||||
|
||||
type Level string
|
||||
|
||||
const (
|
||||
LevelDefault Level = ""
|
||||
LevelOptimal Level = "optimal"
|
||||
LevelFastest Level = "fastest"
|
||||
LevelSmallestSize Level = "smallest_size"
|
||||
)
|
||||
|
||||
// Config represents common compression-related configuration.
|
||||
type Config struct {
|
||||
Enabled bool
|
||||
UncompressableContentTypes []string
|
||||
Level Level
|
||||
|
||||
UseCompressEstimation bool
|
||||
CompressEstimationThreshold float64
|
||||
|
@ -30,7 +41,7 @@ func (c *Config) Init() error {
|
|||
var err error
|
||||
|
||||
if c.Enabled {
|
||||
c.encoder, err = zstd.NewWriter(nil)
|
||||
c.encoder, err = zstd.NewWriter(nil, zstd.WithEncoderLevel(c.compressionLevel()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -116,3 +127,24 @@ func (c *Config) Close() error {
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Config) HasValidCompressionLevel() bool {
|
||||
return c.Level == LevelDefault ||
|
||||
c.Level == LevelOptimal ||
|
||||
c.Level == LevelFastest ||
|
||||
c.Level == LevelSmallestSize
|
||||
}
|
||||
|
||||
func (c *Config) compressionLevel() zstd.EncoderLevel {
|
||||
switch c.Level {
|
||||
case LevelDefault, LevelOptimal:
|
||||
return zstd.SpeedDefault
|
||||
case LevelFastest:
|
||||
return zstd.SpeedFastest
|
||||
case LevelSmallestSize:
|
||||
return zstd.SpeedBestCompression
|
||||
default:
|
||||
assert.Fail("unknown compression level", string(c.Level))
|
||||
return zstd.SpeedDefault
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue