Skip to content

Commit

Permalink
Change the command args
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <ghzpotato@gmail.com>
  • Loading branch information
JmPotato committed Jul 10, 2023
1 parent 9e82c37 commit 4323127
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
10 changes: 9 additions & 1 deletion tests/pdctl/keyspace/keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func TestMergeKeyspaceGroup(t *testing.T) {

// merge keyspace group with `all` flag.
testutil.Eventually(re, func() bool {
args := []string{"-u", pdAddr, "keyspace-group", "merge", "--all"}
args := []string{"-u", pdAddr, "keyspace-group", "merge", "0", "--all"}
output, err := pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
return strings.Contains(string(output), "Success")
Expand All @@ -393,6 +393,14 @@ func TestMergeKeyspaceGroup(t *testing.T) {
output, err = pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
strings.Contains(string(output), "Must specify the source keyspace group ID(s) or the merge all flag")
args = []string{"-u", pdAddr, "keyspace-group", "merge", "0", "1", "--all"}
output, err = pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
strings.Contains(string(output), "Must specify the source keyspace group ID(s) or the merge all flag")
args = []string{"-u", pdAddr, "keyspace-group", "merge", "1", "--all"}
output, err = pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
strings.Contains(string(output), "Unable to merge all keyspace groups into a non-default keyspace group")

re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/keyspace/acceleratedAllocNodes"))
re.NoError(failpoint.Disable("github.com/tikv/pd/server/delayStartServerLoop"))
Expand Down
21 changes: 13 additions & 8 deletions tools/pd-ctl/pdctl/command/keyspace_group_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,28 @@ func finishSplitKeyspaceGroupCommandFunc(cmd *cobra.Command, args []string) {

func mergeKeyspaceGroupCommandFunc(cmd *cobra.Command, args []string) {
var (
targetGroupID = mcsutils.DefaultKeyspaceGroupID
targetGroupID uint32
params = map[string]interface{}{}
argNum = len(args)
)
if argNum == 0 {
mergeAll, err := cmd.Flags().GetBool("all")
mergeAll, err := cmd.Flags().GetBool("all")
if err != nil {
cmd.Printf("Failed to get the merge all flag: %s\n", err)
return
}
if argNum == 1 && mergeAll {
target, err := strconv.ParseUint(args[0], 10, 32)
if err != nil {
cmd.Printf("Failed to get the merge all flag: %s\n", err)
cmd.Printf("Failed to parse the target keyspace group ID: %s\n", err)
return
}
if !mergeAll {
cmd.Println("Must specify the source keyspace group ID(s) or the merge all flag")
cmd.Usage()
targetGroupID = uint32(target)
if targetGroupID != mcsutils.DefaultKeyspaceGroupID {
cmd.Println("Unable to merge all keyspace groups into a non-default keyspace group")
return
}
params["merge-all-into-default"] = true
} else if argNum >= 2 {
} else if argNum >= 2 && !mergeAll {
target, err := strconv.ParseUint(args[0], 10, 32)
if err != nil {
cmd.Printf("Failed to parse the target keyspace group ID: %s\n", err)
Expand Down

0 comments on commit 4323127

Please sign in to comment.