2022-07-05 13:47:39 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/fs"
|
2023-09-22 10:07:32 +00:00
|
|
|
"time"
|
2022-07-05 13:47:39 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/compression"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2022-07-05 13:47:39 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cfg struct {
|
2023-09-22 14:08:48 +00:00
|
|
|
log *logger.Logger
|
|
|
|
perm fs.FileMode
|
|
|
|
readOnly bool
|
|
|
|
rootPath string
|
|
|
|
openedCacheSize int
|
2023-12-18 09:47:32 +00:00
|
|
|
openedCacheTTL time.Duration
|
2023-09-22 14:08:48 +00:00
|
|
|
blzShallowDepth uint64
|
|
|
|
blzShallowWidth uint64
|
|
|
|
blzLeafWidth uint64
|
|
|
|
compression *compression.Config
|
|
|
|
blzOpts []blobovnicza.Option
|
|
|
|
reportError func(string, error) // reportError is the function called when encountering disk errors.
|
|
|
|
metrics Metrics
|
|
|
|
waitBeforeDropDB time.Duration
|
|
|
|
blzInitWorkerCount int
|
2023-10-10 13:01:35 +00:00
|
|
|
blzMoveBatchSize int
|
2023-11-27 13:01:48 +00:00
|
|
|
createDBInAdvance bool
|
2022-07-05 13:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
const (
|
2023-09-22 14:08:48 +00:00
|
|
|
defaultPerm = 0o700
|
|
|
|
defaultOpenedCacheSize = 50
|
2023-12-18 09:47:32 +00:00
|
|
|
defaultOpenedCacheTTL = 0 // means expiring is off
|
2023-09-22 14:08:48 +00:00
|
|
|
defaultBlzShallowDepth = 2
|
|
|
|
defaultBlzShallowWidth = 16
|
|
|
|
defaultWaitBeforeDropDB = 10 * time.Second
|
|
|
|
defaultBlzInitWorkerCount = 5
|
2023-10-10 13:01:35 +00:00
|
|
|
defaulBlzMoveBatchSize = 10000
|
2022-07-05 13:47:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func initConfig(c *cfg) {
|
|
|
|
*c = cfg{
|
2023-09-22 14:08:48 +00:00
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
|
|
|
perm: defaultPerm,
|
|
|
|
openedCacheSize: defaultOpenedCacheSize,
|
2023-12-18 09:47:32 +00:00
|
|
|
openedCacheTTL: defaultOpenedCacheTTL,
|
2023-09-22 14:08:48 +00:00
|
|
|
blzShallowDepth: defaultBlzShallowDepth,
|
|
|
|
blzShallowWidth: defaultBlzShallowWidth,
|
|
|
|
reportError: func(string, error) {},
|
|
|
|
metrics: &noopMetrics{},
|
|
|
|
waitBeforeDropDB: defaultWaitBeforeDropDB,
|
|
|
|
blzInitWorkerCount: defaultBlzInitWorkerCount,
|
2023-10-10 13:01:35 +00:00
|
|
|
blzMoveBatchSize: defaulBlzMoveBatchSize,
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 06:08:26 +00:00
|
|
|
func WithBlobovniczaLeafWidth(w uint64) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.blzLeafWidth = w
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-18 09:47:32 +00:00
|
|
|
func WithOpenedCacheTTL(ttl time.Duration) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.openedCacheTTL = ttl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
func WithObjectSizeLimit(sz uint64) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.blzOpts = append(c.blzOpts, blobovnicza.WithObjectSizeLimit(sz))
|
|
|
|
}
|
|
|
|
}
|
2023-06-05 07:25:25 +00:00
|
|
|
|
|
|
|
func WithMetrics(m Metrics) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.metrics = m
|
|
|
|
}
|
|
|
|
}
|
2023-09-22 10:07:32 +00:00
|
|
|
|
|
|
|
func WithWaitBeforeDropDB(t time.Duration) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.waitBeforeDropDB = t
|
|
|
|
}
|
|
|
|
}
|
2023-09-22 14:08:48 +00:00
|
|
|
|
2023-10-10 13:01:35 +00:00
|
|
|
func WithMoveBatchSize(v int) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.blzMoveBatchSize = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-22 14:08:48 +00:00
|
|
|
// WithInitWorkerCount sets maximum workers count to init blobovnicza tree.
|
|
|
|
//
|
|
|
|
// Negative or zero value means no limit.
|
|
|
|
func WithInitWorkerCount(v int) Option {
|
|
|
|
if v <= 0 {
|
|
|
|
v = -1
|
|
|
|
}
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.blzInitWorkerCount = v
|
|
|
|
}
|
|
|
|
}
|
2023-11-27 13:01:48 +00:00
|
|
|
|
|
|
|
// WithInitInAdvance returns an option to create blobovnicza tree DB's in advance.
|
|
|
|
func WithInitInAdvance(v bool) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.createDBInAdvance = v
|
|
|
|
}
|
|
|
|
}
|