frostfs-node/pkg/local_object_storage/writecache/writecachebitcask/options.go
Alejandro Lopez 42e74d6aab
Some checks failed
DCO action / DCO (pull_request) Successful in 3m8s
Vulncheck / Vulncheck (pull_request) Successful in 3m16s
Build / Build Components (1.20) (pull_request) Successful in 4m13s
Build / Build Components (1.21) (pull_request) Successful in 4m16s
Tests and linters / Staticcheck (pull_request) Successful in 5m11s
Tests and linters / Lint (pull_request) Successful in 5m58s
Tests and linters / Tests with -race (pull_request) Failing after 6m3s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m29s
Tests and linters / Tests (1.21) (pull_request) Successful in 7m38s
[#610] Add bitcask-inspired writecache implementation
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
2023-08-31 14:17:10 +03:00

140 lines
3.6 KiB
Go

package writecachebitcask
import (
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"go.uber.org/zap"
)
// Option represents write-cache configuration option.
type Option func(*options)
type options struct {
path string
log *logger.Logger
blobstor writecache.MainStorage
metabase writecache.Metabase
metrics writecache.Metrics
// reportError is the function called when encountering disk errors in background workers.
reportError func(string, error)
maxObjectSize uint64
bucketCount int
regionCount int
maxLogSize uint64
maxBatchDelay time.Duration
maxPendingLogFileFlush int
}
// WithPath sets path to writecache data.
func WithPath(path string) Option {
return func(o *options) {
o.path = path
}
}
// WithLogger sets logger.
func WithLogger(log *logger.Logger) Option {
return func(o *options) {
o.log = &logger.Logger{Logger: log.With(zap.String("component", "WriteCache"))}
}
}
// WithBlobstor sets main object storage.
func WithBlobstor(bs writecache.MainStorage) Option {
return func(o *options) {
o.blobstor = bs
}
}
// WithMetabase sets metabase.
func WithMetabase(db writecache.Metabase) Option {
return func(o *options) {
o.metabase = db
}
}
// WithMetrics sets metrics implementation.
func WithMetrics(metrics writecache.Metrics) Option {
return func(o *options) {
o.metrics = metrics
}
}
// WithReportErrorFunc sets error reporting function.
func WithReportErrorFunc(f func(string, error)) Option {
return func(o *options) {
o.reportError = f
}
}
// WithMaxObjectSize sets maximum object size to be stored in write-cache.
func WithMaxObjectSize(sz uint64) Option {
return func(o *options) {
if sz > 0 {
o.maxObjectSize = sz
}
}
}
// WithBucketCount sets the number of buckets to use.
//
// This value determines the total number of buckets to use by the internal hash table.
// More buckets means fewer collisions but also increased memory usage.
//
// Default value is 2^16.
func WithBucketCount(bucketCount int) Option {
return func(o *options) {
o.bucketCount = bucketCount
}
}
// WithRegionCount sets the number of regions to use.
//
// This is the number of independent partitions of the key space. Each region contains its
// own lock, key directory, membuffer, log files and flushing process.
//
// Default value is 4.
func WithRegionCount(regionCount int) Option {
return func(o *options) {
o.regionCount = regionCount
}
}
// WithLogFileSize sets the maximum size of a log file.
//
// After a log file grows to this size, it will be closed and passed to the flushing process.
//
// Default value is 64 MiB.
func WithLogFileSize(logSize uint64) Option {
return func(o *options) {
o.maxLogSize = logSize
}
}
// WithMaxBatchDelay sets for how long to keep current write batch.
//
// Any pending write batch will be flushed to the current log file after at most this duration.
// This helps minimize the number of sync IO operations under heavy load.
//
// Default value is 1ms.
func WithMaxBatchDelay(d time.Duration) Option {
return func(o *options) {
o.maxBatchDelay = d
}
}
// WithMaxPendingLogFileFlush sets the maximum number of pending log files to be flushed per region.
//
// This is the maximum size of the queue of log files for the flushing process. After this many
// files are enqueued for flushing, requests will block until the flushing process can keep up.
//
// Default value is 4.
func WithMaxPendingLogFileFlush(n int) Option {
return func(o *options) {
o.maxPendingLogFileFlush = n
}
}