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

*: balance based on read flow #708

Merged
merged 15 commits into from
Sep 12, 2017
328 changes: 219 additions & 109 deletions _vendor/src/github.com/pingcap/kvproto/pkg/pdpb/pdpb.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ import:
- package: github.com/pingcap/check
version: ce8a2f822ab1e245a4eefcef2996531c79c943f1
- package: github.com/pingcap/kvproto
version: ebe86abfa6519ffefdf2946fba762a894fe88256
version: aa89780c80ffbad78c6aaaf0c53829547cf3a5c2
subpackages:
- pkg/coprocessor
- pkg/eraftpb
Expand Down
25 changes: 23 additions & 2 deletions pdctl/command/hot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (
)

const (
hotRegionsPrefix = "pd/api/v1/hotspot/regions"
hotStoresPrefix = "pd/api/v1/hotspot/stores"
hotRegionsPrefix = "pd/api/v1/hotspot/regions"
hotReadRegionsPrefix = "pd/api/v1/hotspot/readregions"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe regions/write and regions/read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"pd/api/v1/hotspot/regions"

this is for write, maybe

"pd/api/v1/hotspot/read"

this is for read ?

hotStoresPrefix = "pd/api/v1/hotspot/stores"
)

// NewHotSpotCommand return a hot subcommand of rootCmd
Expand All @@ -32,6 +33,7 @@ func NewHotSpotCommand() *cobra.Command {
Short: "show the hotspot status of the cluster",
}
cmd.AddCommand(NewHotRegionCommand())
cmd.AddCommand(NewHotReadRegionCommand())
cmd.AddCommand(NewHotStoreCommand())
return cmd
}
Expand All @@ -55,6 +57,25 @@ func showHotRegionsCommandFunc(cmd *cobra.Command, args []string) {
fmt.Println(r)
}

// NewHotReadRegionCommand return a hot read regions subcommand of hotSpotCmd
func NewHotReadRegionCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "read region",
Short: "show the hot read regions",
Run: showHotReadRegionsCommandFunc,
}
return cmd
}

func showHotReadRegionsCommandFunc(cmd *cobra.Command, args []string) {
r, err := doRequest(cmd, hotReadRegionsPrefix, http.MethodGet)
if err != nil {
fmt.Printf("Failed to get hotspot: %s\n", err)
return
}
fmt.Println(r)
}

// NewHotStoreCommand return a hot stores subcommand of hotSpotCmd
func NewHotStoreCommand() *cobra.Command {
cmd := &cobra.Command{
Expand Down
4 changes: 4 additions & 0 deletions server/api/hot_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (h *hotStatusHandler) GetHotRegions(w http.ResponseWriter, r *http.Request)
h.rd.JSON(w, http.StatusOK, h.GetHotWriteRegions())
}

func (h *hotStatusHandler) GetHotReadRegions(w http.ResponseWriter, r *http.Request) {
h.rd.JSON(w, http.StatusOK, h.Handler.GetHotReadRegions())
}

func (h *hotStatusHandler) GetHotStores(w http.ResponseWriter, r *http.Request) {
h.rd.JSON(w, http.StatusOK, h.GetHotWriteStores())
}
1 change: 1 addition & 0 deletions server/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func createRouter(prefix string, svr *server.Server) *mux.Router {

hotStatusHandler := newHotStatusHandler(handler, rd)
router.HandleFunc("/api/v1/hotspot/regions", hotStatusHandler.GetHotRegions).Methods("GET")
router.HandleFunc("/api/v1/hotspot/readregions", hotStatusHandler.GetHotReadRegions).Methods("GET")
router.HandleFunc("/api/v1/hotspot/stores", hotStatusHandler.GetHotStores).Methods("GET")
router.Handle("/api/v1/events", newEventsHandler(svr, rd)).Methods("GET")
router.Handle("/api/v1/feed", newFeedHandler(svr, rd)).Methods("GET")
Expand Down