2022-07-05 13:47:39 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/fs"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/compression"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2022-07-05 13:47:39 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cfg struct {
|
2022-09-28 07:41:01 +00:00
|
|
|
log *logger.Logger
|
2022-07-05 13:47:39 +00:00
|
|
|
perm fs.FileMode
|
|
|
|
readOnly bool
|
|
|
|
rootPath string
|
|
|
|
openedCacheSize int
|
|
|
|
blzShallowDepth uint64
|
|
|
|
blzShallowWidth uint64
|
2022-08-19 14:29:53 +00:00
|
|
|
compression *compression.Config
|
|
|
|
blzOpts []blobovnicza.Option
|
2022-11-09 10:59:24 +00:00
|
|
|
// reportError is the function called when encountering disk errors.
|
|
|
|
reportError func(string, error)
|
2022-07-05 13:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultPerm = 0700
|
|
|
|
defaultOpenedCacheSize = 50
|
|
|
|
defaultBlzShallowDepth = 2
|
|
|
|
defaultBlzShallowWidth = 16
|
|
|
|
)
|
|
|
|
|
|
|
|
func initConfig(c *cfg) {
|
|
|
|
*c = cfg{
|
2022-09-28 07:41:01 +00:00
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
2022-07-05 13:47:39 +00:00
|
|
|
perm: defaultPerm,
|
|
|
|
openedCacheSize: defaultOpenedCacheSize,
|
|
|
|
blzShallowDepth: defaultBlzShallowDepth,
|
|
|
|
blzShallowWidth: defaultBlzShallowWidth,
|
2022-11-09 10:59:24 +00:00
|
|
|
reportError: func(string, error) {},
|
2022-07-05 13:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-28 07:41:01 +00:00
|
|
|
func WithLogger(l *logger.Logger) Option {
|
2022-07-05 13:47:39 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l
|
|
|
|
c.blzOpts = append(c.blzOpts, blobovnicza.WithLogger(l))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithPermissions(perm fs.FileMode) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.perm = perm
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithBlobovniczaShallowWidth(width uint64) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.blzShallowWidth = width
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithBlobovniczaShallowDepth(depth uint64) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.blzShallowDepth = depth
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithRootPath(p string) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.rootPath = p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithBlobovniczaSize(sz uint64) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.blzOpts = append(c.blzOpts, blobovnicza.WithFullSizeLimit(sz))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithOpenedCacheSize(sz int) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.openedCacheSize = sz
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithObjectSizeLimit(sz uint64) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.blzOpts = append(c.blzOpts, blobovnicza.WithObjectSizeLimit(sz))
|
|
|
|
}
|
|
|
|
}
|