diff --git a/tests/pdctl/store/store_test.go b/tests/pdctl/store/store_test.go index cdd21a2c29c..a4c818a27d4 100644 --- a/tests/pdctl/store/store_test.go +++ b/tests/pdctl/store/store_test.go @@ -257,6 +257,24 @@ func (s *storeTestSuite) TestStore(c *C) { c.Assert(json.Unmarshal(output, &storeInfo), IsNil) c.Assert(storeInfo.Store.State, Equals, metapb.StoreState_Offline) + // store check status + args = []string{"-u", pdAddr, "store", "check", "Offline"} + output, err = pdctl.ExecuteCommand(cmd, args...) + c.Assert(err, IsNil) + c.Assert(strings.Contains(string(output), "\"id\": 1,"), IsTrue) + args = []string{"-u", pdAddr, "store", "check", "Tombstone"} + output, err = pdctl.ExecuteCommand(cmd, args...) + c.Assert(err, IsNil) + c.Assert(strings.Contains(string(output), "\"id\": 2,"), IsTrue) + args = []string{"-u", pdAddr, "store", "check", "Up"} + output, err = pdctl.ExecuteCommand(cmd, args...) + c.Assert(err, IsNil) + c.Assert(strings.Contains(string(output), "\"id\": 3,"), IsTrue) + args = []string{"-u", pdAddr, "store", "check", "Invalid_State"} + output, err = pdctl.ExecuteCommand(cmd, args...) + c.Assert(err, IsNil) + c.Assert(strings.Contains(string(output), "Unknown state: Invalid_state"), IsTrue) + // store delete addr
args = []string{"-u", pdAddr, "store", "delete", "addr", "tikv3"} output, err = pdctl.ExecuteCommand(cmd, args...) @@ -326,5 +344,4 @@ func (s *storeTestSuite) TestStore(c *C) { err = json.Unmarshal(output, scene) c.Assert(err, IsNil) c.Assert(scene.Idle, Equals, 100) - } diff --git a/tools/pd-ctl/pdctl/command/store_command.go b/tools/pd-ctl/pdctl/command/store_command.go index 91f4671bac1..6ccfeb47381 100644 --- a/tools/pd-ctl/pdctl/command/store_command.go +++ b/tools/pd-ctl/pdctl/command/store_command.go @@ -44,6 +44,7 @@ func NewStoreCommand() *cobra.Command { s.AddCommand(NewStoreLimitCommand()) s.AddCommand(NewRemoveTombStoneCommand()) s.AddCommand(NewStoreLimitSceneCommand()) + s.AddCommand(NewStoreCheckCommand()) s.Flags().String("jq", "", "jq query") s.Flags().StringSlice("state", nil, "state filter") return s @@ -101,6 +102,16 @@ func NewStoreLimitCommand() *cobra.Command { return c } +// NewStoreCheckCommand return a check subcommand of storeCmd +func NewStoreCheckCommand() *cobra.Command { + d := &cobra.Command{ + Use: "check [up|offline|tombstone]", + Short: "Check all the stores with specified status", + Run: storeCheckCommandFunc, + } + return d +} + // NewStoresCommand returns a store subcommand of rootCmd func NewStoresCommand() *cobra.Command { s := &cobra.Command{ @@ -447,6 +458,28 @@ func storeLimitCommandFunc(cmd *cobra.Command, args []string) { } } +func storeCheckCommandFunc(cmd *cobra.Command, args []string) { + if len(args) != 1 { + cmd.Usage() + return + } + + state := strings.Title(strings.ToLower(args[0])) + stateValue, ok := metapb.StoreState_value[state] + if !ok { + cmd.Println("Unknown state: " + state) + return + } + + prefix := fmt.Sprintf("%s?state=%d", storesPrefix, stateValue) + r, err := doRequest(cmd, prefix, http.MethodGet) + if err != nil { + cmd.Printf("Failed to get store: %s\n", err) + return + } + cmd.Println(r) +} + func showStoresCommandFunc(cmd *cobra.Command, args []string) { prefix := storesPrefix r, err := doRequest(cmd, prefix, http.MethodGet)