2023-12-27 11:37:22 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2024-08-06 10:20:33 +00:00
|
|
|
func (c *cache) Seal(ctx context.Context, prm SealPrm) error {
|
2023-12-27 11:37:22 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "writecache.Seal",
|
|
|
|
trace.WithAttributes(
|
2024-08-06 10:20:33 +00:00
|
|
|
attribute.Bool("ignore_errors", prm.IgnoreErrors),
|
|
|
|
attribute.Bool("restore_mode", prm.RestoreMode),
|
2023-12-27 11:37:22 +00:00
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
c.modeMtx.Lock()
|
|
|
|
defer c.modeMtx.Unlock()
|
|
|
|
|
2024-08-06 10:20:33 +00:00
|
|
|
sourceMode := c.mode
|
2023-12-27 11:37:22 +00:00
|
|
|
// flush will be done by setMode
|
2024-08-06 10:20:33 +00:00
|
|
|
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))
|
|
|
|
}
|
2023-12-27 11:37:22 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|