From e8c6dce46699b4c50f4631e99f166cc6b8b346d1 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 19 Aug 2022 17:29:53 +0300 Subject: [PATCH] [#1523] blobstor: Rename `compression.CConfig` to `Config` Signed-off-by: Evgenii Stratonikov --- .../blobstor/blobovniczatree/blobovnicza.go | 14 +++++++------- .../blobstor/blobovniczatree/get.go | 2 +- .../blobstor/blobovniczatree/get_range.go | 2 +- .../blobstor/blobovniczatree/iterate.go | 2 +- .../blobstor/blobovniczatree/option.go | 4 ++-- .../blobstor/blobovniczatree/put.go | 2 +- pkg/local_object_storage/blobstor/blobstor.go | 12 ++++++------ .../blobstor/common/storage.go | 2 +- .../blobstor/compression/compress.go | 14 +++++++------- pkg/local_object_storage/blobstor/control.go | 4 ++-- pkg/local_object_storage/blobstor/fstree/fstree.go | 8 ++++---- pkg/local_object_storage/blobstor/put.go | 2 +- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go index 5e1143704..665047631 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go @@ -48,11 +48,11 @@ import ( // B-s are intitialized and opened. // // Object is saved as follows: -// 1. at each level, according to HRW, the next one is selected and -// dives into it until we reach the deepest; -// 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 no more X candidates, goto 1 and process next level. +// 1. at each level, according to HRW, the next one is selected and +// dives into it until we reach the deepest; +// 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 no more X candidates, goto 1 and process next level. // // 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"). @@ -228,6 +228,6 @@ func (b *Blobovniczas) Type() string { } // SetCompressor implements common.Storage. -func (b *Blobovniczas) SetCompressor(cc *compression.CConfig) { - b.CConfig = cc +func (b *Blobovniczas) SetCompressor(cc *compression.Config) { + b.compression = cc } diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/get.go b/pkg/local_object_storage/blobstor/blobovniczatree/get.go index b8b55dc15..b9cffdd33 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/get.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/get.go @@ -132,7 +132,7 @@ func (b *Blobovniczas) getObject(blz *blobovnicza.Blobovnicza, prm blobovnicza.G } // decompress the data - data, err := b.Decompress(res.Object()) + data, err := b.compression.Decompress(res.Object()) if err != nil { return common.GetRes{}, fmt.Errorf("could not decompress object data: %w", err) } diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/get_range.go b/pkg/local_object_storage/blobstor/blobovniczatree/get_range.go index 72d26b72e..fb3591dcf 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/get_range.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/get_range.go @@ -154,7 +154,7 @@ func (b *Blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm common.G } // decompress the data - data, err := b.Decompress(res.Object()) + data, err := b.compression.Decompress(res.Object()) if err != nil { return common.GetRangeRes{}, fmt.Errorf("could not decompress object data: %w", err) } diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go b/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go index 4759fb086..41ab2c932 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go @@ -14,7 +14,7 @@ import ( 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 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 prm.IgnoreErrors { if prm.ErrorHandler != nil { diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/option.go b/pkg/local_object_storage/blobstor/blobovniczatree/option.go index b16243b18..f5ed19df4 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/option.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/option.go @@ -16,8 +16,8 @@ type cfg struct { openedCacheSize int blzShallowDepth uint64 blzShallowWidth uint64 - *compression.CConfig - blzOpts []blobovnicza.Option + compression *compression.Config + blzOpts []blobovnicza.Option } type Option func(*cfg) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/put.go b/pkg/local_object_storage/blobstor/blobovniczatree/put.go index a353efd5d..681f80cd4 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/put.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/put.go @@ -14,7 +14,7 @@ import ( // returns error if could not save object in any blobovnicza. func (b *Blobovniczas) Put(prm common.PutPrm) (common.PutRes, error) { if !prm.DontCompress { - prm.RawData = b.CConfig.Compress(prm.RawData) + prm.RawData = b.compression.Compress(prm.RawData) } var putPrm blobovnicza.PutPrm diff --git a/pkg/local_object_storage/blobstor/blobstor.go b/pkg/local_object_storage/blobstor/blobstor.go index dabc4f18e..4d8bd94f9 100644 --- a/pkg/local_object_storage/blobstor/blobstor.go +++ b/pkg/local_object_storage/blobstor/blobstor.go @@ -32,9 +32,9 @@ type Info = fstree.Info type Option func(*cfg) type cfg struct { - compression.CConfig - log *logger.Logger - storage []SubStorage + compression compression.Config + log *logger.Logger + storage []SubStorage } func initConfig(c *cfg) { @@ -51,7 +51,7 @@ func New(opts ...Option) *BlobStor { } for i := range bs.storage { - bs.storage[i].Storage.SetCompressor(&bs.CConfig) + bs.storage[i].Storage.SetCompressor(&bs.compression) } return bs @@ -86,7 +86,7 @@ func WithLogger(l *logger.Logger) Option { // is recorded in the provided log. func WithCompressObjects(comp bool) Option { 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. func WithUncompressableContentTypes(values []string) Option { return func(c *cfg) { - c.UncompressableContentTypes = values + c.compression.UncompressableContentTypes = values } } diff --git a/pkg/local_object_storage/blobstor/common/storage.go b/pkg/local_object_storage/blobstor/common/storage.go index 741a863e7..d6bea47a2 100644 --- a/pkg/local_object_storage/blobstor/common/storage.go +++ b/pkg/local_object_storage/blobstor/common/storage.go @@ -10,7 +10,7 @@ type Storage interface { Close() error Type() string - SetCompressor(cc *compression.CConfig) + SetCompressor(cc *compression.Config) Get(GetPrm) (GetRes, error) GetRange(GetRangePrm) (GetRangeRes, error) diff --git a/pkg/local_object_storage/blobstor/compression/compress.go b/pkg/local_object_storage/blobstor/compression/compress.go index e71dc8a1a..51d8039c7 100644 --- a/pkg/local_object_storage/blobstor/compression/compress.go +++ b/pkg/local_object_storage/blobstor/compression/compress.go @@ -8,8 +8,8 @@ import ( objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" ) -// CConfig represents common compression-related configuration. -type CConfig struct { +// Config represents common compression-related configuration. +type Config struct { Enabled bool UncompressableContentTypes []string @@ -22,7 +22,7 @@ type CConfig struct { var zstdFrameMagic = []byte{0x28, 0xb5, 0x2f, 0xfd} // Init initializes compression routines. -func (c *CConfig) Init() error { +func (c *Config) Init() error { var err error if c.Enabled { @@ -44,7 +44,7 @@ func (c *CConfig) Init() error { // For an object to be compressed 2 conditions must hold: // 1. Compression is enabled in settings. // 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 { return c.Enabled } @@ -73,7 +73,7 @@ func (c *CConfig) NeedsCompression(obj *objectSDK.Object) bool { // Decompress decompresses data if it starts with the magic // 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) { return data, nil } @@ -82,7 +82,7 @@ func (c *CConfig) Decompress(data []byte) ([]byte, error) { // Compress compresses data if compression is enabled // and returns data untouched otherwise. -func (c *CConfig) Compress(data []byte) []byte { +func (c *Config) Compress(data []byte) []byte { if c == nil || !c.Enabled { return data } @@ -90,7 +90,7 @@ func (c *CConfig) Compress(data []byte) []byte { } // Close closes encoder and decoder, returns any error occured. -func (c *CConfig) Close() error { +func (c *Config) Close() error { var err error if c.encoder != nil { err = c.encoder.Close() diff --git a/pkg/local_object_storage/blobstor/control.go b/pkg/local_object_storage/blobstor/control.go index e009080d4..6ceb9cefa 100644 --- a/pkg/local_object_storage/blobstor/control.go +++ b/pkg/local_object_storage/blobstor/control.go @@ -31,7 +31,7 @@ var ErrInitBlobovniczas = errors.New("failure on blobovnicza initialization stag func (b *BlobStor) Init() error { b.log.Debug("initializing...") - if err := b.CConfig.Init(); err != nil { + if err := b.compression.Init(); err != nil { return err } @@ -60,7 +60,7 @@ func (b *BlobStor) Close() error { } } - err := b.CConfig.Close() + err := b.compression.Close() if firstErr == nil { firstErr = err } diff --git a/pkg/local_object_storage/blobstor/fstree/fstree.go b/pkg/local_object_storage/blobstor/fstree/fstree.go index d430dfcfd..2e729943e 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree.go @@ -22,7 +22,7 @@ import ( type FSTree struct { Info - *compression.CConfig + *compression.Config Depth int DirNameLen int } @@ -51,7 +51,7 @@ func New(opts ...Option) *FSTree { Permissions: 0700, RootPath: "./", }, - CConfig: nil, + Config: nil, Depth: 4, DirNameLen: DirNameLen, } @@ -318,6 +318,6 @@ func (*FSTree) Type() string { } // SetCompressor implements common.Storage. -func (t *FSTree) SetCompressor(cc *compression.CConfig) { - t.CConfig = cc +func (t *FSTree) SetCompressor(cc *compression.Config) { + t.Config = cc } diff --git a/pkg/local_object_storage/blobstor/put.go b/pkg/local_object_storage/blobstor/put.go index 6e0f45539..9d0a48813 100644 --- a/pkg/local_object_storage/blobstor/put.go +++ b/pkg/local_object_storage/blobstor/put.go @@ -54,5 +54,5 @@ func (b *BlobStor) Put(prm common.PutPrm) (common.PutRes, error) { // 1. Compression is enabled in settings. // 2. Object MIME Content-Type is allowed for compression. func (b *BlobStor) NeedsCompression(obj *objectSDK.Object) bool { - return b.cfg.CConfig.NeedsCompression(obj) + return b.cfg.compression.NeedsCompression(obj) }