Skip to content

Commit

Permalink
Merge branch 'master' into hot-region-useless-code
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jul 5, 2021
2 parents f8b28b4 + c5aff6e commit bb9c0f7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/pdctl/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <address>
args = []string{"-u", pdAddr, "store", "delete", "addr", "tikv3"}
output, err = pdctl.ExecuteCommand(cmd, args...)
Expand Down Expand Up @@ -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)

}
33 changes: 33 additions & 0 deletions tools/pd-ctl/pdctl/command/store_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bb9c0f7

Please sign in to comment.