@@ -175,14 +175,31 @@ void THive::DeleteTabletWithoutStorage(TLeaderTabletInfo* tablet, TSideEffects&
175175 sideEffects.Send (SelfId (), new TEvTabletBase::TEvDeleteTabletResult (NKikimrProto::OK, tablet->Id ));
176176}
177177
178+ TInstant THive::GetAllowedBootingTime () {
179+ TDuration passed = LastConnect - StartTime ();
180+ i64 connectedNodes = TabletCounters->Simple ()[NHive::COUNTER_NODES_CONNECTED].Get ();
181+ BLOG_D (connectedNodes << " nodes connected out of " << ExpectedNodes);
182+ if (connectedNodes == 0 ) {
183+ return {};
184+ }
185+ TDuration avgConnectTime = passed / connectedNodes;
186+ TInstant result = LastConnect + avgConnectTime * std::max<i64 >(ExpectedNodes - connectedNodes, 1 );
187+ if (connectedNodes < ExpectedNodes) {
188+ result = std::max (result, StartTime () + GetMaxWarmUpPeriod ());
189+ }
190+ return result;
191+ }
192+
178193void THive::ExecuteProcessBootQueue (NIceDb::TNiceDb& db, TSideEffects& sideEffects) {
179194 TInstant now = TActivationContext::Now ();
180- TInstant allowed = std::min (LastConnect + GetWarmUpBootWaitingPeriod (), StartTime () + GetMaxWarmUpPeriod ());
181- if (WarmUp && now < allowed) {
182- BLOG_D (" ProcessBootQueue - last connect was at " << LastConnect << " - not long enough ago" );
183- ProcessBootQueueScheduled = false ;
184- PostponeProcessBootQueue (allowed - now);
185- return ;
195+ if (WarmUp) {
196+ TInstant allowed = GetAllowedBootingTime ();
197+ if (now < allowed) {
198+ BLOG_D (" ProcessBootQueue - waiting unitl " << allowed << " because of warmup, now: " << now);
199+ ProcessBootQueueScheduled = false ;
200+ PostponeProcessBootQueue (allowed - now);
201+ return ;
202+ }
186203 }
187204 BLOG_D (" Handle ProcessBootQueue (size: " << BootQueue.BootQueue .size () << " )" );
188205 THPTimer bootQueueProcessingTimer;
@@ -302,9 +319,11 @@ void THive::ProcessBootQueue() {
302319}
303320
304321void THive::PostponeProcessBootQueue (TDuration after) {
305- if (!ProcessBootQueuePostponed) {
322+ TInstant postponeUntil = TActivationContext::Now () + after;
323+ if (!ProcessBootQueuePostponed || postponeUntil < ProcessBootQueuePostponedUntil) {
306324 BLOG_D (" PostponeProcessBootQueue (" << after << " )" );
307325 ProcessBootQueuePostponed = true ;
326+ ProcessBootQueuePostponedUntil = postponeUntil;
308327 Schedule (after, new TEvPrivate::TEvPostponeProcessBootQueue ());
309328 }
310329}
0 commit comments