-
Notifications
You must be signed in to change notification settings - Fork 726
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 hot regions by peer && by leader #638
Conversation
server/balancer.go
Outdated
RegionsCountAsLeader int `json:"regions_count_as_leader"` | ||
RegionsStatAsLeader RegionsStat | ||
|
||
// Hot regions in this store as the role of Follower or Follower |
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.
what is of Follower or Follower
?
server/balancer.go
Outdated
// Hot regions in this store as the role of replica | ||
WrittenBytesAsPeer uint64 `json:"total_written_bytes_as_peer"` | ||
RegionsCountAsPeer int `json:"regions_count_as_peer"` | ||
RegionsStatAsPeer RegionsStat `json:"statistics_as_peer"` |
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.
I think you can use 2 maps to store 2 types of hot regions.
server/balancer.go
Outdated
if !ok { | ||
status = &StoreHotRegions{ | ||
RegionsStat: make(RegionsStat, 0, storeHotRegionsDefaultLen), | ||
LeaderStoreID := regionInfo.Leader.GetStoreId() |
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.
LeaderStoreID -> leaderStoreID
server/balancer.go
Outdated
status = &StoreHotRegions{ | ||
RegionsStat: make(RegionsStat, 0, storeHotRegionsDefaultLen), | ||
LeaderStoreID := regionInfo.Leader.GetStoreId() | ||
StoreIDs := regionInfo.GetStoreIds() |
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.
StoreIDs -> storeIDs
server/balancer.go
Outdated
minRegionsCount := int(math.MaxInt32) | ||
for _, storeID := range candidateStoreIDs { | ||
if s, ok := h.scoreStatus[storeID]; ok { | ||
if srcHotRegionsCount-s.RegionsStatAsPeer.Len() > 1 && minRegionsCount > s.RegionsStatAsLeader.Len() { |
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.
s/RegionsStatAsLeader/RegionsStatAsPeer
server/balancer.go
Outdated
} | ||
|
||
avgRegionCount := hotRegionTotalCount / float64(len(h.scoreStatus)) | ||
// Multiplied by hotRegionLimitFactor to avoid transfer back and forth | ||
limit := uint64((float64(s.RegionsStat.Len()) - avgRegionCount) * hotRegionLimitFactor) | ||
limit := uint64((float64(s.RegionsStatAsPeer.Len()) - avgRegionCount) * hotRegionLimitFactor) |
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.
need we adjust limit by leader?
server/balancer.go
Outdated
func (h *balanceHotRegionScheduler) GetStatus() *StoreHotRegionInfos { | ||
h.RLock() | ||
defer h.RUnlock() | ||
asPeer := make(map[uint64]*HotRegionsStat) |
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.
make with capacity
server/balancer.go
Outdated
} | ||
|
||
func newBalanceHotRegionScheduler(opt *scheduleOption) *balanceHotRegionScheduler { | ||
return &balanceHotRegionScheduler{ | ||
opt: opt, | ||
limit: 1, | ||
scoreStatus: make(map[uint64]*StoreHotRegions), | ||
statisticsAsPeer: make(map[uint64]*HotRegionsStat), | ||
statisticsAsLeader: make(map[uint64]*HotRegionsStat), |
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.
Seems not well formatted? Have you tried make dev
?
server/balancer.go
Outdated
|
||
if srcPeer == nil { | ||
// Todo: should panic here | ||
return nil, nil, nil |
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.
Why should panic here? Is there a chance that the hot region statistics and region cache are not perfectly synced?
server/balancer.go
Outdated
sourceStore = sid | ||
if maxHotStoreRegionCount == statistics.RegionsStat.Len() && maxWrittenBytes < statistics.WrittenBytes { | ||
maxWrittenBytes = statistics.WrittenBytes | ||
srcStoreID = storeID |
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.
I suppose you can make it simpler:
count, writtenBytes := statistics.RegionStat.Len(), statistics.WrittenBytes
if count >= 2 && (count > maxRegionCount || count == maxRegionCount && writtenBytes > maxWrittenBytes) {
maxRegionCount, maxWrittenBytes = count, writtenBytes
srcStoreID = storeID
}
server/balancer.go
Outdated
destStoreID = h.selectDestStoreByPeer(destStoreIDs, srcRegion, srcStoreID) | ||
if destStoreID != 0 { | ||
srcRegion.WrittenBytes = rs.WrittenBytes | ||
h.adjustBalanceLimitByPeer(srcStoreID) |
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 the peer is relatively balanced, the limit will not adjust when balance leader.
Any update? |
@nolouch PTAL |
server/balancer.go
Outdated
@@ -31,6 +30,13 @@ const ( | |||
bootstrapBalanceDiff = 2 | |||
) | |||
|
|||
type BalanceType int |
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.
please fix this remind by make dev
. and then pass the ci
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.
rest LGTM
@zhangjinpeng1987 Please merge master and fix the compile error. |
LGTM. |
We just consider the leader when do "hot regions" balance, this will lead to a bad situation that a store contains many hot regions’ peer, and TiKV nodes load various from each other.
@nolouch @disksing @siddontang PTAL