forked from TrueCloudLab/frostfs-node
[#1523] blobstor: Rename compression.CConfig
to Config
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
0042c1d4a6
commit
e8c6dce466
12 changed files with 34 additions and 34 deletions
|
@ -48,11 +48,11 @@ import (
|
||||||
// B-s are intitialized and opened.
|
// B-s are intitialized and opened.
|
||||||
//
|
//
|
||||||
// Object is saved as follows:
|
// Object is saved as follows:
|
||||||
// 1. at each level, according to HRW, the next one is selected and
|
// 1. at each level, according to HRW, the next one is selected and
|
||||||
// dives into it until we reach the deepest;
|
// dives into it until we reach the deepest;
|
||||||
// 2. at the B-s level object is saved to the active B. If active B
|
// 2. at the B-s level object is saved to the active B. If active B
|
||||||
// is full, next B is opened, initialized and cached. If there
|
// is full, next B is opened, initialized and cached. If there
|
||||||
// is no more X candidates, goto 1 and process next level.
|
// is no more X candidates, goto 1 and process next level.
|
||||||
//
|
//
|
||||||
// After the object is saved in B, path concatenation is returned
|
// After the object is saved in B, path concatenation is returned
|
||||||
// in system path format as B identifier (ex. "0/1/1" or "3/2/1").
|
// in system path format as B identifier (ex. "0/1/1" or "3/2/1").
|
||||||
|
@ -228,6 +228,6 @@ func (b *Blobovniczas) Type() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCompressor implements common.Storage.
|
// SetCompressor implements common.Storage.
|
||||||
func (b *Blobovniczas) SetCompressor(cc *compression.CConfig) {
|
func (b *Blobovniczas) SetCompressor(cc *compression.Config) {
|
||||||
b.CConfig = cc
|
b.compression = cc
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ func (b *Blobovniczas) getObject(blz *blobovnicza.Blobovnicza, prm blobovnicza.G
|
||||||
}
|
}
|
||||||
|
|
||||||
// decompress the data
|
// decompress the data
|
||||||
data, err := b.Decompress(res.Object())
|
data, err := b.compression.Decompress(res.Object())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.GetRes{}, fmt.Errorf("could not decompress object data: %w", err)
|
return common.GetRes{}, fmt.Errorf("could not decompress object data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ func (b *Blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm common.G
|
||||||
}
|
}
|
||||||
|
|
||||||
// decompress the data
|
// decompress the data
|
||||||
data, err := b.Decompress(res.Object())
|
data, err := b.compression.Decompress(res.Object())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.GetRangeRes{}, fmt.Errorf("could not decompress object data: %w", err)
|
return common.GetRangeRes{}, fmt.Errorf("could not decompress object data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
func (b *Blobovniczas) Iterate(prm common.IteratePrm) (common.IterateRes, error) {
|
func (b *Blobovniczas) Iterate(prm common.IteratePrm) (common.IterateRes, error) {
|
||||||
return common.IterateRes{}, b.iterateBlobovniczas(prm.IgnoreErrors, func(p string, blz *blobovnicza.Blobovnicza) error {
|
return common.IterateRes{}, b.iterateBlobovniczas(prm.IgnoreErrors, func(p string, blz *blobovnicza.Blobovnicza) error {
|
||||||
return blobovnicza.IterateObjects(blz, func(addr oid.Address, data []byte) error {
|
return blobovnicza.IterateObjects(blz, func(addr oid.Address, data []byte) error {
|
||||||
data, err := b.Decompress(data)
|
data, err := b.compression.Decompress(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if prm.IgnoreErrors {
|
if prm.IgnoreErrors {
|
||||||
if prm.ErrorHandler != nil {
|
if prm.ErrorHandler != nil {
|
||||||
|
|
|
@ -16,8 +16,8 @@ type cfg struct {
|
||||||
openedCacheSize int
|
openedCacheSize int
|
||||||
blzShallowDepth uint64
|
blzShallowDepth uint64
|
||||||
blzShallowWidth uint64
|
blzShallowWidth uint64
|
||||||
*compression.CConfig
|
compression *compression.Config
|
||||||
blzOpts []blobovnicza.Option
|
blzOpts []blobovnicza.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
type Option func(*cfg)
|
type Option func(*cfg)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
// returns error if could not save object in any blobovnicza.
|
// returns error if could not save object in any blobovnicza.
|
||||||
func (b *Blobovniczas) Put(prm common.PutPrm) (common.PutRes, error) {
|
func (b *Blobovniczas) Put(prm common.PutPrm) (common.PutRes, error) {
|
||||||
if !prm.DontCompress {
|
if !prm.DontCompress {
|
||||||
prm.RawData = b.CConfig.Compress(prm.RawData)
|
prm.RawData = b.compression.Compress(prm.RawData)
|
||||||
}
|
}
|
||||||
|
|
||||||
var putPrm blobovnicza.PutPrm
|
var putPrm blobovnicza.PutPrm
|
||||||
|
|
|
@ -32,9 +32,9 @@ type Info = fstree.Info
|
||||||
type Option func(*cfg)
|
type Option func(*cfg)
|
||||||
|
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
compression.CConfig
|
compression compression.Config
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
storage []SubStorage
|
storage []SubStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
func initConfig(c *cfg) {
|
func initConfig(c *cfg) {
|
||||||
|
@ -51,7 +51,7 @@ func New(opts ...Option) *BlobStor {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range bs.storage {
|
for i := range bs.storage {
|
||||||
bs.storage[i].Storage.SetCompressor(&bs.CConfig)
|
bs.storage[i].Storage.SetCompressor(&bs.compression)
|
||||||
}
|
}
|
||||||
|
|
||||||
return bs
|
return bs
|
||||||
|
@ -86,7 +86,7 @@ func WithLogger(l *logger.Logger) Option {
|
||||||
// is recorded in the provided log.
|
// is recorded in the provided log.
|
||||||
func WithCompressObjects(comp bool) Option {
|
func WithCompressObjects(comp bool) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
c.Enabled = comp
|
c.compression.Enabled = comp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +94,6 @@ func WithCompressObjects(comp bool) Option {
|
||||||
// for specific content types as seen by object.AttributeContentType attribute.
|
// for specific content types as seen by object.AttributeContentType attribute.
|
||||||
func WithUncompressableContentTypes(values []string) Option {
|
func WithUncompressableContentTypes(values []string) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
c.UncompressableContentTypes = values
|
c.compression.UncompressableContentTypes = values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ type Storage interface {
|
||||||
Close() error
|
Close() error
|
||||||
|
|
||||||
Type() string
|
Type() string
|
||||||
SetCompressor(cc *compression.CConfig)
|
SetCompressor(cc *compression.Config)
|
||||||
|
|
||||||
Get(GetPrm) (GetRes, error)
|
Get(GetPrm) (GetRes, error)
|
||||||
GetRange(GetRangePrm) (GetRangeRes, error)
|
GetRange(GetRangePrm) (GetRangeRes, error)
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CConfig represents common compression-related configuration.
|
// Config represents common compression-related configuration.
|
||||||
type CConfig struct {
|
type Config struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
UncompressableContentTypes []string
|
UncompressableContentTypes []string
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ type CConfig struct {
|
||||||
var zstdFrameMagic = []byte{0x28, 0xb5, 0x2f, 0xfd}
|
var zstdFrameMagic = []byte{0x28, 0xb5, 0x2f, 0xfd}
|
||||||
|
|
||||||
// Init initializes compression routines.
|
// Init initializes compression routines.
|
||||||
func (c *CConfig) Init() error {
|
func (c *Config) Init() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if c.Enabled {
|
if c.Enabled {
|
||||||
|
@ -44,7 +44,7 @@ func (c *CConfig) Init() error {
|
||||||
// For an object to be compressed 2 conditions must hold:
|
// For an object to be compressed 2 conditions must hold:
|
||||||
// 1. Compression is enabled in settings.
|
// 1. Compression is enabled in settings.
|
||||||
// 2. Object MIME Content-Type is allowed for compression.
|
// 2. Object MIME Content-Type is allowed for compression.
|
||||||
func (c *CConfig) NeedsCompression(obj *objectSDK.Object) bool {
|
func (c *Config) NeedsCompression(obj *objectSDK.Object) bool {
|
||||||
if !c.Enabled || len(c.UncompressableContentTypes) == 0 {
|
if !c.Enabled || len(c.UncompressableContentTypes) == 0 {
|
||||||
return c.Enabled
|
return c.Enabled
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ func (c *CConfig) NeedsCompression(obj *objectSDK.Object) bool {
|
||||||
|
|
||||||
// Decompress decompresses data if it starts with the magic
|
// Decompress decompresses data if it starts with the magic
|
||||||
// and returns data untouched otherwise.
|
// and returns data untouched otherwise.
|
||||||
func (c *CConfig) Decompress(data []byte) ([]byte, error) {
|
func (c *Config) Decompress(data []byte) ([]byte, error) {
|
||||||
if len(data) < 4 || !bytes.Equal(data[:4], zstdFrameMagic) {
|
if len(data) < 4 || !bytes.Equal(data[:4], zstdFrameMagic) {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func (c *CConfig) Decompress(data []byte) ([]byte, error) {
|
||||||
|
|
||||||
// Compress compresses data if compression is enabled
|
// Compress compresses data if compression is enabled
|
||||||
// and returns data untouched otherwise.
|
// and returns data untouched otherwise.
|
||||||
func (c *CConfig) Compress(data []byte) []byte {
|
func (c *Config) Compress(data []byte) []byte {
|
||||||
if c == nil || !c.Enabled {
|
if c == nil || !c.Enabled {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (c *CConfig) Compress(data []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes encoder and decoder, returns any error occured.
|
// Close closes encoder and decoder, returns any error occured.
|
||||||
func (c *CConfig) Close() error {
|
func (c *Config) Close() error {
|
||||||
var err error
|
var err error
|
||||||
if c.encoder != nil {
|
if c.encoder != nil {
|
||||||
err = c.encoder.Close()
|
err = c.encoder.Close()
|
||||||
|
|
|
@ -31,7 +31,7 @@ var ErrInitBlobovniczas = errors.New("failure on blobovnicza initialization stag
|
||||||
func (b *BlobStor) Init() error {
|
func (b *BlobStor) Init() error {
|
||||||
b.log.Debug("initializing...")
|
b.log.Debug("initializing...")
|
||||||
|
|
||||||
if err := b.CConfig.Init(); err != nil {
|
if err := b.compression.Init(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func (b *BlobStor) Close() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := b.CConfig.Close()
|
err := b.compression.Close()
|
||||||
if firstErr == nil {
|
if firstErr == nil {
|
||||||
firstErr = err
|
firstErr = err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import (
|
||||||
type FSTree struct {
|
type FSTree struct {
|
||||||
Info
|
Info
|
||||||
|
|
||||||
*compression.CConfig
|
*compression.Config
|
||||||
Depth int
|
Depth int
|
||||||
DirNameLen int
|
DirNameLen int
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func New(opts ...Option) *FSTree {
|
||||||
Permissions: 0700,
|
Permissions: 0700,
|
||||||
RootPath: "./",
|
RootPath: "./",
|
||||||
},
|
},
|
||||||
CConfig: nil,
|
Config: nil,
|
||||||
Depth: 4,
|
Depth: 4,
|
||||||
DirNameLen: DirNameLen,
|
DirNameLen: DirNameLen,
|
||||||
}
|
}
|
||||||
|
@ -318,6 +318,6 @@ func (*FSTree) Type() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCompressor implements common.Storage.
|
// SetCompressor implements common.Storage.
|
||||||
func (t *FSTree) SetCompressor(cc *compression.CConfig) {
|
func (t *FSTree) SetCompressor(cc *compression.Config) {
|
||||||
t.CConfig = cc
|
t.Config = cc
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,5 +54,5 @@ func (b *BlobStor) Put(prm common.PutPrm) (common.PutRes, error) {
|
||||||
// 1. Compression is enabled in settings.
|
// 1. Compression is enabled in settings.
|
||||||
// 2. Object MIME Content-Type is allowed for compression.
|
// 2. Object MIME Content-Type is allowed for compression.
|
||||||
func (b *BlobStor) NeedsCompression(obj *objectSDK.Object) bool {
|
func (b *BlobStor) NeedsCompression(obj *objectSDK.Object) bool {
|
||||||
return b.cfg.CConfig.NeedsCompression(obj)
|
return b.cfg.compression.NeedsCompression(obj)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue