From 7b014aa5cc5b29a71fde82c5b36d26e124cf4715 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Mon, 22 Jul 2024 14:21:03 +0800 Subject: [PATCH] pd-ctl: disable EnablePrefixMatching and avoid misuse of `store remove` and `store delete` (#8414) close tikv/pd#8413 Signed-off-by: lhy1024 Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- tools/pd-ctl/pdctl/command/store_command.go | 6 +++++- tools/pd-ctl/pdctl/ctl.go | 2 +- tools/pd-ctl/tests/store/store_test.go | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/pd-ctl/pdctl/command/store_command.go b/tools/pd-ctl/pdctl/command/store_command.go index bc024d5a2e6..188d36e25de 100644 --- a/tools/pd-ctl/pdctl/command/store_command.go +++ b/tools/pd-ctl/pdctl/command/store_command.go @@ -706,7 +706,11 @@ func showAllStoresLimitCommandFunc(cmd *cobra.Command, args []string) { cmd.Println(r) } -func removeTombStoneCommandFunc(cmd *cobra.Command, _ []string) { +func removeTombStoneCommandFunc(cmd *cobra.Command, args []string) { + if len(args) != 0 { + cmd.Usage() + return + } prefix := path.Join(storesPrefix, "remove-tombstone") _, err := doRequest(cmd, prefix, http.MethodDelete, http.Header{}) if err != nil { diff --git a/tools/pd-ctl/pdctl/ctl.go b/tools/pd-ctl/pdctl/ctl.go index fbacd65dc53..5f8c6485c42 100644 --- a/tools/pd-ctl/pdctl/ctl.go +++ b/tools/pd-ctl/pdctl/ctl.go @@ -29,7 +29,7 @@ import ( ) func init() { - cobra.EnablePrefixMatching = true + cobra.EnablePrefixMatching = false cobra.EnableTraverseRunHooks = true } diff --git a/tools/pd-ctl/tests/store/store_test.go b/tools/pd-ctl/tests/store/store_test.go index 0f522b8bd44..2e1e7ac9444 100644 --- a/tools/pd-ctl/tests/store/store_test.go +++ b/tools/pd-ctl/tests/store/store_test.go @@ -339,9 +339,14 @@ func TestStore(t *testing.T) { // store delete command storeInfo.Store.State = metapb.StoreState(metapb.StoreState_value[storeInfo.Store.StateName]) re.Equal(metapb.StoreState_Up, storeInfo.Store.State) + args = []string{"-u", pdAddr, "store", "remove", "1"} // it means remove-tombstone + output, err = tests.ExecuteCommand(cmd, args...) + re.NoError(err) + re.NotContains(string(output), "Success") args = []string{"-u", pdAddr, "store", "delete", "1"} - _, err = tests.ExecuteCommand(cmd, args...) + output, err = tests.ExecuteCommand(cmd, args...) re.NoError(err) + re.Contains(string(output), "Success") args = []string{"-u", pdAddr, "store", "1"} output, err = tests.ExecuteCommand(cmd, args...) re.NoError(err)