Skip to content

Commit

Permalink
pd-ctl: disable EnablePrefixMatching and avoid misuse of `store remov…
Browse files Browse the repository at this point in the history
…e` and `store delete` (#8414)

close #8413

Signed-off-by: lhy1024 <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
lhy1024 and ti-chi-bot[bot] authored Jul 22, 2024
1 parent 8de0412 commit 7b014aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tools/pd-ctl/pdctl/command/store_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-ctl/pdctl/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func init() {
cobra.EnablePrefixMatching = true
cobra.EnablePrefixMatching = false
cobra.EnableTraverseRunHooks = true
}

Expand Down
7 changes: 6 additions & 1 deletion tools/pd-ctl/tests/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,14 @@ func TestStore(t *testing.T) {
// store delete <store_id> 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)
Expand Down

0 comments on commit 7b014aa

Please sign in to comment.