diff options
author | zalyalov <zalyalov@yandex-team.com> | 2023-07-18 09:37:38 +0300 |
---|---|---|
committer | zalyalov <zalyalov@yandex-team.com> | 2023-07-18 09:37:38 +0300 |
commit | ccbe76e66014692c9945391d3321d5bd491d022b (patch) | |
tree | 19a9d03c764f51189a0656793ef900f8646ef99b | |
parent | 4900e12fd417f46cca069d3b39c1adc2608f6f1b (diff) | |
download | ydb-ccbe76e66014692c9945391d3321d5bd491d022b.tar.gz |
add complete rebalance KIKIMR-17796
add support for full rebalance
-rw-r--r-- | ydb/core/mind/hive/hive_impl.h | 1 | ||||
-rw-r--r-- | ydb/core/mind/hive/monitoring.cpp | 96 | ||||
-rw-r--r-- | ydb/core/protos/counters_hive.proto | 1 |
3 files changed, 95 insertions, 3 deletions
diff --git a/ydb/core/mind/hive/hive_impl.h b/ydb/core/mind/hive/hive_impl.h index 282e6f6ec4f..be6ea786370 100644 --- a/ydb/core/mind/hive/hive_impl.h +++ b/ydb/core/mind/hive/hive_impl.h @@ -192,6 +192,7 @@ protected: friend class TTxMonEvent_ResumeTablet; friend class TTxMonEvent_InitMigration; friend class TTxMonEvent_QueryMigration; + friend class TTxMonEvent_RebalanceFromScratch; friend class TTxKillNode; friend class TTxLoadEverything; friend class TTxRestartTablet; diff --git a/ydb/core/mind/hive/monitoring.cpp b/ydb/core/mind/hive/monitoring.cpp index 8ad91a568e3..3e567133a60 100644 --- a/ydb/core/mind/hive/monitoring.cpp +++ b/ydb/core/mind/hive/monitoring.cpp @@ -1352,7 +1352,7 @@ public: << aliveNodes << "/" << nodes << "</td></tr>";*/ out << "<tr><td>" << "Tablets:" << "</td><td id='runningTablets'>" << (tablets == 0 ? 0 : runningTablets * 100 / tablets) << "% " << runningTablets << "/" << tablets << "</td></tr>"; - out << "<tr><td title='Rebalance all tablets' style='cursor:pointer' onclick='rebalanceTablets(this)'>Balancer: </td><td id='balancerProgress'>" + out << "<tr><td><button type='button' class='btn btn-link' data-toggle='modal' data-target='#rebalance'>Balancer: </button></td><td id='balancerProgress'>" << (Self->BalancerProgress >= 0 ? Sprintf("%d%%", Self->BalancerProgress) : TString()) << "</td></tr>"; out << "<tr><td>" << "Boot Queue:" << "</td><td id='bootQueue'>" << Self->BootQueue.BootQueue.size() << "</td></tr>"; out << "<tr><td>" << "Wait Queue:" << "</td><td id='waitQueue'>" << Self->BootQueue.WaitQueue.size() << "</td></tr>"; @@ -1540,6 +1540,48 @@ public: </div> )___"; + out << R"___( + <div class='modal fade' id='rebalance' role='dialog'> + <div class='modal-dialog' style='width:60%'> + <div class='modal-content'> + <div class='modal-header'> + <button type='button' class='close' data-dismiss='modal'>×</button> + <h4 class='modal-title'>Rebalance tablets</h4> + </div> + <div class='modal-body'> + <div class='row'> + <div class='col-md-12'> + <h2> Run Balancer</h2> + <label for='balancer_max_movements'>Max movements</label> + <div in='balancer_max_movements' class='input-group'> + <input id='balancer_max_movements' type='number' value='1000' class='form-control'> + </div> + <button type='submit' class='btn btn-primary' onclick='rebalanceTablets()' data-dismiss='modal'>Run</button> + </div> + </div> + <div class='row'> + <div class='col-md-12'> + <hr> + </div> + </div> + <div class='row'> + <div class='col-md-12'> + <h2> Rebalance ALL tablets FROM SCRATCH</h2> + <label for='tenant_name'> Please enter the tenant name to confirm you know what you are doing</label> + <div in='tenant_name' class='input-group' style='width:100%'> + <input id='tenant_name' type='text' class='form-control'> + </div> + <button id='button_rebalance' type='submit' class='btn btn-danger' onclick='rebalanceTabletsFromScratch();' data-dismiss='modal'>Run</button> + </div> + </div> + </div> + <div class='modal-footer'> + <button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button> + </div> + </div> + </div> + </div> + )___"; out << "<script>"; out << "var hiveId = '" << Self->HiveId << "';"; out << "var tablets = ["; @@ -1707,9 +1749,15 @@ public: $.ajax({url:'app?TabletID=' + hiveId + '&node=' + nodeId + '&page=DrainNode', success: function(){ $(element).addClass('blinking'); }}); } - function rebalanceTablets(element) { + function rebalanceTablets() { $('#balancerProgress').html('o.O'); - $.ajax({url:'app?TabletID=' + hiveId + '&page=Rebalance'}); + var max_movements = $('#balancer_max_movements').val(); + $.ajax({url:'app?TabletID=' + hiveId + '&page=Rebalance&movements=' + max_movements}); + } + + function rebalanceTabletsFromScratch(element) { + var tenant_name = $('#tenant_name').val(); + $.ajax({url:'app?TabletID=' + hiveId + '&page=RebalanceFromScratch&tenantName=' + tenant_name}); } function toggleAlert() { @@ -2249,6 +2297,45 @@ public: } }; +class TTxMonEvent_RebalanceFromScratch : public TTransactionBase<THive> { +public: + const TActorId Source; + TString TenantName; + + TTxMonEvent_RebalanceFromScratch(const TActorId& source, NMon::TEvRemoteHttpInfo::TPtr& ev, TSelf* hive) + : TBase(hive) + , Source(source) + { + TenantName = ev->Get()->Cgi().Get("tenantName"); + } + + TTxType GetTxType() const override { return NHive::TXTYPE_MON_REBALANCE_FROM_SCRATCH; } + + bool ValidateTenantName() { + auto domainId = Self->GetMySubDomainKey(); + auto* domainInfo = Self->FindDomain(domainId); + if (!domainInfo || !domainInfo->Path) { + // In the non-normal case of not knowing our domain, allow anything + return true; + } + return TenantName == domainInfo->Path; + } + + bool Execute(TTransactionContext&, const TActorContext&) override { + if (!ValidateTenantName()) { + return true; + } + for (const auto& tablet : Self->Tablets) { + Self->Execute(Self->CreateRestartTablet(tablet.second.GetFullTabletId())); + } + return true; + } + + void Complete(const TActorContext& ctx) override { + ctx.Send(Source, new NMon::TEvRemoteJsonInfoRes("{}")); + } +}; + class TReassignTabletWaitActor : public TActor<TReassignTabletWaitActor>, public ISubActor { public: TActorId Source; @@ -3634,6 +3721,9 @@ void THive::CreateEvMonitoring(NMon::TEvRemoteHttpInfo::TPtr& ev, const TActorCo if (page == "Rebalance") { return Execute(new TTxMonEvent_Rebalance(ev->Sender, ev, this), ctx); } + if (page == "RebalanceFromScratch") { + return Execute(new TTxMonEvent_RebalanceFromScratch(ev->Sender, ev, this), ctx); + } if (page == "LandingData") { return Execute(new TTxMonEvent_LandingData(ev->Sender, ev, this), ctx); } diff --git a/ydb/core/protos/counters_hive.proto b/ydb/core/protos/counters_hive.proto index 5321e1fe65f..b84e986807b 100644 --- a/ydb/core/protos/counters_hive.proto +++ b/ydb/core/protos/counters_hive.proto @@ -112,4 +112,5 @@ enum ETxTypes { TXTYPE_REQUEST_TABLET_OWNERS = 59 [(TxTypeOpts) = {Name: "TxRequestTabletOwners"}]; TXTYPE_REASSIGN_GROUPS_ON_DECOMMIT = 60 [(TxTypeOpts) = {Name: "TxReassignGroupsOnDecommit"}]; TXTYPE_UPDATE_TABLETS_OBJECT = 61 [(TxTypeOpts) = {Name: "TxUpdateTabletsObject"}]; + TXTYPE_MON_REBALANCE_FROM_SCRATCH = 62 [(TxTypeOpts) = {Name: "TxMonRebalanceFromScratch"}]; } |