Skip to content

Commit 057743b

Browse files
committed
Add min delay before shutdown
1 parent ed3dd72 commit 057743b

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

ydb/core/driver_lib/run/run.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@ static TString ReadFile(const TString& fileName) {
502502
}
503503

504504
void TKikimrRunner::InitializeGracefulShutdown(const TKikimrRunConfig& runConfig) {
505-
Y_UNUSED(runConfig);
506505
GracefulShutdownSupported = true;
507-
if (runConfig.AppConfig.HasDelayBeforeShutdownSeconds()) {
508-
DelayBeforeShutdown = TDuration::Seconds(runConfig.AppConfig.GetDelayBeforeShutdownSeconds());
506+
const auto& config = runConfig.AppConfig.GetShutdownConfig();
507+
if (config.HasMinDelayBeforeShutdownSeconds()) {
508+
MinDelayBeforeShutdown = TDuration::Seconds(config.GetMinDelayBeforeShutdownSeconds());
509509
}
510510
}
511511

@@ -1735,9 +1735,9 @@ void TKikimrRunner::KikimrStop(bool graceful) {
17351735

17361736
if (EnabledGrpcService) {
17371737
ActorSystem->Send(new IEventHandle(NGRpcService::CreateGrpcPublisherServiceActorId(), {}, new TEvents::TEvPoisonPill));
1738-
Sleep(DelayBeforeShutdown);
17391738
}
17401739

1740+
THPTimer timer;
17411741
TIntrusivePtr<TDrainProgress> drainProgress(new TDrainProgress());
17421742
if (AppData->FeatureFlags.GetEnableDrainOnShutdown() && GracefulShutdownSupported && ActorSystem) {
17431743
drainProgress->OnSend();
@@ -1771,6 +1771,10 @@ void TKikimrRunner::KikimrStop(bool graceful) {
17711771
}
17721772
}
17731773

1774+
// Wait for a minimum delay to make sure that clients forget about this node
1775+
auto timeLeftBeforeShutdown = MinDelayBeforeShutdown - TDuration::Seconds(timer.Passed());
1776+
Sleep(timeLeftBeforeShutdown);
1777+
17741778
if (ActorSystem) {
17751779
ActorSystem->BroadcastToProxies([](const TActorId& proxyId) {
17761780
return new IEventHandle(proxyId, {}, new TEvInterconnect::TEvTerminate);

ydb/core/driver_lib/run/run.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class TKikimrRunner : public virtual TThrRefBase, private IGlobalObjectStorage {
4343

4444
bool EnabledGrpcService = false;
4545
bool GracefulShutdownSupported = false;
46-
TDuration DelayBeforeShutdown;
46+
TDuration MinDelayBeforeShutdown;
47+
TDuration DelayBeforeShutdown2;
4748
THolder<NSQS::TAsyncHttpServer> SqsHttp;
4849

4950
THolder<NYdb::TDriver> YdbDriver;

ydb/core/protos/config.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,10 @@ message TMetadataCacheConfig {
19051905
optional uint64 RefreshPeriodMs = 1 [default = 15000];
19061906
}
19071907

1908+
message TShutdownConfig {
1909+
optional uint32 MinDelayBeforeShutdownSeconds = 1;
1910+
}
1911+
19081912
message TLabel {
19091913
optional string Name = 1;
19101914
optional string Value = 2;
@@ -1989,7 +1993,7 @@ message TAppConfig {
19891993
optional TMemoryControllerConfig MemoryControllerConfig = 81;
19901994
optional TGroupedMemoryLimiterConfig GroupedMemoryLimiterConfig = 82;
19911995
optional NKikimrReplication.TReplicationDefaults ReplicationConfig = 83;
1992-
optional uint32 DelayBeforeShutdownSeconds = 108;
1996+
optional TShutdownConfig ShutdownConfig = 84;
19931997

19941998
repeated TNamedConfig NamedConfigs = 100;
19951999
optional string ClusterYamlConfig = 101;

0 commit comments

Comments
 (0)