2020-11-26 08:17:53 +00:00
|
|
|
package blobovnicza
|
|
|
|
|
2020-11-26 14:26:21 +00:00
|
|
|
import (
|
2021-06-28 14:01:31 +00:00
|
|
|
"io/fs"
|
2020-11-26 14:26:21 +00:00
|
|
|
"os"
|
2021-01-18 13:03:00 +00:00
|
|
|
"time"
|
2020-11-26 14:26:21 +00:00
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2020-11-26 14:26:21 +00:00
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
"go.uber.org/atomic"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// Blobovnicza represents the implementation of FrostFS Blobovnicza.
|
2020-11-26 08:17:53 +00:00
|
|
|
type Blobovnicza struct {
|
2022-06-01 11:05:26 +00:00
|
|
|
cfg
|
2020-11-26 14:26:21 +00:00
|
|
|
|
2022-06-01 11:05:26 +00:00
|
|
|
filled atomic.Uint64
|
2020-11-26 14:26:21 +00:00
|
|
|
|
|
|
|
boltDB *bbolt.DB
|
2020-11-26 08:17:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Option is an option of Blobovnicza's constructor.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
2020-11-26 14:26:21 +00:00
|
|
|
boltDBCfg
|
|
|
|
|
|
|
|
fullSizeLimit uint64
|
|
|
|
|
|
|
|
objSizeLimit uint64
|
|
|
|
|
|
|
|
log *logger.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
type boltDBCfg struct {
|
2021-06-28 14:01:31 +00:00
|
|
|
perm fs.FileMode
|
2020-11-26 14:26:21 +00:00
|
|
|
|
|
|
|
path string
|
|
|
|
|
|
|
|
boltOptions *bbolt.Options
|
2020-11-26 08:17:53 +00:00
|
|
|
}
|
|
|
|
|
2023-01-16 12:52:44 +00:00
|
|
|
func defaultCfg(c *cfg) {
|
|
|
|
*c = cfg{
|
2020-11-26 14:26:21 +00:00
|
|
|
boltDBCfg: boltDBCfg{
|
|
|
|
perm: os.ModePerm, // 0777
|
2021-01-18 13:03:00 +00:00
|
|
|
boltOptions: &bbolt.Options{
|
|
|
|
Timeout: 100 * time.Millisecond,
|
|
|
|
},
|
2020-11-26 14:26:21 +00:00
|
|
|
},
|
|
|
|
fullSizeLimit: 1 << 30, // 1GB
|
|
|
|
objSizeLimit: 1 << 20, // 1MB
|
2022-09-28 07:41:01 +00:00
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
2020-11-26 14:26:21 +00:00
|
|
|
}
|
2020-11-26 08:17:53 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// New creates and returns a new Blobovnicza instance.
|
2020-11-26 08:17:53 +00:00
|
|
|
func New(opts ...Option) *Blobovnicza {
|
2022-06-01 11:05:26 +00:00
|
|
|
var b Blobovnicza
|
|
|
|
|
|
|
|
defaultCfg(&b.cfg)
|
2020-11-26 08:17:53 +00:00
|
|
|
|
|
|
|
for i := range opts {
|
2022-06-01 11:05:26 +00:00
|
|
|
opts[i](&b.cfg)
|
2020-11-26 08:17:53 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 11:05:26 +00:00
|
|
|
return &b
|
2020-11-26 14:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WithPath returns option to set system path to Blobovnicza.
|
|
|
|
func WithPath(path string) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.path = path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithPermissions returns an option to specify permission bits
|
2020-11-26 14:26:21 +00:00
|
|
|
// of Blobovnicza's system path.
|
2021-06-28 14:01:31 +00:00
|
|
|
func WithPermissions(perm fs.FileMode) Option {
|
2020-11-26 14:26:21 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.perm = perm
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithObjectSizeLimit returns an option to specify the maximum size
|
2020-11-26 14:26:21 +00:00
|
|
|
// of the objects stored in Blobovnicza.
|
|
|
|
func WithObjectSizeLimit(lim uint64) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.objSizeLimit = lim
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithFullSizeLimit returns an option to set the maximum sum size
|
2020-11-26 14:26:21 +00:00
|
|
|
// of all stored objects.
|
|
|
|
func WithFullSizeLimit(lim uint64) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.fullSizeLimit = lim
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithLogger returns an option to specify Blobovnicza's logger.
|
2020-11-26 14:26:21 +00:00
|
|
|
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", "Blobovnicza"))}
|
2020-11-26 14:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-14 14:44:07 +00:00
|
|
|
|
2022-06-28 13:42:50 +00:00
|
|
|
// WithReadOnly returns an option to open Blobovnicza in read-only mode.
|
|
|
|
func WithReadOnly(ro bool) Option {
|
2021-09-14 14:44:07 +00:00
|
|
|
return func(c *cfg) {
|
2022-06-28 13:42:50 +00:00
|
|
|
c.boltOptions.ReadOnly = ro
|
2021-09-14 14:44:07 +00:00
|
|
|
}
|
|
|
|
}
|