frostfs-node/pkg/local_object_storage/writecache/seal.go
Dmitrii Stepanov 5c01bd5be8 [#1298] writecache: Add restore-mode flag for Seal command
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-08-07 11:20:14 +03:00

37 lines
962 B
Go

package writecache
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
func (c *cache) Seal(ctx context.Context, prm SealPrm) error {
ctx, span := tracing.StartSpanFromContext(ctx, "writecache.Seal",
trace.WithAttributes(
attribute.Bool("ignore_errors", prm.IgnoreErrors),
attribute.Bool("restore_mode", prm.RestoreMode),
))
defer span.End()
c.modeMtx.Lock()
defer c.modeMtx.Unlock()
sourceMode := c.mode
// flush will be done by setMode
err := c.setMode(ctx, mode.DegradedReadOnly, prm.IgnoreErrors)
if err != nil {
return err
}
c.metrics.SetMode(mode.ComponentDisabled)
if prm.RestoreMode {
err = c.setMode(ctx, sourceMode, prm.IgnoreErrors)
if err == nil {
c.metrics.SetMode(mode.ConvertToComponentMode(sourceMode))
}
}
return err
}