2020-11-17 16:29:00 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2022-07-05 04:55:46 +00:00
|
|
|
"sync"
|
2020-11-18 12:27:21 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"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"
|
2020-11-18 12:27:21 +00:00
|
|
|
"go.uber.org/zap"
|
2020-11-17 16:29:00 +00:00
|
|
|
)
|
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
// SubStorage represents single storage component with some storage policy.
|
|
|
|
type SubStorage struct {
|
|
|
|
Storage common.Storage
|
|
|
|
Policy func(*objectSDK.Object, []byte) bool
|
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// BlobStor represents FrostFS local BLOB storage.
|
2020-11-17 16:29:00 +00:00
|
|
|
type BlobStor struct {
|
2022-07-05 13:47:39 +00:00
|
|
|
cfg
|
2022-07-05 04:55:46 +00:00
|
|
|
|
|
|
|
modeMtx sync.RWMutex
|
|
|
|
mode mode.Mode
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 12:41:36 +00:00
|
|
|
// Info contains information about blobstor.
|
|
|
|
type Info struct {
|
|
|
|
SubStorages []SubStorageInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SubStorageInfo contains information about blobstor storage component.
|
|
|
|
type SubStorageInfo struct {
|
|
|
|
Type string
|
|
|
|
Path string
|
|
|
|
}
|
2021-04-08 13:53:25 +00:00
|
|
|
|
2020-11-17 16:29:00 +00:00
|
|
|
// Option represents BlobStor's constructor option.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
2022-08-19 14:29:53 +00:00
|
|
|
compression compression.Config
|
|
|
|
log *logger.Logger
|
|
|
|
storage []SubStorage
|
2023-06-06 06:05:52 +00:00
|
|
|
metrics Metrics
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
func initConfig(c *cfg) {
|
2022-09-28 07:41:01 +00:00
|
|
|
c.log = &logger.Logger{Logger: zap.L()}
|
2023-06-06 06:05:52 +00:00
|
|
|
c.metrics = &noopMetrics{}
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns new BlobStor instance.
|
|
|
|
func New(opts ...Option) *BlobStor {
|
2022-07-05 13:47:39 +00:00
|
|
|
bs := new(BlobStor)
|
|
|
|
initConfig(&bs.cfg)
|
2020-11-17 16:29:00 +00:00
|
|
|
|
|
|
|
for i := range opts {
|
2022-07-05 13:47:39 +00:00
|
|
|
opts[i](&bs.cfg)
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 12:34:17 +00:00
|
|
|
for i := range bs.storage {
|
2022-08-19 14:29:53 +00:00
|
|
|
bs.storage[i].Storage.SetCompressor(&bs.compression)
|
2022-07-08 11:33:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
return bs
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 11:27:12 +00:00
|
|
|
// SetLogger sets logger. It is used after the shard ID was generated to use it in logs.
|
2022-09-28 07:41:01 +00:00
|
|
|
func (b *BlobStor) SetLogger(l *logger.Logger) {
|
2022-07-19 11:27:12 +00:00
|
|
|
b.log = l
|
|
|
|
}
|
|
|
|
|
2023-06-07 11:39:03 +00:00
|
|
|
func (b *BlobStor) SetParentID(parentID string) {
|
|
|
|
b.metrics.SetParentID(parentID)
|
|
|
|
for _, ss := range b.storage {
|
|
|
|
ss.Storage.SetParentID(parentID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 12:34:17 +00:00
|
|
|
// WithStorages provides sub-blobstors.
|
|
|
|
func WithStorages(st []SubStorage) Option {
|
2020-11-17 16:29:00 +00:00
|
|
|
return func(c *cfg) {
|
2022-07-11 12:34:17 +00:00
|
|
|
c.storage = st
|
|
|
|
}
|
|
|
|
}
|
2020-11-17 16:29:00 +00:00
|
|
|
|
2022-07-11 12:34:17 +00:00
|
|
|
// WithLogger returns option to specify BlobStor's logger.
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
2022-09-28 07:41:01 +00:00
|
|
|
c.log = &logger.Logger{Logger: l.With(zap.String("component", "BlobStor"))}
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithCompressObjects returns option to toggle
|
|
|
|
// compression of the stored objects.
|
2020-11-18 12:27:21 +00:00
|
|
|
//
|
|
|
|
// If true, Zstandard algorithm is used for data compression.
|
|
|
|
//
|
|
|
|
// If compressor (decompressor) creation failed,
|
|
|
|
// the uncompressed option will be used, and the error
|
|
|
|
// is recorded in the provided log.
|
2021-10-07 14:19:55 +00:00
|
|
|
func WithCompressObjects(comp bool) Option {
|
2020-11-17 16:29:00 +00:00
|
|
|
return func(c *cfg) {
|
2022-08-19 14:29:53 +00:00
|
|
|
c.compression.Enabled = comp
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-10 12:46:01 +00:00
|
|
|
// WithUncompressableContentTypes returns option to disable decompression
|
|
|
|
// for specific content types as seen by object.AttributeContentType attribute.
|
|
|
|
func WithUncompressableContentTypes(values []string) Option {
|
|
|
|
return func(c *cfg) {
|
2022-08-19 14:29:53 +00:00
|
|
|
c.compression.UncompressableContentTypes = values
|
2022-01-10 12:46:01 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-09 10:59:24 +00:00
|
|
|
|
|
|
|
// 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(string, error)) {
|
|
|
|
for i := range b.storage {
|
|
|
|
b.storage[i].Storage.SetReportErrorFunc(f)
|
|
|
|
}
|
|
|
|
}
|
2023-06-06 06:05:52 +00:00
|
|
|
|
|
|
|
func WithMetrics(m Metrics) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.metrics = m
|
|
|
|
}
|
|
|
|
}
|
2023-08-09 12:54:08 +00:00
|
|
|
|
|
|
|
func (b *BlobStor) Compressor() *compression.Config {
|
|
|
|
return &b.cfg.compression
|
|
|
|
}
|