diff --git a/CHANGELOG.md b/CHANGELOG.md index 502981d05d..cf88105e81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Changelog for NeoFS Node - Changelog updates CI step (#1808) - Validate storage node configuration before node startup (#1805) - `neofs-node -check` command to check the configuration file (#1805) +- `flush-cache` control service command to flush write-cache (#1806) ### Changed diff --git a/cmd/neofs-cli/modules/control/flush_cache.go b/cmd/neofs-cli/modules/control/flush_cache.go new file mode 100644 index 0000000000..49948cfeeb --- /dev/null +++ b/cmd/neofs-cli/modules/control/flush_cache.go @@ -0,0 +1,50 @@ +package control + +import ( + "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" + "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" + "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" + "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" + "github.com/nspcc-dev/neofs-node/pkg/services/control" + "github.com/spf13/cobra" +) + +var flushCacheCmd = &cobra.Command{ + Use: "flush-cache", + Short: "Flush objects from the write-cache to the main storage", + Long: "Flush objects from the write-cache to the main storage", + Run: flushCache, +} + +func flushCache(cmd *cobra.Command, _ []string) { + pk := key.Get(cmd) + + req := &control.FlushCacheRequest{Body: new(control.FlushCacheRequest_Body)} + req.Body.Shard_ID = getShardID(cmd) + + signRequest(cmd, pk, req) + + cli := getClient(cmd, pk) + + var resp *control.FlushCacheResponse + var err error + err = cli.ExecRaw(func(client *client.Client) error { + resp, err = control.FlushCache(client, req) + return err + }) + common.ExitOnErr(cmd, "rpc error: %w", err) + + verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + + cmd.Println("Write-cache has been flushed.") +} + +func initControlFlushCacheCmd() { + commonflags.InitWithoutRPC(flushCacheCmd) + + ff := flushCacheCmd.Flags() + ff.String(controlRPC, controlRPCDefault, controlRPCUsage) + ff.String(shardIDFlag, "", "Shard ID in base58 encoding") + + _ = flushCacheCmd.MarkFlagRequired(shardIDFlag) +} diff --git a/cmd/neofs-cli/modules/control/shards.go b/cmd/neofs-cli/modules/control/shards.go index 228703ea72..6719a4acf8 100644 --- a/cmd/neofs-cli/modules/control/shards.go +++ b/cmd/neofs-cli/modules/control/shards.go @@ -16,10 +16,12 @@ func initControlShardsCmd() { shardsCmd.AddCommand(dumpShardCmd) shardsCmd.AddCommand(restoreShardCmd) shardsCmd.AddCommand(evacuateShardCmd) + shardsCmd.AddCommand(flushCacheCmd) initControlShardsListCmd() initControlSetShardModeCmd() initControlDumpShardCmd() initControlRestoreShardCmd() initControlEvacuateShardCmd() + initControlFlushCacheCmd() }