Skip to content

Commit

Permalink
24-3: Add min delay before shutdown (#9688) (#10087)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixcc authored and uzhastik committed Oct 7, 2024
1 parent 1d9b01f commit f83a4c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ydb/core/driver_lib/run/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,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) {
Expand Down Expand Up @@ -1708,6 +1711,7 @@ void TKikimrRunner::KikimrStop(bool graceful) {
ActorSystem->Send(new IEventHandle(NGRpcService::CreateGrpcPublisherServiceActorId(), {}, new TEvents::TEvPoisonPill));
}

THPTimer timer;
TIntrusivePtr<TDrainProgress> drainProgress(new TDrainProgress());
if (AppData->FeatureFlags.GetEnableDrainOnShutdown() && GracefulShutdownSupported && ActorSystem) {
drainProgress->OnSend();
Expand Down Expand Up @@ -1741,6 +1745,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);
Expand Down
1 change: 1 addition & 0 deletions ydb/core/driver_lib/run/run.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TKikimrRunner : public virtual TThrRefBase, private IGlobalObjectStorage {

bool EnabledGrpcService = false;
bool GracefulShutdownSupported = false;
TDuration MinDelayBeforeShutdown;
THolder<NSQS::TAsyncHttpServer> SqsHttp;

THolder<NYdb::TDriver> YdbDriver;
Expand Down
5 changes: 5 additions & 0 deletions ydb/core/protos/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,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;
Expand Down Expand Up @@ -1937,6 +1941,7 @@ message TAppConfig {
//optional TMemoryControllerConfig MemoryControllerConfig = 81; NB. exist in main
optional TGroupedMemoryLimiterConfig GroupedMemoryLimiterConfig = 82;
optional NKikimrReplication.TReplicationDefaults ReplicationConfig = 83;
optional TShutdownConfig ShutdownConfig = 84;

repeated TNamedConfig NamedConfigs = 100;
optional string ClusterYamlConfig = 101;
Expand Down

0 comments on commit f83a4c6

Please sign in to comment.