Skip to content

24-3: Add min delay before shutdown (#9688) #10087

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 1 commit into from
Oct 7, 2024
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
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 @@ -1698,6 +1701,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 @@ -1731,6 +1735,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 @@ -1822,6 +1822,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 @@ -1904,6 +1908,7 @@ message TAppConfig {
optional TLimiterConfig CompDiskLimiterConfig = 79;
optional TMetadataCacheConfig MetadataCacheConfig = 80;
optional NKikimrReplication.TReplicationDefaults ReplicationConfig = 83;
optional TShutdownConfig ShutdownConfig = 84;

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