Skip to content

use adaptive timeouts and persistent node count in hive warmup KIKIMR-20551 #624

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

Merged
merged 3 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions ydb/core/mind/hive/hive_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,30 @@ void THive::DeleteTabletWithoutStorage(TLeaderTabletInfo* tablet, TSideEffects&
sideEffects.Send(SelfId(), new TEvTabletBase::TEvDeleteTabletResult(NKikimrProto::OK, tablet->Id));
}

TInstant THive::GetAllowedBootingTime() {
auto connectedNodes = TabletCounters->Simple()[NHive::COUNTER_NODES_CONNECTED].Get();
BLOG_D(connectedNodes << " nodes connected out of " << ExpectedNodes);
if (connectedNodes == 0) {
return {};
}
TInstant result = LastConnect + MaxTimeBetweenConnects * std::max<i64>(static_cast<i64>(ExpectedNodes) - static_cast<i64>(connectedNodes), 1);
if (connectedNodes < ExpectedNodes) {
result = std::max(result, StartTime() + GetWarmUpBootWaitingPeriod());
}
result = std::min(result, StartTime() + GetMaxWarmUpPeriod());
return result;
}

void THive::ExecuteProcessBootQueue(NIceDb::TNiceDb& db, TSideEffects& sideEffects) {
TInstant now = TActivationContext::Now();
TInstant allowed = std::min(LastConnect + GetWarmUpBootWaitingPeriod(), StartTime() + GetMaxWarmUpPeriod());
if (WarmUp && now < allowed) {
BLOG_D("ProcessBootQueue - last connect was at " << LastConnect << "- not long enough ago");
ProcessBootQueueScheduled = false;
PostponeProcessBootQueue(allowed - now);
return;
if (WarmUp) {
TInstant allowed = GetAllowedBootingTime();
if (now < allowed) {
BLOG_D("ProcessBootQueue - waiting until " << allowed << " because of warmup, now: " << now);
ProcessBootQueueScheduled = false;
PostponeProcessBootQueue(allowed - now);
return;
}
}
BLOG_D("Handle ProcessBootQueue (size: " << BootQueue.BootQueue.size() << ")");
THPTimer bootQueueProcessingTimer;
Expand Down Expand Up @@ -302,9 +318,11 @@ void THive::ProcessBootQueue() {
}

void THive::PostponeProcessBootQueue(TDuration after) {
if (!ProcessBootQueuePostponed) {
TInstant postponeUntil = TActivationContext::Now() + after;
if (!ProcessBootQueuePostponed || postponeUntil < ProcessBootQueuePostponedUntil) {
BLOG_D("PostponeProcessBootQueue (" << after << ")");
ProcessBootQueuePostponed = true;
ProcessBootQueuePostponedUntil = postponeUntil;
Schedule(after, new TEvPrivate::TEvPostponeProcessBootQueue());
}
}
Expand Down
4 changes: 4 additions & 0 deletions ydb/core/mind/hive/hive_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ class THive : public TActor<THive>, public TTabletExecutedFlat, public THiveShar
bool ProcessBootQueueScheduled = false;
bool ProcessBootQueuePostponed = false;
TInstant LastConnect;
TInstant ProcessBootQueuePostponedUntil;
TDuration MaxTimeBetweenConnects;
bool WarmUp;
ui64 ExpectedNodes;

THashMap<ui32, TEvInterconnect::TNodeInfo> NodesInfo;
TTabletCountersBase* TabletCounters;
Expand Down Expand Up @@ -901,6 +904,7 @@ class THive : public TActor<THive>, public TTabletExecutedFlat, public THiveShar
void ScheduleDisconnectNode(THolder<TEvPrivate::TEvProcessDisconnectNode> event);
void DeleteTabletWithoutStorage(TLeaderTabletInfo* tablet);
void DeleteTabletWithoutStorage(TLeaderTabletInfo* tablet, TSideEffects& sideEffects);
TInstant GetAllowedBootingTime();
void ScheduleUnlockTabletExecution(TNodeInfo& node);
TString DebugDomainsActiveNodes() const;
TResourceNormalizedValues GetStDevResourceValues() const;
Expand Down
2 changes: 2 additions & 0 deletions ydb/core/mind/hive/hive_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {
TMailboxType::Simple, 0,
TMailboxType::Simple, 0);
TTenantPoolConfig::TPtr tenantPoolConfig = new TTenantPoolConfig(localConfig);
// tenantPoolConfig->AddStaticSlot(DOMAIN_NAME);
tenantPoolConfig->AddStaticSlot(tenant);

TActorId actorId = runtime.Register(
Expand Down Expand Up @@ -1877,6 +1878,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {

Ctest << "killing tablet " << tabletId << Endl;
runtime.Register(CreateTabletKiller(tabletId, runtime.GetNodeId(0)));
// runtime.Register(CreateTabletKiller(tabletId, runtime.GetNodeId(1)));

waitFor([&]{ return blockedCommits.size() >= 2; }, "at least 2 blocked commits");

Expand Down
2 changes: 1 addition & 1 deletion ydb/core/mind/hive/monitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ function fillDataShort(result) {
if ("TotalTablets" in result) {
var percent = Math.floor(result.RunningTablets * 100 / result.TotalTablets) + '%';
var values = result.RunningTablets + ' of ' + result.TotalTablets;
var warmup = result.Warmup ? "<span class='glyphicon glyphicon-fire' style='color:red; margin-right:4px'></span>" : "";
var warmup = result.WarmUp ? "<span class='glyphicon glyphicon-fire' style='color:red; margin-right:4px'></span>" : "";
$('#runningTablets').html(warmup + percent + ' (' + values + ')');
$('#aliveNodes').html(result.AliveNodes);
$('#bootQueue').html(result.BootQueueSize);
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/mind/hive/tx__load_everything.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ class TTxLoadEverything : public TTransactionBase<THive> {
Self->SetCounterTabletsTotal(tabletsTotal);
Self->TabletCounters->Simple()[NHive::COUNTER_SEQUENCE_FREE].Set(Self->Sequencer.FreeSize());
Self->TabletCounters->Simple()[NHive::COUNTER_SEQUENCE_ALLOCATED].Set(Self->Sequencer.AllocatedSequencesSize());
Self->TabletCounters->Simple()[NHive::COUNTER_NODES_TOTAL].Set(Self->Nodes.size());
Self->ExpectedNodes = Self->Nodes.size();
Self->TabletCounters->Simple()[NHive::COUNTER_NODES_TOTAL].Set(Self->ExpectedNodes);
Self->MigrationState = NKikimrHive::EMigrationState::MIGRATION_READY;
ctx.Send(Self->SelfId(), new TEvPrivate::TEvBootTablets());

Expand Down
6 changes: 5 additions & 1 deletion ydb/core/mind/hive/tx__status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ class TTxStatus : public TTransactionBase<THive> {
}
if (Self->WarmUp &&
node.Statistics.RestartTimestampSize() < Self->GetNodeRestartsToIgnoreInWarmup()) {
Self->LastConnect = TActivationContext::Now();
TInstant now = TActivationContext::Now();
if (Self->LastConnect != TInstant{}) {
Self->MaxTimeBetweenConnects = std::max(Self->MaxTimeBetweenConnects, now - Self->LastConnect);
}
Self->LastConnect = now;
}
if (node.LocationAcquired) {
NIceDb::TNiceDb db(txc.DB);
Expand Down
4 changes: 2 additions & 2 deletions ydb/core/protos/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1384,9 +1384,9 @@ message THiveConfig {
repeated NKikimrTabletBase.TTabletTypes.EType BalancerIgnoreTabletTypes = 49;
optional double SpaceUsagePenaltyThreshold = 53 [default = 1.1]; // number > 1
optional double SpaceUsagePenalty = 54 [default = 0.2]; // number <= 1
optional uint64 WarmUpBootWaitingPeriod = 50 [default = 5000]; // milliseconds
optional uint64 WarmUpBootWaitingPeriod = 50 [default = 30000]; // milliseconds, time to wait for known nodes on cluster restart
optional uint64 NodeRestartsToIgnoreInWarmup = 51 [default = 10];
optional double MaxWarmUpPeriod = 52 [default = 30.0]; // seconds
optional double MaxWarmUpPeriod = 52 [default = 600.0]; // seconds
optional bool WarmUpEnabled = 55 [default = true];
optional uint64 EmergencyBalancerInflight = 56 [default = 1]; // tablets
optional uint64 MaxMovementsOnEmergencyBalancer = 57 [default = 2];
Expand Down