Skip to content

Commit

Permalink
do not change the default TiFlash limit
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Jun 22, 2020
1 parent 07420d4 commit ad8013b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
5 changes: 3 additions & 2 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1684,18 +1684,19 @@ func (c *RaftCluster) GetAllStoresLimit() map[uint64]config.StoreLimitConfig {
}

// AddStoreLimit add a store limit for a given store ID.
func (c *RaftCluster) AddStoreLimit(storeID uint64, isTiFlashStore bool) {
func (c *RaftCluster) AddStoreLimit(store *metapb.Store) {
cfg := c.opt.GetScheduleConfig().Clone()
sc := config.StoreLimitConfig{
AddPeer: config.DefaultStoreLimit.GetDefaultStoreLimit(storelimit.AddPeer),
RemovePeer: config.DefaultStoreLimit.GetDefaultStoreLimit(storelimit.RemovePeer),
}
if isTiFlashStore {
if core.IsTiFlashStore(store) {
sc = config.StoreLimitConfig{
AddPeer: config.DefaultTiFlashStoreLimit.GetDefaultStoreLimit(storelimit.AddPeer),
RemovePeer: config.DefaultTiFlashStoreLimit.GetDefaultStoreLimit(storelimit.RemovePeer),
}
}
storeID := store.GetId()
cfg.StoreLimit[storeID] = sc
c.opt.SetScheduleConfig(cfg)
}
Expand Down
2 changes: 0 additions & 2 deletions server/config/persist_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,12 @@ func (o *PersistOptions) SetAllStoresLimit(typ storelimit.Type, ratePerMin float
switch typ {
case storelimit.AddPeer:
DefaultStoreLimit.SetDefaultStoreLimit(storelimit.AddPeer, ratePerMin)
DefaultTiFlashStoreLimit.SetDefaultStoreLimit(storelimit.AddPeer, ratePerMin)
for storeID := range v.StoreLimit {
sc := StoreLimitConfig{AddPeer: ratePerMin, RemovePeer: v.StoreLimit[storeID].RemovePeer}
v.StoreLimit[storeID] = sc
}
case storelimit.RemovePeer:
DefaultStoreLimit.SetDefaultStoreLimit(storelimit.RemovePeer, ratePerMin)
DefaultTiFlashStoreLimit.SetDefaultStoreLimit(storelimit.RemovePeer, ratePerMin)
for storeID := range v.StoreLimit {
sc := StoreLimitConfig{AddPeer: v.StoreLimit[storeID].AddPeer, RemovePeer: ratePerMin}
v.StoreLimit[storeID] = sc
Expand Down
11 changes: 11 additions & 0 deletions server/core/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,14 @@ func (s *StoresInfo) UpdateStoreStatus(storeID uint64, leaderCount int, regionCo
s.SetStore(newStore)
}
}

// IsTiFlashStore used to judge flash store.
// FIXME: remove the hack way
func IsTiFlashStore(store *metapb.Store) bool {
for _, l := range store.GetLabels() {
if l.GetKey() == "engine" && l.GetValue() == "tiflash" {
return true
}
}
return false
}
8 changes: 2 additions & 6 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (s *Server) PutStore(ctx context.Context, request *pdpb.PutStoreRequest) (*
}

// NOTE: can be removed when placement rules feature is enabled by default.
if !s.GetConfig().Replication.EnablePlacementRules && isTiFlashStore(store) {
if !s.GetConfig().Replication.EnablePlacementRules && core.IsTiFlashStore(store) {
return nil, status.Errorf(codes.FailedPrecondition, "placement rules is disabled")
}

Expand All @@ -235,11 +235,7 @@ func (s *Server) PutStore(ctx context.Context, request *pdpb.PutStoreRequest) (*
log.Info("put store ok", zap.Stringer("store", store))
rc.OnStoreVersionChange()
CheckPDVersion(s.persistOptions)
if isTiFlashStore(store) {
rc.AddStoreLimit(store.GetId(), true /* isTiFlashStore*/)
} else {
rc.AddStoreLimit(store.GetId(), false /* isTiFlashStore*/)
}
rc.AddStoreLimit(store)

return &pdpb.PutStoreResponse{
Header: s.header(),
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ func (s *Server) SetReplicationConfig(cfg config.ReplicationConfig) error {
} else {
// NOTE: can be removed after placement rules feature is enabled by default.
for _, s := range raftCluster.GetStores() {
if !s.IsTombstone() && isTiFlashStore(s.GetMeta()) {
if !s.IsTombstone() && core.IsTiFlashStore(s.GetMeta()) {
return errors.New("cannot disable placement rules with TiFlash nodes")
}
}
Expand Down
12 changes: 0 additions & 12 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"path"
"time"

"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"
"github.com/pingcap/pd/v4/pkg/etcdutil"
Expand Down Expand Up @@ -182,14 +181,3 @@ func checkBootstrapRequest(clusterID uint64, req *pdpb.BootstrapRequest) error {

return nil
}

// isTiFlashStore used to judge flash store.
// FIXME: remove the hack way
func isTiFlashStore(store *metapb.Store) bool {
for _, l := range store.GetLabels() {
if l.GetKey() == "engine" && l.GetValue() == "tiflash" {
return true
}
}
return false
}

0 comments on commit ad8013b

Please sign in to comment.