aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorijon <ijon@yandex-team.com>2022-09-05 14:12:00 +0300
committerijon <ijon@yandex-team.com>2022-09-05 14:12:00 +0300
commit7597a329b3256b41c92d36c943cf18dd0de845ea (patch)
tree70f5bc1d92dcae273a715e2932ece8e10557f155
parent44e5c0e63920f9d9359f45894903c8dc26da542b (diff)
downloadydb-7597a329b3256b41c92d36c943cf18dd0de845ea.tar.gz
add balancer ignore-tablets-by-type feature
Tablets could be excluded from attempts to rebalance them across nodes by their type. BalancerIgnoreTabletTypes configuration parameter specifies tablet type list for the balancer to ignore. Empty by default. Could be set by config(s) and/or changed through Hive's web-ui.
-rw-r--r--contrib/restricted/boost/test/include/boost/test/tools/old/impl.hpp3
-rw-r--r--ydb/core/mind/hive/hive_impl.cpp8
-rw-r--r--ydb/core/mind/hive/hive_impl.h11
-rw-r--r--ydb/core/mind/hive/hive_statics.cpp11
-rw-r--r--ydb/core/mind/hive/monitoring.cpp87
-rw-r--r--ydb/core/mind/hive/tablet_info.cpp3
-rw-r--r--ydb/core/protos/config.proto1
7 files changed, 118 insertions, 6 deletions
diff --git a/contrib/restricted/boost/test/include/boost/test/tools/old/impl.hpp b/contrib/restricted/boost/test/include/boost/test/tools/old/impl.hpp
index 7759adf788b..0b8f888cbec 100644
--- a/contrib/restricted/boost/test/include/boost/test/tools/old/impl.hpp
+++ b/contrib/restricted/boost/test/include/boost/test/tools/old/impl.hpp
@@ -104,10 +104,7 @@ BOOST_PP_REPEAT( BOOST_TEST_MAX_PREDICATE_ARITY, IMPL_FRWD, _ )
template <class Left, class Right>
inline assertion_result equal_impl( Left const& left, Right const& right )
{
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
return left == right;
-#pragma GCC diagnostic pop
}
//____________________________________________________________________________//
diff --git a/ydb/core/mind/hive/hive_impl.cpp b/ydb/core/mind/hive/hive_impl.cpp
index efd7f36bb10..4337a1e75d9 100644
--- a/ydb/core/mind/hive/hive_impl.cpp
+++ b/ydb/core/mind/hive/hive_impl.cpp
@@ -554,6 +554,14 @@ void THive::BuildCurrentConfig() {
for (const NKikimrConfig::THiveTabletPreference& tabletPreference : CurrentConfig.GetDefaultTabletPreference()) {
DefaultDataCentersPreference[tabletPreference.GetType()] = tabletPreference.GetDataCentersPreference();
}
+ BalancerIgnoreTabletTypes.clear();
+ for (auto i : CurrentConfig.GetBalancerIgnoreTabletTypes()) {
+ const auto type = TTabletTypes::EType(i);
+ if (IsValidTabletType(type)) {
+ BalancerIgnoreTabletTypes.emplace_back(type);
+ }
+ }
+ MakeTabletTypeSet(BalancerIgnoreTabletTypes);
}
void THive::Cleanup() {
diff --git a/ydb/core/mind/hive/hive_impl.h b/ydb/core/mind/hive/hive_impl.h
index 85f6ea922df..c4eba001801 100644
--- a/ydb/core/mind/hive/hive_impl.h
+++ b/ydb/core/mind/hive/hive_impl.h
@@ -140,6 +140,8 @@ TString GetConditionalRedString(const TString& str, bool condition);
TString GetDataCenterName(ui64 dataCenterId);
TString LongToShortTabletName(const TString& longTabletName);
TString GetLocationString(const NActors::TNodeLocation& location);
+void MakeTabletTypeSet(std::vector<TTabletTypes::EType>& list);
+bool IsValidTabletType(TTabletTypes::EType type);
class THive : public TActor<THive>, public TTabletExecutedFlat, public THiveSharedSettings {
public:
@@ -404,6 +406,9 @@ protected:
std::unordered_map<TDataCenterId, std::unordered_set<TNodeId>> RegisteredDataCenterNodes;
std::unordered_set<TNodeId> ConnectedNodes;
+ // normalized to be sorted list of unique values
+ std::vector<TTabletTypes::EType> BalancerIgnoreTabletTypes; // built from CurrentConfig
+
// to be removed later
bool TabletOwnersSynced = false;
// to be removed later
@@ -748,6 +753,12 @@ public:
return initialMaximum;
}
+ bool IsInBalancerIgnoreList(TTabletTypes::EType type) const {
+ const auto& ignoreList = BalancerIgnoreTabletTypes;
+ auto found = std::find(ignoreList.begin(), ignoreList.end(), type);
+ return (found != ignoreList.end());
+ }
+
static void ActualizeRestartStatistics(google::protobuf::RepeatedField<google::protobuf::uint64>& restartTimestamps, ui64 barrier);
static bool IsSystemTablet(TTabletTypes::EType type);
diff --git a/ydb/core/mind/hive/hive_statics.cpp b/ydb/core/mind/hive/hive_statics.cpp
index 1f5e2643935..4eae631b946 100644
--- a/ydb/core/mind/hive/hive_statics.cpp
+++ b/ydb/core/mind/hive/hive_statics.cpp
@@ -340,5 +340,16 @@ TString GetLocationString(const NActors::TNodeLocation& location) {
return proto.ShortDebugString();
}
+void MakeTabletTypeSet(std::vector<TTabletTypes::EType>& list) {
+ std::sort(list.begin(), list.end());
+ list.erase(std::unique(list.begin(), list.end()), list.end());
+}
+
+bool IsValidTabletType(TTabletTypes::EType type) {
+ return (type > TTabletTypes::Unknown
+ && type < TTabletTypes::Reserved40
+ );
+}
+
} // NHive
} // NKikimr
diff --git a/ydb/core/mind/hive/monitoring.cpp b/ydb/core/mind/hive/monitoring.cpp
index 414d8f769de..959a3ae48be 100644
--- a/ydb/core/mind/hive/monitoring.cpp
+++ b/ydb/core/mind/hive/monitoring.cpp
@@ -730,6 +730,29 @@ public:
UpdateConfig(db, "NodeSelectStrategy");
UpdateConfig(db, "CheckMoveExpediency");
+ if (params.contains("BalancerIgnoreTabletTypes")) {
+ TVector<TString> tabletTypeNames = SplitString(params.Get("BalancerIgnoreTabletTypes"), ";");
+ std::vector<TTabletTypes::EType> newTypeList;
+ for (const auto& name : tabletTypeNames) {
+ TTabletTypes::EType type = TTabletTypes::StrToType(Strip(name));
+ if (IsValidTabletType(type)) {
+ newTypeList.emplace_back(type);
+ }
+ }
+ MakeTabletTypeSet(newTypeList);
+ if (newTypeList != Self->BalancerIgnoreTabletTypes) {
+ // replace DatabaseConfig.BalancerIgnoreTabletTypes inplace
+ auto* field = Self->DatabaseConfig.MutableBalancerIgnoreTabletTypes();
+ field->Reserve(newTypeList.size());
+ field->Clear();
+ for (auto i : newTypeList) {
+ field->Add(i);
+ }
+ ChangeRequest = true;
+ // Self->BalancerIgnoreTabletTypes will be replaced by Self->BuildCurrentConfig()
+ }
+ }
+
if (ChangeRequest) {
Self->BuildCurrentConfig();
db.Table<Schema::State>().Key(TSchemeIds::State::DefaultState).Update<Schema::State::Config>(Self->DatabaseConfig);
@@ -880,6 +903,65 @@ public:
}
}
+ void ShowConfigForBalancerIgnoreTabletTypes(IOutputStream& out) {
+ // value of protobuf type "repeated field of ETabletTypes::EType"
+ // is represented as a single string build from list delimited type names
+
+ auto makeListString = [] (const NKikimrConfig::THiveConfig& config) {
+ std::vector<TTabletTypes::EType> types;
+ for (auto i : config.GetBalancerIgnoreTabletTypes()) {
+ const auto type = TTabletTypes::EType(i);
+ if (IsValidTabletType(type)) {
+ types.emplace_back(type);
+ }
+ }
+ MakeTabletTypeSet(types);
+ TVector<TString> names;
+ for (auto i : types) {
+ names.emplace_back(TTabletTypes::TypeToStr(i));
+ }
+ return JoinStrings(names, ";");
+ };
+
+ const TString param("BalancerIgnoreTabletTypes");
+
+ NKikimrConfig::THiveConfig builtinConfig;
+ auto builtinDefault = makeListString(builtinConfig);
+ auto clusterDefault = makeListString(Self->ClusterConfig);
+ auto currentValue = makeListString(Self->CurrentConfig);
+
+ bool localOverrided = (currentValue != clusterDefault);
+
+ out << "<div class='row'>";
+ {
+ // mark if value is changed locally
+ out << "<div class='col-sm-3' style='padding-top:12px;text-align:right'>"
+ << "<label for='" << param << "'"
+ << (localOverrided ? "" : "' style='font-weight:normal'")
+ << ">" << param << ":</label>"
+ << "</div>";
+ // editable current value
+ out << "<div class='col-sm-2' style='padding-top:5px'>"
+ << "<input id='" << param << "' style='max-width:170px;margin-top:7px' onkeydown='edit(this);' onchange='edit(this);'"
+ << " value='" << currentValue << "'>"
+ << "</div>";
+ // apply button
+ out << "<div class='col-sm-1'><button type='button' class='btn' style='margin-top:5px' onclick='applyVal(this, \"" << param << "\");' disabled='true'>Apply</button></div>";
+ // reset button
+ out << "<div class='col-sm-1'><button type='button' class='btn' style='margin-top:5px' onclick='resetVal(this, \"" << param << "\");' " << (localOverrided ? "" : "disabled='true'") << ">Reset</button></div>";
+ // show cluster default
+ out << "<div id='CMS" << param << "' class='col-sm-2' style='padding-top:12px'>"
+ << clusterDefault
+ << "</div>";
+ // show builtin default
+ out << "<div id='Default" << param << "' class='col-sm-2' style='padding-top:12px'>"
+ << builtinDefault
+ << "</div>";
+ }
+ out << "</div>";
+ }
+
+
void RenderHTMLPage(IOutputStream& out, const TActorContext&/* ctx*/) {
out << "<head></head><body>";
out << "<script>$('.container > h2').html('Settings');</script>";
@@ -916,6 +998,7 @@ public:
ShowConfig(out, "MaxMovementsOnAutoBalancer");
ShowConfig(out, "ContinueAutoBalancer");
ShowConfig(out, "CheckMoveExpediency");
+ ShowConfigForBalancerIgnoreTabletTypes(out);
out << "<div class='row' style='margin-top:40px'>";
out << "<div class='col-sm-2' style='padding-top:30px;text-align:right'><label for='allowedMetrics'>AllowedMetrics:</label></div>";
@@ -956,10 +1039,8 @@ public:
}
out << "</table></div>";
out << "<div class='col-sm-2' style='padding-top:22px'><button type='button' class='btn' style='margin-top:5px' onclick='applyTab(this);' disabled='true'>Apply</button></div>";
-
out << "</div>";
-
out << "</div>";
out << R"___(
@@ -1027,6 +1108,7 @@ public:
error: function() { $(button).addClass('btn-danger'); }
});
}
+
</script>
)___";
@@ -1061,6 +1143,7 @@ public:
Y_UNUSED(ctx);
}
+ //TODO: move to hive_statics.cpp as utility function
static TString GetTabletType(TTabletTypes::EType type) {
switch(type) {
case TTabletTypes::SchemeShard:
diff --git a/ydb/core/mind/hive/tablet_info.cpp b/ydb/core/mind/hive/tablet_info.cpp
index 81af51c3a93..ab0cec58368 100644
--- a/ydb/core/mind/hive/tablet_info.cpp
+++ b/ydb/core/mind/hive/tablet_info.cpp
@@ -181,7 +181,8 @@ bool TTabletInfo::IsStopped() const {
}
bool TTabletInfo::IsGoodForBalancer(TInstant now) const {
- return now - LastBalancerDecisionTime > Hive.GetTabletKickCooldownPeriod();
+ return !Hive.IsInBalancerIgnoreList(GetTabletType())
+ && (now - LastBalancerDecisionTime > Hive.GetTabletKickCooldownPeriod());
}
bool TTabletInfo::InitiateBoot() {
diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto
index 45dfa91e214..1f934bc08d0 100644
--- a/ydb/core/protos/config.proto
+++ b/ydb/core/protos/config.proto
@@ -1426,6 +1426,7 @@ message THiveConfig {
optional bool CheckMoveExpediency = 46 [default = true];
optional uint64 StoragePoolFreshPeriod = 47 [default = 60000]; // milliseconds
optional string PoolsToMonitorForUsage = 48 [default = "System,User,IC"];
+ repeated NKikimrTabletBase.TTabletTypes.EType BalancerIgnoreTabletTypes = 49;
}
message TDataShardConfig {