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 } }