[#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:
parent
fa1dc31320
commit
cc377b34d2
4 changed files with 22 additions and 24 deletions
|
@ -385,7 +385,7 @@ func initShardOptions(c *cfg) {
|
|||
shard.WithRefillMetabase(sc.RefillMetabase()),
|
||||
shard.WithBlobStorOptions(
|
||||
blobstor.WithRootPath(blobStorCfg.Path()),
|
||||
blobstor.WithCompressObjects(blobStorCfg.Compress(), c.log),
|
||||
blobstor.WithCompressObjects(blobStorCfg.Compress()),
|
||||
blobstor.WithRootPerm(blobStorCfg.Perm()),
|
||||
blobstor.WithShallowDepth(blobStorCfg.ShallowDepth()),
|
||||
blobstor.WithSmallSizeLimit(blobStorCfg.SmallSizeLimit()),
|
||||
|
|
|
@ -781,6 +781,22 @@ func (b *blobovniczas) updateAndGet(p string, old *uint64) (blobovniczaWithIndex
|
|||
func (b *blobovniczas) init() error {
|
||||
b.log.Debug("initializing Blobovnicza's")
|
||||
|
||||
if b.compressionEnabled {
|
||||
zstdC, err := zstdCompressor()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create zstd compressor: %v", err)
|
||||
}
|
||||
zstdD, err := zstdDecompressor()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create zstd decompressor: %v", err)
|
||||
}
|
||||
b.compressor = zstdC
|
||||
b.decompressor = zstdD
|
||||
} else {
|
||||
b.compressor = noOpCompressor
|
||||
b.decompressor = noOpDecompressor
|
||||
}
|
||||
|
||||
return b.iterateBlobovniczas(func(p string, blz *blobovnicza.Blobovnicza) error {
|
||||
if err := blz.Init(); err != nil {
|
||||
return fmt.Errorf("could not initialize blobovnicza structure %s: %w", p, err)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -19,7 +18,7 @@ func TestIterateObjects(t *testing.T) {
|
|||
|
||||
// create BlobStor instance
|
||||
blobStor := New(
|
||||
WithCompressObjects(true, test.NewLogger(false)),
|
||||
WithCompressObjects(true),
|
||||
WithRootPath(p),
|
||||
WithSmallSizeLimit(smalSz),
|
||||
WithBlobovniczaShallowWidth(1),
|
||||
|
|
Loading…
Reference in a new issue