diff --git a/cmd/frostfs-cli/modules/control/writecache.go b/cmd/frostfs-cli/modules/control/writecache.go index abc4ed2e6..a665ccae8 100644 --- a/cmd/frostfs-cli/modules/control/writecache.go +++ b/cmd/frostfs-cli/modules/control/writecache.go @@ -9,6 +9,8 @@ import ( "github.com/spf13/cobra" ) +const restoreModeFlag = "restore-mode" + var writecacheShardCmd = &cobra.Command{ Use: "writecache", Short: "Operations with storage node's write-cache", @@ -26,10 +28,12 @@ func sealWritecache(cmd *cobra.Command, _ []string) { pk := key.Get(cmd) ignoreErrors, _ := cmd.Flags().GetBool(ignoreErrorsFlag) + restoreMode, _ := cmd.Flags().GetBool(restoreModeFlag) req := &control.SealWriteCacheRequest{Body: &control.SealWriteCacheRequest_Body{ Shard_ID: getShardIDList(cmd), IgnoreErrors: ignoreErrors, + RestoreMode: restoreMode, }} signRequest(cmd, pk, req) @@ -68,6 +72,7 @@ func initControlShardsWritecacheCmd() { ff.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding") ff.Bool(shardAllFlag, false, "Process all shards") ff.Bool(ignoreErrorsFlag, true, "Skip invalid/unreadable objects") + ff.Bool(restoreModeFlag, false, "Restore writecache's mode after sealing") sealWritecacheShardCmd.MarkFlagsMutuallyExclusive(shardIDFlag, shardAllFlag) } diff --git a/pkg/local_object_storage/engine/writecache.go b/pkg/local_object_storage/engine/writecache.go index da488260a..8f37d7860 100644 --- a/pkg/local_object_storage/engine/writecache.go +++ b/pkg/local_object_storage/engine/writecache.go @@ -70,6 +70,7 @@ func (e *StorageEngine) FlushWriteCache(ctx context.Context, p FlushWriteCachePr type SealWriteCachePrm struct { ShardIDs []*shard.ID IgnoreErrors bool + RestoreMode bool } type ShardSealResult struct { @@ -88,6 +89,7 @@ func (e *StorageEngine) SealWriteCache(ctx context.Context, prm SealWriteCachePr trace.WithAttributes( attribute.Int("shard_id_count", len(prm.ShardIDs)), attribute.Bool("ignore_errors", prm.IgnoreErrors), + attribute.Bool("restore_mode", prm.RestoreMode), )) defer span.End() @@ -114,7 +116,7 @@ func (e *StorageEngine) SealWriteCache(ctx context.Context, prm SealWriteCachePr return nil } - err := sh.SealWriteCache(egCtx, shard.SealWriteCachePrm{IgnoreErrors: prm.IgnoreErrors}) + err := sh.SealWriteCache(egCtx, shard.SealWriteCachePrm{IgnoreErrors: prm.IgnoreErrors, RestoreMode: prm.RestoreMode}) resGuard.Lock() defer resGuard.Unlock() diff --git a/pkg/local_object_storage/shard/writecache.go b/pkg/local_object_storage/shard/writecache.go index 05e014d29..9edad7170 100644 --- a/pkg/local_object_storage/shard/writecache.go +++ b/pkg/local_object_storage/shard/writecache.go @@ -4,6 +4,7 @@ import ( "context" "errors" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -59,6 +60,7 @@ func (s *Shard) FlushWriteCache(ctx context.Context, p FlushWriteCachePrm) error type SealWriteCachePrm struct { IgnoreErrors bool + RestoreMode bool } // SealWriteCache flushes all data from the write-cache and moves it to degraded read only mode. @@ -67,6 +69,7 @@ func (s *Shard) SealWriteCache(ctx context.Context, p SealWriteCachePrm) error { trace.WithAttributes( attribute.String("shard_id", s.ID().String()), attribute.Bool("ignore_errors", p.IgnoreErrors), + attribute.Bool("restore_mode", p.RestoreMode), )) defer span.End() @@ -84,5 +87,5 @@ func (s *Shard) SealWriteCache(ctx context.Context, p SealWriteCachePrm) error { return ErrDegradedMode } - return s.writeCache.Seal(ctx, p.IgnoreErrors) + return s.writeCache.Seal(ctx, writecache.SealPrm{IgnoreErrors: p.IgnoreErrors, RestoreMode: p.RestoreMode}) } diff --git a/pkg/local_object_storage/writecache/seal.go b/pkg/local_object_storage/writecache/seal.go index 48107a75f..22b4e0988 100644 --- a/pkg/local_object_storage/writecache/seal.go +++ b/pkg/local_object_storage/writecache/seal.go @@ -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 } diff --git a/pkg/local_object_storage/writecache/writecache.go b/pkg/local_object_storage/writecache/writecache.go index 71dba61cf..7085a57b2 100644 --- a/pkg/local_object_storage/writecache/writecache.go +++ b/pkg/local_object_storage/writecache/writecache.go @@ -20,6 +20,11 @@ type Info struct { Path string } +type SealPrm struct { + IgnoreErrors bool + RestoreMode bool +} + // Cache represents write-cache for objects. type Cache interface { Get(ctx context.Context, address oid.Address) (*objectSDK.Object, error) @@ -36,7 +41,7 @@ type Cache interface { SetLogger(*logger.Logger) DumpInfo() Info Flush(context.Context, bool, bool) error - Seal(context.Context, bool) error + Seal(context.Context, SealPrm) error Init() error Open(ctx context.Context, mode mode.Mode) error diff --git a/pkg/services/control/ir/service_grpc.pb.go b/pkg/services/control/ir/service_grpc.pb.go index 724149c44..336bf5f70 100644 Binary files a/pkg/services/control/ir/service_grpc.pb.go and b/pkg/services/control/ir/service_grpc.pb.go differ diff --git a/pkg/services/control/server/seal_writecache.go b/pkg/services/control/server/seal_writecache.go index e3f8b8caf..b663cfc81 100644 --- a/pkg/services/control/server/seal_writecache.go +++ b/pkg/services/control/server/seal_writecache.go @@ -19,6 +19,7 @@ func (s *Server) SealWriteCache(ctx context.Context, req *control.SealWriteCache prm := engine.SealWriteCachePrm{ ShardIDs: s.getShardIDList(req.GetBody().GetShard_ID()), IgnoreErrors: req.GetBody().GetIgnoreErrors(), + RestoreMode: req.GetBody().GetRestoreMode(), } res, err := s.s.SealWriteCache(ctx, prm) diff --git a/pkg/services/control/service.pb.go b/pkg/services/control/service.pb.go index 727dd1218..895b74368 100644 Binary files a/pkg/services/control/service.pb.go and b/pkg/services/control/service.pb.go differ diff --git a/pkg/services/control/service.proto b/pkg/services/control/service.proto index 2cd8434fc..a10410025 100644 --- a/pkg/services/control/service.proto +++ b/pkg/services/control/service.proto @@ -655,6 +655,9 @@ message SealWriteCacheRequest { // Flag indicating whether object read errors should be ignored. bool ignore_errors = 2; + + // If true, then writecache will be sealed, but mode will be restored to the current one. + bool restore_mode = 4; } Body body = 1; diff --git a/pkg/services/control/service_frostfs.pb.go b/pkg/services/control/service_frostfs.pb.go index a287606fa..b6b064973 100644 Binary files a/pkg/services/control/service_frostfs.pb.go and b/pkg/services/control/service_frostfs.pb.go differ diff --git a/pkg/services/tree/service_grpc.pb.go b/pkg/services/tree/service_grpc.pb.go index 4c293a4c0..63f96e11a 100644 Binary files a/pkg/services/tree/service_grpc.pb.go and b/pkg/services/tree/service_grpc.pb.go differ