Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pd-ctl: disable EnablePrefixMatching and avoid misuse of store remove and store delete #8414

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe EnablePrefixMatching is a dangerous operator for the user, do we need to disable it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref

cobra.EnablePrefixMatching = true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

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
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