Skip to content

Commit

Permalink
Improve host's leader number bounds when doing leader balance (#5670)
Browse files Browse the repository at this point in the history
Improve host bounds when doing leader balance

Co-authored-by: Sophie <[email protected]>
  • Loading branch information
songqing and Sophie-Xie authored Sep 5, 2023
1 parent 129ee9e commit 3a74633
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ core.*
workspace.*
.metals/
.cproject
.ycm_extra_conf.py

#py
*.egg-info
Expand Down
25 changes: 22 additions & 3 deletions src/meta/processors/job/LeaderBalanceJobExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,28 @@ ErrorOr<nebula::cpp2::ErrorCode, bool> LeaderBalanceJobExecutor::buildLeaderBala

if (dependentOnZone) {
for (auto it = allHostParts.begin(); it != allHostParts.end(); it++) {
auto min = it->second.size() / replicaFactor;
LOG(INFO) << "Host: " << it->first << " Bounds: " << min << " : " << min + 1;
hostBounds_[it->first] = std::make_pair(min, min + 1);
size_t localParts = it->second.size();
size_t localAvg = localParts / replicaFactor;
size_t localMin = localAvg;
size_t localMax = localAvg;
if (localParts % replicaFactor != 0) {
localMax += 1;
}

if (useDeviation) {
size_t localMinTmp = std::ceil(static_cast<double>(localParts) / replicaFactor *
(1 - FLAGS_leader_balance_deviation));
size_t localMaxTmp = std::floor(static_cast<double>(localParts) / replicaFactor *
(1 + FLAGS_leader_balance_deviation));
if (localMinTmp <= localMaxTmp) {
localMin = localMinTmp;
localMax = localMaxTmp;
}
}
LOG(INFO) << "Host:" << it->first << "'s leader balance plan, expected min load: " << localMin
<< ", max load: " << localMax << " avg: " << localAvg;

hostBounds_[it->first] = std::make_pair(localMin, localMax);
}
} else {
size_t activeSize = activeHosts.size();
Expand Down

0 comments on commit 3a74633

Please sign in to comment.