Change-Id: I55ffcce9d2a74fdd47621674739b07f2e20199e3 Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
120 lines
2.7 KiB
Go
120 lines
2.7 KiB
Go
package blobstor
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/compression"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// SubStorage represents single storage component with some storage policy.
|
|
type SubStorage struct {
|
|
Storage common.Storage
|
|
Policy func(*objectSDK.Object, []byte) bool
|
|
}
|
|
|
|
// BlobStor represents FrostFS local BLOB storage.
|
|
type BlobStor struct {
|
|
cfg
|
|
|
|
modeMtx sync.RWMutex
|
|
mode mode.Mode
|
|
}
|
|
|
|
// Info contains information about blobstor.
|
|
type Info struct {
|
|
SubStorages []SubStorageInfo
|
|
}
|
|
|
|
// SubStorageInfo contains information about blobstor storage component.
|
|
type SubStorageInfo struct {
|
|
Type string
|
|
Path string
|
|
}
|
|
|
|
// Option represents BlobStor's constructor option.
|
|
type Option func(*cfg)
|
|
|
|
type cfg struct {
|
|
compression compression.Compressor
|
|
log *logger.Logger
|
|
storage []SubStorage
|
|
metrics Metrics
|
|
}
|
|
|
|
func initConfig(c *cfg) {
|
|
c.log = logger.NewLoggerWrapper(zap.L())
|
|
c.metrics = &noopMetrics{}
|
|
}
|
|
|
|
// New creates, initializes and returns new BlobStor instance.
|
|
func New(opts ...Option) *BlobStor {
|
|
bs := new(BlobStor)
|
|
bs.mode = mode.Disabled
|
|
initConfig(&bs.cfg)
|
|
|
|
for i := range opts {
|
|
opts[i](&bs.cfg)
|
|
}
|
|
|
|
for i := range bs.storage {
|
|
bs.storage[i].Storage.SetCompressor(&bs.compression)
|
|
}
|
|
|
|
return bs
|
|
}
|
|
|
|
// SetLogger sets logger. It is used after the shard ID was generated to use it in logs.
|
|
func (b *BlobStor) SetLogger(l *logger.Logger) {
|
|
b.log = l
|
|
}
|
|
|
|
func (b *BlobStor) SetParentID(parentID string) {
|
|
b.metrics.SetParentID(parentID)
|
|
for _, ss := range b.storage {
|
|
ss.Storage.SetParentID(parentID)
|
|
}
|
|
}
|
|
|
|
// WithStorages provides sub-blobstors.
|
|
func WithStorages(st []SubStorage) Option {
|
|
return func(c *cfg) {
|
|
c.storage = st
|
|
}
|
|
}
|
|
|
|
// WithLogger returns option to specify BlobStor's logger.
|
|
func WithLogger(l *logger.Logger) Option {
|
|
return func(c *cfg) {
|
|
c.log = l
|
|
}
|
|
}
|
|
|
|
func WithCompression(comp compression.Config) Option {
|
|
return func(c *cfg) {
|
|
c.compression.Config = comp
|
|
}
|
|
}
|
|
|
|
// SetReportErrorFunc allows to provide a function to be called on disk errors.
|
|
// This function MUST be called before Open.
|
|
func (b *BlobStor) SetReportErrorFunc(f func(context.Context, string, error)) {
|
|
for i := range b.storage {
|
|
b.storage[i].Storage.SetReportErrorFunc(f)
|
|
}
|
|
}
|
|
|
|
func WithMetrics(m Metrics) Option {
|
|
return func(c *cfg) {
|
|
c.metrics = m
|
|
}
|
|
}
|
|
|
|
func (b *BlobStor) Compressor() *compression.Compressor {
|
|
return &b.compression
|
|
}
|