From 531542ce60a90a01ae04b63c54a92fede1b881c3 Mon Sep 17 00:00:00 2001 From: aarifullin Date: Fri, 29 Mar 2024 15:59:50 +0300 Subject: [PATCH] [#1063] cli: Validate container creation for EC policy Signed-off-by: Airat Arifullin --- cmd/frostfs-cli/modules/container/create.go | 28 +++++++++++++++------ cmd/frostfs-cli/modules/container/nodes.go | 10 +++++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/cmd/frostfs-cli/modules/container/create.go b/cmd/frostfs-cli/modules/container/create.go index 6d0ed750e..c6f576908 100644 --- a/cmd/frostfs-cli/modules/container/create.go +++ b/cmd/frostfs-cli/modules/container/create.go @@ -58,13 +58,27 @@ It will be stored in sidechain when inner ring will accepts it.`, "use --force option to skip this check: %w", err) for i, nodes := range nodesByRep { - if placementPolicy.ReplicaDescriptor(i).NumberOfObjects() > uint32(len(nodes)) { - commonCmd.ExitOnErr(cmd, "", fmt.Errorf( - "the number of nodes '%d' in selector is not enough for the number of replicas '%d', "+ - "use --force option to skip this check", - len(nodes), - placementPolicy.ReplicaDescriptor(i).NumberOfObjects(), - )) + if repNum := placementPolicy.ReplicaDescriptor(i).NumberOfObjects(); repNum > 0 { + if repNum > uint32(len(nodes)) { + commonCmd.ExitOnErr(cmd, "", fmt.Errorf( + "the number of nodes '%d' in selector is not enough for the number of replicas '%d', "+ + "use --force option to skip this check", + len(nodes), + repNum, + )) + } + } else if ecParts := placementPolicy.ReplicaDescriptor(i).TotalECPartCount(); ecParts > 0 { + if ecParts > uint32(len(nodes)) { + commonCmd.ExitOnErr(cmd, "", fmt.Errorf( + "the number of nodes '%d' in selector is not enough for EC placement '%d.%d', "+ + "use --force option to skip this check", + len(nodes), + placementPolicy.ReplicaDescriptor(i).GetECDataCount(), + placementPolicy.ReplicaDescriptor(i).GetECParityCount(), + )) + } + } else { + commonCmd.ExitOnErr(cmd, "%w", errors.New("no replication policy is set")) } } } diff --git a/cmd/frostfs-cli/modules/container/nodes.go b/cmd/frostfs-cli/modules/container/nodes.go index b8765061c..1ae8ab604 100644 --- a/cmd/frostfs-cli/modules/container/nodes.go +++ b/cmd/frostfs-cli/modules/container/nodes.go @@ -2,6 +2,7 @@ package container import ( "crypto/sha256" + "errors" internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags" @@ -46,7 +47,14 @@ var containerNodesCmd = &cobra.Command{ commonCmd.ExitOnErr(cmd, "could not build container nodes for given container: %w", err) for i := range cnrNodes { - cmd.Printf("Descriptor #%d, REP %d:\n", i+1, policy.ReplicaDescriptor(i).NumberOfObjects()) + if repNum := policy.ReplicaDescriptor(i).NumberOfObjects(); repNum > 0 { + cmd.Printf("Descriptor #%d, REP %d:\n", i+1, repNum) + } else if ecParts := policy.ReplicaDescriptor(i).TotalECPartCount(); ecParts > 0 { + cmd.Printf("Descriptor #%d, EC %d.%d:\n", i+1, policy.ReplicaDescriptor(i).GetECDataCount(), + policy.ReplicaDescriptor(i).GetECParityCount()) + } else { + commonCmd.ExitOnErr(cmd, "%w", errors.New("no replication policy is set")) + } for j := range cnrNodes[i] { commonCmd.PrettyPrintNodeInfo(cmd, cnrNodes[i][j], j, "\t", short) }