Evgenii Stratonikov
4c520be9f1
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 1m59s
DCO action / DCO (pull_request) Successful in 1m53s
Build / Build Components (1.21) (pull_request) Successful in 2m20s
Build / Build Components (1.22) (pull_request) Successful in 2m26s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m56s
Tests and linters / Staticcheck (pull_request) Successful in 2m47s
Tests and linters / Tests (1.21) (pull_request) Successful in 2m56s
Tests and linters / Tests (1.22) (pull_request) Successful in 2m57s
Tests and linters / Lint (pull_request) Successful in 3m7s
Tests and linters / Tests with -race (pull_request) Successful in 3m7s
Tests and linters / gopls check (pull_request) Successful in 3m46s
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
129 lines
2.4 KiB
Go
129 lines
2.4 KiB
Go
package blobovnicza
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"sync"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
"go.etcd.io/bbolt"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// Blobovnicza represents the implementation of FrostFS Blobovnicza.
|
|
type Blobovnicza struct {
|
|
cfg
|
|
|
|
dataSize atomic.Uint64
|
|
itemsCount atomic.Uint64
|
|
|
|
boltDB *bbolt.DB
|
|
|
|
opened bool
|
|
controlMtx sync.RWMutex
|
|
}
|
|
|
|
// Option is an option of Blobovnicza's constructor.
|
|
type Option func(*cfg)
|
|
|
|
type cfg struct {
|
|
boltDBCfg
|
|
|
|
fullSizeLimit uint64
|
|
|
|
objSizeLimit uint64
|
|
|
|
log *logger.Logger
|
|
|
|
metrics Metrics
|
|
}
|
|
|
|
type boltDBCfg struct {
|
|
perm fs.FileMode
|
|
|
|
path string
|
|
|
|
boltOptions *bbolt.Options
|
|
}
|
|
|
|
func defaultCfg(c *cfg) {
|
|
*c = cfg{
|
|
boltDBCfg: boltDBCfg{
|
|
perm: os.ModePerm, // 0777
|
|
boltOptions: &bbolt.Options{
|
|
Timeout: 100 * time.Millisecond,
|
|
},
|
|
},
|
|
fullSizeLimit: 1 << 30, // 1GB
|
|
objSizeLimit: 1 << 20, // 1MB
|
|
log: &logger.Logger{Logger: zap.L()},
|
|
metrics: &NoopMetrics{},
|
|
}
|
|
}
|
|
|
|
// New creates and returns a new Blobovnicza instance.
|
|
func New(opts ...Option) *Blobovnicza {
|
|
var b Blobovnicza
|
|
|
|
defaultCfg(&b.cfg)
|
|
|
|
for i := range opts {
|
|
opts[i](&b.cfg)
|
|
}
|
|
|
|
return &b
|
|
}
|
|
|
|
// WithPath returns option to set system path to Blobovnicza.
|
|
func WithPath(path string) Option {
|
|
return func(c *cfg) {
|
|
c.path = path
|
|
}
|
|
}
|
|
|
|
// WithPermissions returns an option to specify permission bits
|
|
// of Blobovnicza's system path.
|
|
func WithPermissions(perm fs.FileMode) Option {
|
|
return func(c *cfg) {
|
|
c.perm = perm
|
|
}
|
|
}
|
|
|
|
// WithObjectSizeLimit returns an option to specify the maximum size
|
|
// of the objects stored in Blobovnicza.
|
|
func WithObjectSizeLimit(lim uint64) Option {
|
|
return func(c *cfg) {
|
|
c.objSizeLimit = lim
|
|
}
|
|
}
|
|
|
|
// WithFullSizeLimit returns an option to set the maximum sum size
|
|
// of all stored objects.
|
|
func WithFullSizeLimit(lim uint64) Option {
|
|
return func(c *cfg) {
|
|
c.fullSizeLimit = lim
|
|
}
|
|
}
|
|
|
|
// WithLogger returns an option to specify Blobovnicza's logger.
|
|
func WithLogger(l *logger.Logger) Option {
|
|
return func(c *cfg) {
|
|
c.log = &logger.Logger{Logger: l.With(zap.String("component", "Blobovnicza"))}
|
|
}
|
|
}
|
|
|
|
// WithReadOnly returns an option to open Blobovnicza in read-only mode.
|
|
func WithReadOnly(ro bool) Option {
|
|
return func(c *cfg) {
|
|
c.boltOptions.ReadOnly = ro
|
|
}
|
|
}
|
|
|
|
// WithMetrics returns an option to set metrics storage.
|
|
func WithMetrics(m Metrics) Option {
|
|
return func(c *cfg) {
|
|
c.metrics = m
|
|
}
|
|
}
|