[#868] blobstor: initialize (de-)compressors in Init

Do not log in options constructors. Also failure to
initialize compression module (possibly due to invalid options) is
certainly an error deserving proper treatment.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-10-07 17:19:55 +03:00 committed by Leonard Lyubich
parent fa1dc31320
commit cc377b34d2
4 changed files with 22 additions and 24 deletions

View file

@ -26,6 +26,8 @@ type Option func(*cfg)
type cfg struct {
fsTree fstree.FSTree
compressionEnabled bool
compressor func([]byte) []byte
decompressor func([]byte) ([]byte, error)
@ -65,8 +67,6 @@ func defaultCfg() *cfg {
RootPath: "./",
},
},
compressor: noOpCompressor,
decompressor: noOpDecompressor,
smallSizeLimit: defaultSmallSizeLimit,
log: zap.L(),
openedCacheSize: defaultOpenedCacheSize,
@ -111,26 +111,9 @@ func WithShallowDepth(depth int) Option {
// If compressor (decompressor) creation failed,
// the uncompressed option will be used, and the error
// is recorded in the provided log.
func WithCompressObjects(comp bool, log *logger.Logger) Option {
func WithCompressObjects(comp bool) Option {
return func(c *cfg) {
if comp {
var err error
if c.compressor, err = zstdCompressor(); err != nil {
log.Error("could not create zstd compressor",
zap.String("error", err.Error()),
)
} else if c.decompressor, err = zstdDecompressor(); err != nil {
log.Error("could not create zstd decompressor",
zap.String("error", err.Error()),
)
} else {
return
}
}
c.compressor = noOpCompressor
c.decompressor = noOpDecompressor
c.compressionEnabled = comp
}
}