2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2021-02-17 12:27:40 +00:00
|
|
|
"context"
|
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"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2023-11-02 10:50:52 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2023-03-07 13:38:26 +00:00
|
|
|
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
|
|
|
|
|
2024-07-31 13:30:07 +00:00
|
|
|
gcCancel atomic.Value
|
|
|
|
setModeRequested atomic.Bool
|
|
|
|
writecacheSealCancel atomic.Pointer[writecacheSealCanceler]
|
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)
|
|
|
|
|
2023-12-27 15:23:12 +00:00
|
|
|
// EmptyContainersCallback is a callback hanfling list of zero-size and zero-count containers.
|
|
|
|
type EmptyContainersCallback func(context.Context, []cid.ID)
|
2023-12-27 15:58:36 +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
|
|
|
|
2024-03-05 12:39:50 +00:00
|
|
|
refillMetabase bool
|
|
|
|
refillMetabaseWorkersCount int
|
2021-09-13 13:56:07 +00:00
|
|
|
|
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-12-22 09:58:20 +00:00
|
|
|
writeCacheOpts []writecache.Option
|
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
|
|
|
|
|
2023-12-27 15:23:12 +00:00
|
|
|
zeroSizeContainersCallback EmptyContainersCallback
|
|
|
|
zeroCountContainersCallback EmptyContainersCallback
|
2023-12-27 15:58:36 +00:00
|
|
|
|
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{
|
2023-12-27 15:23:12 +00:00
|
|
|
rmBatchSize: 100,
|
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
|
|
|
gcCfg: defaultGCCfg(),
|
|
|
|
reportErrorFunc: func(string, string, error) {},
|
|
|
|
zeroSizeContainersCallback: func(context.Context, []cid.ID) {},
|
|
|
|
zeroCountContainersCallback: func(context.Context, []cid.ID) {},
|
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-12-22 09:58:20 +00:00
|
|
|
s.writeCache = writecache.New(
|
|
|
|
append(c.writeCacheOpts,
|
|
|
|
writecache.WithReportErrorFunc(reportFunc),
|
|
|
|
writecache.WithBlobstor(bs),
|
|
|
|
writecache.WithMetabase(mb))...)
|
2024-04-27 12:49:07 +00:00
|
|
|
s.writeCache.GetMetrics().SetPath(s.writeCache.DumpInfo().Path)
|
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()
|
2024-07-31 13:30:07 +00:00
|
|
|
s.writecacheSealCancel.Store(notInitializedCancel)
|
2021-12-20 10:03:06 +00:00
|
|
|
|
|
|
|
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-12-22 09:58:20 +00:00
|
|
|
func WithWriteCacheOptions(opts []writecache.Option) 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-12-22 09:58:20 +00:00
|
|
|
c.writeCacheOpts = append(c.writeCacheOpts, writecache.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
|
|
|
|
2024-03-05 12:39:50 +00:00
|
|
|
// WithRefillMetabaseWorkersCount returns option to set count of workers to refill the Metabase on Shard's initialization step.
|
|
|
|
func WithRefillMetabaseWorkersCount(v int) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.refillMetabaseWorkersCount = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-21 10:20:36 +00:00
|
|
|
// WithExpiredCollectorWorkerCount returns option to set concurrent
|
2023-03-17 08:06:15 +00:00
|
|
|
// workers count of expired object collection operation.
|
2023-11-21 10:20:36 +00:00
|
|
|
func WithExpiredCollectorWorkerCount(count int) Option {
|
2023-03-17 08:06:15 +00:00
|
|
|
return func(c *cfg) {
|
2023-11-21 10:20:36 +00:00
|
|
|
c.gcCfg.expiredCollectorWorkerCount = count
|
2023-03-17 08:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-10 08:56:24 +00:00
|
|
|
// WithDisabledGC disables GC.
|
|
|
|
// For testing purposes only.
|
|
|
|
func WithDisabledGC() Option {
|
|
|
|
return func(c *cfg) {
|
2024-03-11 14:11:49 +00:00
|
|
|
c.gcCfg.testHookRemover = func(_ context.Context) gcRunResult { return gcRunResult{} }
|
2024-01-10 08:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-27 15:58:36 +00:00
|
|
|
// WithZeroSizeCallback returns option to set zero-size containers callback.
|
2023-12-27 15:23:12 +00:00
|
|
|
func WithZeroSizeCallback(cb EmptyContainersCallback) Option {
|
2023-12-27 15:58:36 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.zeroSizeContainersCallback = cb
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-27 15:23:12 +00:00
|
|
|
// WithZeroCountCallback returns option to set zero-count containers callback.
|
|
|
|
func WithZeroCountCallback(cb EmptyContainersCallback) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.zeroCountContainersCallback = cb
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-12-04 14:35:11 +00:00
|
|
|
// user is an available small or big regular object.
|
|
|
|
user = "user"
|
2022-09-09 11:36:34 +00:00
|
|
|
)
|
|
|
|
|
2023-06-06 09:27:19 +00:00
|
|
|
func (s *Shard) updateMetrics(ctx context.Context) {
|
2023-12-04 09:54:23 +00:00
|
|
|
if s.cfg.metricsWriter == nil || s.GetMode().NoMetabase() {
|
|
|
|
return
|
|
|
|
}
|
2022-08-19 17:24:05 +00:00
|
|
|
|
2023-12-04 09:54:23 +00:00
|
|
|
cc, err := s.metaBase.ObjectCounters()
|
|
|
|
if err != nil {
|
|
|
|
s.log.Warn(logs.ShardMetaObjectCounterRead,
|
|
|
|
zap.Error(err),
|
|
|
|
)
|
2022-08-19 17:24:05 +00:00
|
|
|
|
2023-12-04 09:54:23 +00:00
|
|
|
return
|
|
|
|
}
|
2022-12-01 11:59:22 +00:00
|
|
|
|
2024-01-30 08:37:06 +00:00
|
|
|
s.setObjectCounterBy(physical, cc.Phy)
|
|
|
|
s.setObjectCounterBy(logical, cc.Logic)
|
|
|
|
s.setObjectCounterBy(user, cc.User)
|
2022-12-01 11:59:22 +00:00
|
|
|
|
2023-12-04 09:54:23 +00:00
|
|
|
cnrList, err := s.metaBase.Containers(ctx)
|
|
|
|
if err != nil {
|
|
|
|
s.log.Warn(logs.ShardMetaCantReadContainerList, zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
2023-01-25 14:01:25 +00:00
|
|
|
|
2023-12-04 09:54:23 +00:00
|
|
|
var totalPayload uint64
|
2023-11-02 10:50:52 +00:00
|
|
|
|
2023-12-04 09:54:23 +00:00
|
|
|
for i := range cnrList {
|
|
|
|
size, err := s.metaBase.ContainerSize(cnrList[i])
|
2023-11-02 10:50:52 +00:00
|
|
|
if err != nil {
|
2023-12-04 09:54:23 +00:00
|
|
|
s.log.Warn(logs.ShardMetaCantReadContainerSize,
|
|
|
|
zap.String("cid", cnrList[i].EncodeToString()),
|
|
|
|
zap.Error(err))
|
|
|
|
continue
|
2023-11-02 10:50:52 +00:00
|
|
|
}
|
2024-01-30 08:37:06 +00:00
|
|
|
s.addToContainerSize(cnrList[i].EncodeToString(), int64(size))
|
2023-12-04 09:54:23 +00:00
|
|
|
totalPayload += size
|
|
|
|
}
|
|
|
|
|
2024-01-30 08:37:06 +00:00
|
|
|
s.addToPayloadSize(int64(totalPayload))
|
2023-12-04 09:54:23 +00:00
|
|
|
|
|
|
|
contCount, err := s.metaBase.ContainerCounters(ctx)
|
|
|
|
if err != nil {
|
|
|
|
s.log.Warn(logs.FailedToGetContainerCounters, zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
2023-12-04 14:35:11 +00:00
|
|
|
for contID, count := range contCount.Counts {
|
2024-01-30 08:37:06 +00:00
|
|
|
s.setContainerObjectsCount(contID.EncodeToString(), physical, count.Phy)
|
|
|
|
s.setContainerObjectsCount(contID.EncodeToString(), logical, count.Logic)
|
|
|
|
s.setContainerObjectsCount(contID.EncodeToString(), user, count.User)
|
2022-08-19 17:24:05 +00:00
|
|
|
}
|
2024-06-13 07:10:55 +00:00
|
|
|
s.cfg.metricsWriter.SetMode(s.info.Mode)
|
2022-08-19 17:24:05 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
// incObjectCounter increment both physical and logical object
|
|
|
|
// counters.
|
2023-12-05 14:00:16 +00:00
|
|
|
func (s *Shard) incObjectCounter(cnrID cid.ID, isUser bool) {
|
2022-08-19 16:49:09 +00:00
|
|
|
if s.cfg.metricsWriter != nil {
|
2022-09-09 11:36:34 +00:00
|
|
|
s.cfg.metricsWriter.IncObjectCounter(physical)
|
|
|
|
s.cfg.metricsWriter.IncObjectCounter(logical)
|
2023-11-02 10:50:52 +00:00
|
|
|
s.cfg.metricsWriter.IncContainerObjectsCount(cnrID.EncodeToString(), physical)
|
|
|
|
s.cfg.metricsWriter.IncContainerObjectsCount(cnrID.EncodeToString(), logical)
|
2023-12-05 14:00:16 +00:00
|
|
|
if isUser {
|
|
|
|
s.cfg.metricsWriter.IncObjectCounter(user)
|
|
|
|
s.cfg.metricsWriter.IncContainerObjectsCount(cnrID.EncodeToString(), user)
|
|
|
|
}
|
2022-08-19 16:49:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
func (s *Shard) decObjectCounterBy(typ string, v uint64) {
|
2024-01-30 08:37:06 +00:00
|
|
|
if s.cfg.metricsWriter != nil && v > 0 {
|
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
|
|
|
|
2024-01-30 08:37:06 +00:00
|
|
|
func (s *Shard) setObjectCounterBy(typ string, v uint64) {
|
|
|
|
if s.cfg.metricsWriter != nil && v > 0 {
|
|
|
|
s.cfg.metricsWriter.SetObjectCounter(typ, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 10:50:52 +00:00
|
|
|
func (s *Shard) decContainerObjectCounter(byCnr map[cid.ID]meta.ObjectCounters) {
|
|
|
|
if s.cfg.metricsWriter == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for cnrID, count := range byCnr {
|
2024-01-30 08:37:06 +00:00
|
|
|
if count.Phy > 0 {
|
|
|
|
s.cfg.metricsWriter.SubContainerObjectsCount(cnrID.EncodeToString(), physical, count.Phy)
|
|
|
|
}
|
|
|
|
if count.Logic > 0 {
|
|
|
|
s.cfg.metricsWriter.SubContainerObjectsCount(cnrID.EncodeToString(), logical, count.Logic)
|
|
|
|
}
|
|
|
|
if count.User > 0 {
|
|
|
|
s.cfg.metricsWriter.SubContainerObjectsCount(cnrID.EncodeToString(), user, count.User)
|
|
|
|
}
|
2023-11-02 10:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 11:59:22 +00:00
|
|
|
func (s *Shard) addToContainerSize(cnr string, size int64) {
|
2024-01-30 08:37:06 +00:00
|
|
|
if s.cfg.metricsWriter != nil && size != 0 {
|
2022-12-01 11:59:22 +00:00
|
|
|
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) {
|
2024-01-30 08:37:06 +00:00
|
|
|
if s.cfg.metricsWriter != nil && size != 0 {
|
2023-01-25 14:01:25 +00:00
|
|
|
s.cfg.metricsWriter.AddToPayloadSize(size)
|
|
|
|
}
|
|
|
|
}
|
2023-06-01 14:28:04 +00:00
|
|
|
|
2024-01-30 08:37:06 +00:00
|
|
|
func (s *Shard) setContainerObjectsCount(cnr string, typ string, v uint64) {
|
|
|
|
if s.cfg.metricsWriter != nil && v > 0 {
|
|
|
|
s.metricsWriter.SetContainerObjectsCount(cnr, typ, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2024-09-03 09:18:10 +00:00
|
|
|
|
|
|
|
func (s *Shard) SetEvacuationInProgress(val bool) {
|
|
|
|
s.m.Lock()
|
|
|
|
defer s.m.Unlock()
|
|
|
|
s.info.EvacuationInProgress = val
|
|
|
|
if s.metricsWriter != nil {
|
|
|
|
s.metricsWriter.SetEvacuationInProgress(val)
|
|
|
|
}
|
|
|
|
}
|