diff --git a/ydb/core/driver_lib/run/run.cpp b/ydb/core/driver_lib/run/run.cpp index 4dd4c1ed5900..3d7e42f382e9 100644 --- a/ydb/core/driver_lib/run/run.cpp +++ b/ydb/core/driver_lib/run/run.cpp @@ -502,8 +502,11 @@ static TString ReadFile(const TString& fileName) { } void TKikimrRunner::InitializeGracefulShutdown(const TKikimrRunConfig& runConfig) { - Y_UNUSED(runConfig); GracefulShutdownSupported = true; + const auto& config = runConfig.AppConfig.GetShutdownConfig(); + if (config.HasMinDelayBeforeShutdownSeconds()) { + MinDelayBeforeShutdown = TDuration::Seconds(config.GetMinDelayBeforeShutdownSeconds()); + } } void TKikimrRunner::InitializeKqpController(const TKikimrRunConfig& runConfig) { @@ -1734,6 +1737,7 @@ void TKikimrRunner::KikimrStop(bool graceful) { ActorSystem->Send(new IEventHandle(NGRpcService::CreateGrpcPublisherServiceActorId(), {}, new TEvents::TEvPoisonPill)); } + THPTimer timer; TIntrusivePtr drainProgress(new TDrainProgress()); if (AppData->FeatureFlags.GetEnableDrainOnShutdown() && GracefulShutdownSupported && ActorSystem) { drainProgress->OnSend(); @@ -1767,6 +1771,12 @@ void TKikimrRunner::KikimrStop(bool graceful) { } } + // Wait for a minimum delay to make sure that clients forget about this node + auto passedTime = TDuration::Seconds(timer.Passed()); + if (MinDelayBeforeShutdown > passedTime) { + Sleep(MinDelayBeforeShutdown - passedTime); + } + if (ActorSystem) { ActorSystem->BroadcastToProxies([](const TActorId& proxyId) { return new IEventHandle(proxyId, {}, new TEvInterconnect::TEvTerminate); diff --git a/ydb/core/driver_lib/run/run.h b/ydb/core/driver_lib/run/run.h index 0977da36b521..c84e17069c0c 100644 --- a/ydb/core/driver_lib/run/run.h +++ b/ydb/core/driver_lib/run/run.h @@ -43,6 +43,7 @@ class TKikimrRunner : public virtual TThrRefBase, private IGlobalObjectStorage { bool EnabledGrpcService = false; bool GracefulShutdownSupported = false; + TDuration MinDelayBeforeShutdown; THolder SqsHttp; THolder YdbDriver; diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index 7401e5fb5914..a989189b4f76 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -1905,6 +1905,10 @@ message TMetadataCacheConfig { optional uint64 RefreshPeriodMs = 1 [default = 15000]; } +message TShutdownConfig { + optional uint32 MinDelayBeforeShutdownSeconds = 1; +} + message TLabel { optional string Name = 1; optional string Value = 2; @@ -1989,6 +1993,7 @@ message TAppConfig { optional TMemoryControllerConfig MemoryControllerConfig = 81; optional TGroupedMemoryLimiterConfig GroupedMemoryLimiterConfig = 82; optional NKikimrReplication.TReplicationDefaults ReplicationConfig = 83; + optional TShutdownConfig ShutdownConfig = 84; repeated TNamedConfig NamedConfigs = 100; optional string ClusterYamlConfig = 101;