-
Notifications
You must be signed in to change notification settings - Fork 719
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
Store label limit #2674
Store label limit #2674
Changes from all commits
e2df10e
ba478c6
9fc219f
367255c
8f44e51
c58edd9
b57d74b
7cadd9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,6 +434,19 @@ func (h *storesHandler) SetAllLimit(w http.ResponseWriter, r *http.Request) { | |
return | ||
} | ||
|
||
label := config.StoreLabel{} | ||
labelKey, keyOk := input["labelKey"] | ||
labelValue, valueOk := input["labelValue"] | ||
if keyOk && valueOk { | ||
label.Key = labelKey.(string) | ||
label.Value = labelValue.(string) | ||
} else if !keyOk && !valueOk { | ||
|
||
} else { | ||
h.rd.JSON(w, http.StatusBadRequest, "label key and value must match") | ||
return | ||
} | ||
|
||
rateVal, ok := input["rate"] | ||
if !ok { | ||
h.rd.JSON(w, http.StatusBadRequest, "rate unset") | ||
|
@@ -452,9 +465,16 @@ func (h *storesHandler) SetAllLimit(w http.ResponseWriter, r *http.Request) { | |
} | ||
|
||
for _, typ := range typeValues { | ||
if err := h.SetAllStoresLimit(ratePerMin, typ); err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
if label.Key == "" { | ||
if err := h.SetLabelStoresLimit(label, ratePerMin, typ); err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
} else { | ||
if err := h.SetAllStoresLimit(ratePerMin, typ); err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
} | ||
} | ||
|
||
|
@@ -469,8 +489,34 @@ func (h *storesHandler) SetAllLimit(w http.ResponseWriter, r *http.Request) { | |
// @Failure 500 {string} string "PD server failed to proceed the request." | ||
// @Router /stores/limit [get] | ||
func (h *storesHandler) GetAllLimit(w http.ResponseWriter, r *http.Request) { | ||
limits := h.GetScheduleConfig().StoreLimit | ||
h.rd.JSON(w, http.StatusOK, limits) | ||
var input map[string]interface{} | ||
if err := apiutil.ReadJSONRespondError(h.rd, w, r.Body, &input); err != nil { | ||
return | ||
} | ||
|
||
label := config.StoreLabel{} | ||
labelKey, keyOk := input["labelKey"] | ||
labelValue, valueOk := input["labelValue"] | ||
if keyOk && valueOk { | ||
label.Key = labelKey.(string) | ||
label.Value = labelValue.(string) | ||
} else if !keyOk && !valueOk { | ||
|
||
} else { | ||
h.rd.JSON(w, http.StatusBadRequest, "label key and value must match") | ||
return | ||
} | ||
|
||
if keyOk { | ||
if limit, err := h.GetLabelStoresLimit(label, 0); err != nil { | ||
return | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) |
||
h.rd.JSON(w, http.StatusOK, limit) | ||
} | ||
} else { | ||
limits := h.GetScheduleConfig().StoreLimit | ||
h.rd.JSON(w, http.StatusOK, limits) | ||
} | ||
} | ||
|
||
// @Tags store | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1695,6 +1695,21 @@ func (c *RaftCluster) GetStoreLimitByType(storeID uint64, typ storelimit.Type) f | |
return c.opt.GetStoreLimitByType(storeID, typ) | ||
} | ||
|
||
func (c *RaftCluster) GetLabelStores(label config.StoreLabel) []uint64 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method RaftCluster.GetLabelStores should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method RaftCluster.GetLabelStores should have comment or be unexported |
||
var stores []uint64 | ||
for _, s := range c.GetStores() { | ||
if s.GetLabelValue(label.Key) == label.Value { | ||
stores = append(stores, s.GetID()) | ||
} | ||
} | ||
return stores | ||
} | ||
|
||
// GetLabelStoresLimit returns store limit for a label. | ||
func (c *RaftCluster) GetLabelStoresLimit(label config.StoreLabel) config.StoreLimitConfig { | ||
return c.opt.GetLabelStoresLimit(label) | ||
} | ||
|
||
// GetAllStoresLimit returns all store limit | ||
func (c *RaftCluster) GetAllStoresLimit() map[uint64]config.StoreLimitConfig { | ||
return c.opt.GetAllStoresLimit() | ||
|
@@ -1707,10 +1722,13 @@ func (c *RaftCluster) AddStoreLimit(store *metapb.Store) { | |
AddPeer: config.DefaultStoreLimit.GetDefaultStoreLimit(storelimit.AddPeer), | ||
RemovePeer: config.DefaultStoreLimit.GetDefaultStoreLimit(storelimit.RemovePeer), | ||
} | ||
if core.IsTiFlashStore(store) { | ||
sc = config.StoreLimitConfig{ | ||
AddPeer: config.DefaultTiFlashStoreLimit.GetDefaultStoreLimit(storelimit.AddPeer), | ||
RemovePeer: config.DefaultTiFlashStoreLimit.GetDefaultStoreLimit(storelimit.RemovePeer), | ||
for _, l := range store.GetLabels() { | ||
label := config.StoreLabel{Key: l.GetKey(), Value: l.GetValue()} | ||
if limit, ok := config.StoreLabelLimits[label]; ok { | ||
sc = config.StoreLimitConfig{ | ||
AddPeer: limit.GetDefaultStoreLimit(storelimit.AddPeer), | ||
RemovePeer: limit.GetDefaultStoreLimit(storelimit.RemovePeer), | ||
} | ||
} | ||
} | ||
storeID := store.GetId() | ||
|
@@ -1733,6 +1751,15 @@ func (c *RaftCluster) SetStoreLimit(storeID uint64, typ storelimit.Type, ratePer | |
c.opt.SetStoreLimit(storeID, typ, ratePerMin) | ||
} | ||
|
||
// SetLabelStoresLimit sets store limit for a given label, type and rate. | ||
func (c *RaftCluster) SetLabelStoresLimit(label config.StoreLabel, typ storelimit.Type, ratePerMin float64) { | ||
stores := c.GetLabelStores(label) | ||
for _, s := range stores { | ||
c.SetStoreLimit(s, typ, ratePerMin) | ||
} | ||
c.opt.SetLabelStoresLimit(label, typ, ratePerMin) | ||
} | ||
|
||
// SetAllStoresLimit sets all store limit for a given type and rate. | ||
func (c *RaftCluster) SetAllStoresLimit(typ storelimit.Type, ratePerMin float64) { | ||
c.opt.SetAllStoresLimit(typ, ratePerMin) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,6 +202,24 @@ func (o *PersistOptions) SetStoreLimit(storeID uint64, typ storelimit.Type, rate | |
o.SetScheduleConfig(v) | ||
} | ||
|
||
// SetLabelStoresLimit sets store limit for a given label, type and rate. | ||
func (o *PersistOptions) SetLabelStoresLimit(label StoreLabel, typ storelimit.Type, ratePerMin float64) { | ||
v := o.GetScheduleConfig().Clone() | ||
if _, ok := StoreLabelLimits[label]; !ok { | ||
sl := DefaultStoreLimit | ||
StoreLabelLimits[label] = &sl | ||
} | ||
switch typ { | ||
case storelimit.AddPeer: | ||
StoreLabelLimits[label].SetDefaultStoreLimit(storelimit.AddPeer, ratePerMin) | ||
case storelimit.RemovePeer: | ||
StoreLabelLimits[label].SetDefaultStoreLimit(storelimit.RemovePeer, ratePerMin) | ||
} | ||
sll, _ := StoreLabelLimits[label] | ||
v.StoreLabelLimit[label.String()] = StoreLimitConfig{AddPeer: sll.AddPeer, RemovePeer: sll.RemovePeer} | ||
o.SetScheduleConfig(v) | ||
} | ||
|
||
// SetAllStoresLimit sets all store limit for a given type and rate. | ||
func (o *PersistOptions) SetAllStoresLimit(typ storelimit.Type, ratePerMin float64) { | ||
v := o.GetScheduleConfig().Clone() | ||
|
@@ -296,6 +314,15 @@ func (o *PersistOptions) GetStoreLimitByType(storeID uint64, typ storelimit.Type | |
} | ||
} | ||
|
||
// GetLabelStoresLimit returns the limit of stores for a label. | ||
func (o *PersistOptions) GetLabelStoresLimit(label StoreLabel) StoreLimitConfig { | ||
if l, ok := o.GetScheduleConfig().StoreLabelLimit[label.String()]; !ok { | ||
return l | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) |
||
return StoreLimitConfig{AddPeer: DefaultStoreLimit.AddPeer, RemovePeer: DefaultStoreLimit.RemovePeer} | ||
} | ||
} | ||
|
||
// GetAllStoresLimit returns the limit of all stores. | ||
func (o *PersistOptions) GetAllStoresLimit() map[uint64]StoreLimitConfig { | ||
return o.GetScheduleConfig().StoreLimit | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -673,9 +673,8 @@ func (s *StoresInfo) UpdateStoreStatus(storeID uint64, leaderCount int, regionCo | |
} | ||
} | ||
|
||
// IsTiFlashStore used to judge flash store. | ||
// FIXME: remove the hack way | ||
func IsTiFlashStore(store *metapb.Store) bool { | ||
// Judge if it needs placement rule. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment on exported function IsPlacementNeeded should be of the form "IsPlacementNeeded ..." |
||
func IsPlacementNeeded(store *metapb.Store) bool { | ||
for _, l := range store.GetLabels() { | ||
if l.GetKey() == "engine" && l.GetValue() == "tiflash" { | ||
return true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,6 +409,16 @@ func (h *Handler) GetHistory(start time.Time) ([]operator.OpHistory, error) { | |
return c.GetHistory(start), nil | ||
} | ||
|
||
// SetLabelStoresLimit is used to set limit of stores for a label. | ||
func (h *Handler) SetLabelStoresLimit(label config.StoreLabel, ratePerMin float64, limitType storelimit.Type) error { | ||
c, err := h.GetRaftCluster() | ||
if err != nil { | ||
return err | ||
} | ||
c.SetLabelStoresLimit(label, limitType, ratePerMin) | ||
return nil | ||
} | ||
|
||
// SetAllStoresLimit is used to set limit of all stores. | ||
func (h *Handler) SetAllStoresLimit(ratePerMin float64, limitType storelimit.Type) error { | ||
c, err := h.GetRaftCluster() | ||
|
@@ -419,6 +429,15 @@ func (h *Handler) SetAllStoresLimit(ratePerMin float64, limitType storelimit.Typ | |
return nil | ||
} | ||
|
||
// GetAllStoresLimit is used to get limit of all stores. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment on exported method Handler.GetLabelStoresLimit should be of the form "GetLabelStoresLimit ..." |
||
func (h *Handler) GetLabelStoresLimit(label config.StoreLabel, limitType storelimit.Type) (config.StoreLimitConfig, error) { | ||
c, err := h.GetRaftCluster() | ||
if err != nil { | ||
return config.StoreLimitConfig{AddPeer: config.DefaultStoreLimit.AddPeer, RemovePeer: config.DefaultStoreLimit.RemovePeer}, err | ||
} | ||
return c.GetLabelStoresLimit(label), nil | ||
} | ||
|
||
// GetAllStoresLimit is used to get limit of all stores. | ||
func (h *Handler) GetAllStoresLimit(limitType storelimit.Type) (map[uint64]config.StoreLimitConfig, error) { | ||
c, err := h.GetRaftCluster() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)