2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2021-02-17 12:27:40 +00:00
|
|
|
"context"
|
2023-06-22 11:55:30 +00:00
|
|
|
"fmt"
|
2021-12-27 18:07:02 +00:00
|
|
|
"sync"
|
2023-05-23 12:02:38 +00:00
|
|
|
"sync/atomic"
|
2021-02-16 11:34:48 +00:00
|
|
|
"time"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
2023-06-22 11:55:30 +00:00
|
|
|
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebadger"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2021-02-16 11:34:48 +00:00
|
|
|
"go.uber.org/zap"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// Shard represents single shard of FrostFS Local Storage Engine.
|
2020-11-17 12:23:15 +00:00
|
|
|
type Shard struct {
|
|
|
|
*cfg
|
|
|
|
|
2021-08-04 12:04:37 +00:00
|
|
|
gc *gc
|
|
|
|
|
2021-04-06 10:56:06 +00:00
|
|
|
writeCache writecache.Cache
|
2020-12-01 07:35:25 +00:00
|
|
|
|
2020-11-17 17:39:43 +00:00
|
|
|
blobStor *blobstor.BlobStor
|
|
|
|
|
2022-04-22 13:29:43 +00:00
|
|
|
pilorama pilorama.ForestStorage
|
|
|
|
|
2020-11-17 17:39:43 +00:00
|
|
|
metaBase *meta.DB
|
2022-04-19 18:00:22 +00:00
|
|
|
|
|
|
|
tsSource TombstoneSource
|
2023-05-23 12:02:38 +00:00
|
|
|
|
2023-09-19 10:50:14 +00:00
|
|
|
rb *rebuilder
|
|
|
|
|
2023-05-23 12:02:38 +00:00
|
|
|
gcCancel atomic.Value
|
|
|
|
setModeRequested atomic.Bool
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Option represents Shard's constructor option.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
// ExpiredTombstonesCallback is a callback handling list of expired tombstones.
|
|
|
|
type ExpiredTombstonesCallback func(context.Context, []meta.TombstonedObject)
|
|
|
|
|
2021-02-17 12:27:40 +00:00
|
|
|
// ExpiredObjectsCallback is a callback handling list of expired objects.
|
2023-03-28 08:17:15 +00:00
|
|
|
type ExpiredObjectsCallback func(context.Context, uint64, []oid.Address)
|
2021-02-17 12:27:40 +00:00
|
|
|
|
2022-05-26 17:38:32 +00:00
|
|
|
// DeletedLockCallback is a callback handling list of deleted LOCK objects.
|
|
|
|
type DeletedLockCallback func(context.Context, []oid.Address)
|
|
|
|
|
2022-08-19 16:49:09 +00:00
|
|
|
// MetricsWriter is an interface that must store shard's metrics.
|
|
|
|
type MetricsWriter interface {
|
2022-09-09 11:36:34 +00:00
|
|
|
// SetObjectCounter must set object counter taking into account object type.
|
|
|
|
SetObjectCounter(objectType string, v uint64)
|
|
|
|
// AddToObjectCounter must update object counter taking into account object
|
|
|
|
// type.
|
|
|
|
// Negative parameter must decrease the counter.
|
|
|
|
AddToObjectCounter(objectType string, delta int)
|
2022-12-01 11:59:22 +00:00
|
|
|
// AddToContainerSize must add a value to the container size.
|
|
|
|
// Value can be negative.
|
|
|
|
AddToContainerSize(cnr string, value int64)
|
2023-01-25 14:01:25 +00:00
|
|
|
// AddToPayloadSize must add a value to the payload size.
|
|
|
|
// Value can be negative.
|
|
|
|
AddToPayloadSize(value int64)
|
2022-09-09 11:36:34 +00:00
|
|
|
// IncObjectCounter must increment shard's object counter taking into account
|
|
|
|
// object type.
|
|
|
|
IncObjectCounter(objectType string)
|
|
|
|
// DecObjectCounter must decrement shard's object counter taking into account
|
|
|
|
// object type.
|
|
|
|
DecObjectCounter(objectType string)
|
2022-10-12 17:55:35 +00:00
|
|
|
// SetShardID must set (update) the shard identifier that will be used in
|
|
|
|
// metrics.
|
|
|
|
SetShardID(id string)
|
2023-06-14 08:00:44 +00:00
|
|
|
// SetReadonly must set shard mode.
|
|
|
|
SetMode(mode mode.Mode)
|
2023-06-01 14:28:04 +00:00
|
|
|
// IncErrorCounter increment error counter.
|
|
|
|
IncErrorCounter()
|
|
|
|
// ClearErrorCounter clear error counter.
|
|
|
|
ClearErrorCounter()
|
2023-06-13 16:48:15 +00:00
|
|
|
// DeleteShardMetrics deletes shard metrics from registry.
|
|
|
|
DeleteShardMetrics()
|
2022-08-19 16:49:09 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 12:23:15 +00:00
|
|
|
type cfg struct {
|
2021-12-27 18:07:02 +00:00
|
|
|
m sync.RWMutex
|
2021-12-27 11:04:07 +00:00
|
|
|
|
2021-09-13 13:56:07 +00:00
|
|
|
refillMetabase bool
|
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
rmBatchSize int
|
|
|
|
|
2020-11-30 16:55:21 +00:00
|
|
|
useWriteCache bool
|
|
|
|
|
2020-11-19 13:53:45 +00:00
|
|
|
info Info
|
2020-11-17 17:39:43 +00:00
|
|
|
|
|
|
|
blobOpts []blobstor.Option
|
|
|
|
|
|
|
|
metaOpts []meta.Option
|
|
|
|
|
2023-06-22 11:55:30 +00:00
|
|
|
writeCacheOpts writecacheconfig.Options
|
2020-12-01 09:26:19 +00:00
|
|
|
|
2022-06-09 08:09:18 +00:00
|
|
|
piloramaOpts []pilorama.Option
|
|
|
|
|
2020-11-17 17:39:43 +00:00
|
|
|
log *logger.Logger
|
2021-02-16 11:34:48 +00:00
|
|
|
|
2022-10-16 12:07:38 +00:00
|
|
|
gcCfg gcCfg
|
2021-02-17 12:27:40 +00:00
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
expiredTombstonesCallback ExpiredTombstonesCallback
|
2022-03-10 17:58:58 +00:00
|
|
|
|
|
|
|
expiredLocksCallback ExpiredObjectsCallback
|
2022-04-19 18:00:22 +00:00
|
|
|
|
2022-05-26 17:38:32 +00:00
|
|
|
deletedLockCallBack DeletedLockCallback
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
tsSource TombstoneSource
|
2022-08-19 16:49:09 +00:00
|
|
|
|
|
|
|
metricsWriter MetricsWriter
|
2022-10-20 10:40:25 +00:00
|
|
|
|
|
|
|
reportErrorFunc func(selfID string, message string, err error)
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
2021-02-16 11:34:48 +00:00
|
|
|
return &cfg{
|
2022-10-20 10:40:25 +00:00
|
|
|
rmBatchSize: 100,
|
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
|
|
|
gcCfg: defaultGCCfg(),
|
|
|
|
reportErrorFunc: func(string, string, error) {},
|
2021-02-16 11:34:48 +00:00
|
|
|
}
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns new Shard instance.
|
|
|
|
func New(opts ...Option) *Shard {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
2021-04-06 10:56:06 +00:00
|
|
|
bs := blobstor.New(c.blobOpts...)
|
|
|
|
mb := meta.New(c.metaOpts...)
|
2020-12-01 07:35:25 +00:00
|
|
|
|
2022-10-20 10:40:25 +00:00
|
|
|
s := &Shard{
|
|
|
|
cfg: c,
|
|
|
|
blobStor: bs,
|
|
|
|
metaBase: mb,
|
|
|
|
tsSource: c.tsSource,
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:59:24 +00:00
|
|
|
reportFunc := func(msg string, err error) {
|
|
|
|
s.reportErrorFunc(s.ID().String(), msg, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.blobStor.SetReportErrorFunc(reportFunc)
|
|
|
|
|
2020-12-01 07:35:25 +00:00
|
|
|
if c.useWriteCache {
|
2023-06-22 11:55:30 +00:00
|
|
|
switch c.writeCacheOpts.Type {
|
|
|
|
case writecacheconfig.TypeBBolt:
|
|
|
|
s.writeCache = writecachebbolt.New(
|
|
|
|
append(c.writeCacheOpts.BBoltOptions,
|
|
|
|
writecachebbolt.WithReportErrorFunc(reportFunc),
|
|
|
|
writecachebbolt.WithBlobstor(bs),
|
|
|
|
writecachebbolt.WithMetabase(mb))...)
|
|
|
|
case writecacheconfig.TypeBadger:
|
|
|
|
s.writeCache = writecachebadger.New(
|
|
|
|
append(c.writeCacheOpts.BadgerOptions,
|
|
|
|
writecachebadger.WithReportErrorFunc(reportFunc),
|
|
|
|
writecachebadger.WithBlobstor(bs),
|
|
|
|
writecachebadger.WithMetabase(mb))...)
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("invalid writecache type: %v", c.writeCacheOpts.Type))
|
|
|
|
}
|
2020-12-01 07:35:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 10:16:23 +00:00
|
|
|
if s.piloramaOpts != nil {
|
|
|
|
s.pilorama = pilorama.NewBoltForest(c.piloramaOpts...)
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
2021-12-20 10:03:06 +00:00
|
|
|
|
|
|
|
s.fillInfo()
|
|
|
|
|
|
|
|
return s
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 08:59:05 +00:00
|
|
|
// WithID returns option to set the default shard identifier.
|
2020-11-17 12:23:15 +00:00
|
|
|
func WithID(id *ID) Option {
|
|
|
|
return func(c *cfg) {
|
2020-11-19 13:53:45 +00:00
|
|
|
c.info.ID = id
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-17 17:39:43 +00:00
|
|
|
|
|
|
|
// WithBlobStorOptions returns option to set internal BlobStor options.
|
2020-11-18 11:42:06 +00:00
|
|
|
func WithBlobStorOptions(opts ...blobstor.Option) Option {
|
2020-11-17 17:39:43 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.blobOpts = opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithMetaBaseOptions returns option to set internal metabase options.
|
2020-11-18 11:42:06 +00:00
|
|
|
func WithMetaBaseOptions(opts ...meta.Option) Option {
|
2020-11-17 17:39:43 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.metaOpts = opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-23 13:29:46 +00:00
|
|
|
// WithWriteCacheOptions returns option to set internal write cache options.
|
2023-06-22 11:55:30 +00:00
|
|
|
func WithWriteCacheOptions(opts writecacheconfig.Options) Option {
|
2020-12-01 09:26:19 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.writeCacheOpts = opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-22 11:55:30 +00:00
|
|
|
// WithWriteCacheMetrics returns an option to set the metrics register used by the write cache.
|
|
|
|
func WithWriteCacheMetrics(wcMetrics writecache.Metrics) Option {
|
2023-05-19 08:17:19 +00:00
|
|
|
return func(c *cfg) {
|
2023-06-22 11:55:30 +00:00
|
|
|
switch c.writeCacheOpts.Type {
|
|
|
|
case writecacheconfig.TypeBBolt:
|
|
|
|
c.writeCacheOpts.BBoltOptions = append(c.writeCacheOpts.BBoltOptions, writecachebbolt.WithMetrics(wcMetrics))
|
|
|
|
case writecacheconfig.TypeBadger:
|
|
|
|
c.writeCacheOpts.BadgerOptions = append(c.writeCacheOpts.BadgerOptions, writecachebadger.WithMetrics(wcMetrics))
|
|
|
|
}
|
2023-05-19 08:17:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-09 08:09:18 +00:00
|
|
|
// WithPiloramaOptions returns option to set internal write cache options.
|
|
|
|
func WithPiloramaOptions(opts ...pilorama.Option) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.piloramaOpts = opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 17:39:43 +00:00
|
|
|
// WithLogger returns option to set Shard's logger.
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l
|
2021-02-16 11:34:48 +00:00
|
|
|
c.gcCfg.log = l
|
2020-11-17 17:39:43 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-30 16:55:21 +00:00
|
|
|
|
|
|
|
// WithWriteCache returns option to toggle write cache usage.
|
|
|
|
func WithWriteCache(use bool) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.useWriteCache = use
|
|
|
|
}
|
|
|
|
}
|
2020-12-01 07:35:25 +00:00
|
|
|
|
2020-12-03 09:50:20 +00:00
|
|
|
// hasWriteCache returns bool if write cache exists on shards.
|
2023-05-23 12:02:38 +00:00
|
|
|
func (s *Shard) hasWriteCache() bool {
|
2020-12-01 07:35:25 +00:00
|
|
|
return s.cfg.useWriteCache
|
|
|
|
}
|
2021-02-16 11:34:48 +00:00
|
|
|
|
2023-06-22 07:46:56 +00:00
|
|
|
// NeedRefillMetabase returns true if metabase is needed to be refilled.
|
|
|
|
func (s *Shard) NeedRefillMetabase() bool {
|
2021-09-13 13:56:07 +00:00
|
|
|
return s.cfg.refillMetabase
|
|
|
|
}
|
|
|
|
|
2021-02-16 11:34:48 +00:00
|
|
|
// WithRemoverBatchSize returns option to set batch size
|
|
|
|
// of single removal operation.
|
|
|
|
func WithRemoverBatchSize(sz int) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.rmBatchSize = sz
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithGCWorkerPoolInitializer returns option to set initializer of
|
|
|
|
// worker pool with specified worker number.
|
|
|
|
func WithGCWorkerPoolInitializer(wpInit func(int) util.WorkerPool) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.gcCfg.workerPoolInit = wpInit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithGCRemoverSleepInterval returns option to specify sleep
|
|
|
|
// interval between object remover executions.
|
|
|
|
func WithGCRemoverSleepInterval(dur time.Duration) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.gcCfg.removerInterval = dur
|
|
|
|
}
|
|
|
|
}
|
2021-02-17 12:27:40 +00:00
|
|
|
|
2022-03-10 17:58:58 +00:00
|
|
|
// WithExpiredTombstonesCallback returns option to specify callback
|
2021-02-17 12:27:40 +00:00
|
|
|
// of the expired tombstones handler.
|
2022-04-19 18:00:22 +00:00
|
|
|
func WithExpiredTombstonesCallback(cb ExpiredTombstonesCallback) Option {
|
2021-02-17 12:27:40 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.expiredTombstonesCallback = cb
|
|
|
|
}
|
|
|
|
}
|
2021-09-13 13:56:07 +00:00
|
|
|
|
2022-03-10 17:58:58 +00:00
|
|
|
// WithExpiredLocksCallback returns option to specify callback
|
|
|
|
// of the expired LOCK objects handler.
|
|
|
|
func WithExpiredLocksCallback(cb ExpiredObjectsCallback) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.expiredLocksCallback = cb
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-13 13:56:07 +00:00
|
|
|
// WithRefillMetabase returns option to set flag to refill the Metabase on Shard's initialization step.
|
|
|
|
func WithRefillMetabase(v bool) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.refillMetabase = v
|
|
|
|
}
|
|
|
|
}
|
2021-12-20 10:03:06 +00:00
|
|
|
|
2021-12-27 11:04:07 +00:00
|
|
|
// WithMode returns option to set shard's mode. Mode must be one of the predefined:
|
2022-08-15 16:20:20 +00:00
|
|
|
// - mode.ReadWrite;
|
|
|
|
// - mode.ReadOnly.
|
2022-06-28 14:05:08 +00:00
|
|
|
func WithMode(v mode.Mode) Option {
|
2021-12-27 11:04:07 +00:00
|
|
|
return func(c *cfg) {
|
2021-12-27 18:07:02 +00:00
|
|
|
c.info.Mode = v
|
2021-12-27 11:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:00:22 +00:00
|
|
|
// WithTombstoneSource returns option to set TombstoneSource.
|
|
|
|
func WithTombstoneSource(v TombstoneSource) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.tsSource = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:01:21 +00:00
|
|
|
// WithDeletedLockCallback returns option to specify callback
|
2022-05-26 17:38:32 +00:00
|
|
|
// of the deleted LOCK objects handler.
|
2022-06-06 14:01:21 +00:00
|
|
|
func WithDeletedLockCallback(v DeletedLockCallback) Option {
|
2022-05-26 17:38:32 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.deletedLockCallBack = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 16:49:09 +00:00
|
|
|
// WithMetricsWriter returns option to specify storage of the
|
|
|
|
// shard's metrics.
|
|
|
|
func WithMetricsWriter(v MetricsWriter) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.metricsWriter = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-29 14:32:13 +00:00
|
|
|
// WithGCMetrics returns option to specify storage of the GC metrics.
|
|
|
|
func WithGCMetrics(v GCMectrics) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.gcCfg.metrics = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 10:40:25 +00:00
|
|
|
// WithReportErrorFunc returns option to specify callback for handling storage-related errors
|
|
|
|
// in the background workers.
|
|
|
|
func WithReportErrorFunc(f func(selfID string, message string, err error)) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.reportErrorFunc = f
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-17 08:06:15 +00:00
|
|
|
// WithExpiredCollectorBatchSize returns option to set batch size
|
|
|
|
// of expired object collection operation.
|
|
|
|
func WithExpiredCollectorBatchSize(size int) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.gcCfg.expiredCollectorBatchSize = size
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithExpiredCollectorWorkersCount returns option to set concurrent
|
|
|
|
// workers count of expired object collection operation.
|
|
|
|
func WithExpiredCollectorWorkersCount(count int) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.gcCfg.expiredCollectorWorkersCount = count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 10:03:06 +00:00
|
|
|
func (s *Shard) fillInfo() {
|
|
|
|
s.cfg.info.MetaBaseInfo = s.metaBase.DumpInfo()
|
|
|
|
s.cfg.info.BlobStorInfo = s.blobStor.DumpInfo()
|
2021-12-27 18:07:02 +00:00
|
|
|
s.cfg.info.Mode = s.GetMode()
|
2021-12-20 10:03:06 +00:00
|
|
|
|
|
|
|
if s.cfg.useWriteCache {
|
|
|
|
s.cfg.info.WriteCacheInfo = s.writeCache.DumpInfo()
|
|
|
|
}
|
2022-07-18 10:16:23 +00:00
|
|
|
if s.pilorama != nil {
|
|
|
|
s.cfg.info.PiloramaInfo = s.pilorama.DumpInfo()
|
|
|
|
}
|
2021-12-20 10:03:06 +00:00
|
|
|
}
|
2022-08-19 16:49:09 +00:00
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
const (
|
|
|
|
// physical is a physically stored object
|
2022-10-17 12:03:55 +00:00
|
|
|
// counter type.
|
2022-09-09 11:36:34 +00:00
|
|
|
physical = "phy"
|
|
|
|
|
|
|
|
// logical is a logically stored object
|
|
|
|
// counter type (excludes objects that are
|
2022-10-17 12:03:55 +00:00
|
|
|
// stored but unavailable).
|
2022-09-09 11:36:34 +00:00
|
|
|
logical = "logic"
|
|
|
|
)
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
func (s *Shard) updateMetrics(ctx context.Context) {
|
2022-08-19 17:24:05 +00:00
|
|
|
if s.cfg.metricsWriter != nil && !s.GetMode().NoMetabase() {
|
2022-09-09 11:36:34 +00:00
|
|
|
cc, err := s.metaBase.ObjectCounters()
|
2022-08-19 17:24:05 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
s.log.Warn(logs.ShardMetaObjectCounterRead,
|
2022-08-19 17:24:05 +00:00
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
s.cfg.metricsWriter.SetObjectCounter(physical, cc.Phy())
|
|
|
|
s.cfg.metricsWriter.SetObjectCounter(logical, cc.Logic())
|
2022-12-01 11:59:22 +00:00
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
cnrList, err := s.metaBase.Containers(ctx)
|
2022-12-01 11:59:22 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
s.log.Warn(logs.ShardMetaCantReadContainerList, zap.Error(err))
|
2022-12-01 11:59:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-25 14:01:25 +00:00
|
|
|
var totalPayload uint64
|
|
|
|
|
2022-12-01 11:59:22 +00:00
|
|
|
for i := range cnrList {
|
|
|
|
size, err := s.metaBase.ContainerSize(cnrList[i])
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
s.log.Warn(logs.ShardMetaCantReadContainerSize,
|
2022-12-01 11:59:22 +00:00
|
|
|
zap.String("cid", cnrList[i].EncodeToString()),
|
|
|
|
zap.Error(err))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
s.metricsWriter.AddToContainerSize(cnrList[i].EncodeToString(), int64(size))
|
2023-01-25 14:01:25 +00:00
|
|
|
totalPayload += size
|
2022-12-01 11:59:22 +00:00
|
|
|
}
|
2023-01-25 14:01:25 +00:00
|
|
|
|
|
|
|
s.metricsWriter.AddToPayloadSize(int64(totalPayload))
|
2022-08-19 17:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
// incObjectCounter increment both physical and logical object
|
|
|
|
// counters.
|
2022-08-19 16:49:09 +00:00
|
|
|
func (s *Shard) incObjectCounter() {
|
|
|
|
if s.cfg.metricsWriter != nil {
|
2022-09-09 11:36:34 +00:00
|
|
|
s.cfg.metricsWriter.IncObjectCounter(physical)
|
|
|
|
s.cfg.metricsWriter.IncObjectCounter(logical)
|
2022-08-19 16:49:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
func (s *Shard) decObjectCounterBy(typ string, v uint64) {
|
2022-08-19 16:49:09 +00:00
|
|
|
if s.cfg.metricsWriter != nil {
|
2022-09-09 11:36:34 +00:00
|
|
|
s.cfg.metricsWriter.AddToObjectCounter(typ, -int(v))
|
2022-08-19 16:49:09 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-01 11:59:22 +00:00
|
|
|
|
|
|
|
func (s *Shard) addToContainerSize(cnr string, size int64) {
|
|
|
|
if s.cfg.metricsWriter != nil {
|
|
|
|
s.cfg.metricsWriter.AddToContainerSize(cnr, size)
|
|
|
|
}
|
|
|
|
}
|
2023-01-25 14:01:25 +00:00
|
|
|
|
2023-02-07 11:28:28 +00:00
|
|
|
func (s *Shard) addToPayloadSize(size int64) {
|
2023-01-25 14:01:25 +00:00
|
|
|
if s.cfg.metricsWriter != nil {
|
|
|
|
s.cfg.metricsWriter.AddToPayloadSize(size)
|
|
|
|
}
|
|
|
|
}
|
2023-06-01 14:28:04 +00:00
|
|
|
|
|
|
|
func (s *Shard) IncErrorCounter() {
|
|
|
|
if s.cfg.metricsWriter != nil {
|
|
|
|
s.cfg.metricsWriter.IncErrorCounter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) ClearErrorCounter() {
|
|
|
|
if s.cfg.metricsWriter != nil {
|
|
|
|
s.cfg.metricsWriter.ClearErrorCounter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-13 16:48:15 +00:00
|
|
|
func (s *Shard) DeleteShardMetrics() {
|
2023-06-01 14:28:04 +00:00
|
|
|
if s.cfg.metricsWriter != nil {
|
2023-06-13 16:48:15 +00:00
|
|
|
s.cfg.metricsWriter.DeleteShardMetrics()
|
2023-06-01 14:28:04 +00:00
|
|
|
}
|
|
|
|
}
|