[#1298] writecache: Add restore-mode flag for Seal command

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-08-06 13:20:33 +03:00
parent 8e51d7849a
commit 5c01bd5be8
11 changed files with 238 additions and 205 deletions

View file

@ -9,20 +9,29 @@ import (
"go.opentelemetry.io/otel/trace"
)
func (c *cache) Seal(ctx context.Context, ignoreErrors bool) error {
func (c *cache) Seal(ctx context.Context, prm SealPrm) error {
ctx, span := tracing.StartSpanFromContext(ctx, "writecache.Seal",
trace.WithAttributes(
attribute.Bool("ignore_errors", ignoreErrors),
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, ignoreErrors)
if err == nil {
c.metrics.SetMode(mode.ComponentDisabled)
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
}