Skip to content

Fix BSC vs Console interaction #17752

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
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
44 changes: 26 additions & 18 deletions ydb/core/mind/bscontroller/console_interaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ namespace NKikimr::NBsController {
void TBlobStorageController::TConsoleInteraction::Handle(TEvTabletPipe::TEvClientConnected::TPtr& /*ev*/) {
}

void TBlobStorageController::TConsoleInteraction::Handle(TEvTabletPipe::TEvClientDestroyed::TPtr& /*ev*/) {
void TBlobStorageController::TConsoleInteraction::Handle(TEvTabletPipe::TEvClientDestroyed::TPtr& ev) {
STLOG(PRI_DEBUG, BS_CONTROLLER, BSC33, "Console pipe destroyed", (ConsolePipe, ConsolePipe),
(ClientId, ev->Get()->ClientId), (Working, Working));
ConsolePipe = {};
if (Working) {
if (ClientId) {
Expand All @@ -56,17 +58,13 @@ namespace NKikimr::NBsController {
}

void TBlobStorageController::TConsoleInteraction::MakeGetBlock() {
STLOG(PRI_DEBUG, BS_CONTROLLER, BSC34, "Issuing GetBlock for BSC");
auto ev = std::make_unique<TEvBlobStorage::TEvGetBlock>(Self.TabletID(), TInstant::Max());
auto bsProxyEv = CreateEventForBSProxy(Self.SelfId(), Self.Info()->GroupFor(0, Self.Executor()->Generation()),
ev.release(), 0);
TActivationContext::Schedule(TDuration::MilliSeconds(GetBlockBackoff.NextBackoffMs()), bsProxyEv);
}

void TBlobStorageController::TConsoleInteraction::MakeRetrySession() {
NeedRetrySession = false;
Start();
}

void TBlobStorageController::TConsoleInteraction::Handle(TEvBlobStorage::TEvControllerProposeConfigResponse::TPtr &ev) {
if (!Working) {
return;
Expand Down Expand Up @@ -186,8 +184,10 @@ namespace NKikimr::NBsController {
}

void TBlobStorageController::TConsoleInteraction::Stop() {
STLOG(PRI_DEBUG, BS_CONTROLLER, BSC35, "Stopping console interaction", (ConsolePipe, ConsolePipe), (Working, Working));
if (ConsolePipe) {
NTabletPipe::CloseClient(Self.SelfId(), ConsolePipe);
ConsolePipe = {};
}
Working = false;
}
Expand All @@ -200,8 +200,8 @@ namespace NKikimr::NBsController {
auto& record = ev->Get()->Record;
switch (auto status = record.GetStatus()) {
case NKikimrBlobStorage::TEvControllerConsoleCommitResponse::SessionMismatch:
NTabletPipe::CloseAndForgetClient(Self.SelfId(), ConsolePipe);
MakeGetBlock();
NeedRetrySession = true;
break;

case NKikimrBlobStorage::TEvControllerConsoleCommitResponse::NotCommitted:
Expand All @@ -226,10 +226,13 @@ namespace NKikimr::NBsController {
auto& record = ev->Get()->Record;

const bool reasonOngoingCommit = CommitInProgress || (ClientId && ClientId != ev->Sender);
if (reasonOngoingCommit || (!Self.EnableConfigV2 && !record.GetSwitchEnableConfigV2())) {
if (!ConsolePipe || reasonOngoingCommit || (!Self.EnableConfigV2 && !record.GetSwitchEnableConfigV2())) {
// reply to newly came query
const TActorId temp = std::exchange(ClientId, ev->Sender);
if (reasonOngoingCommit) {
if (!ConsolePipe) {
IssueGRpcResponse(NKikimrBlobStorage::TEvControllerReplaceConfigResponse::SessionClosed,
"connection to Console tablet terminated");
} else if (reasonOngoingCommit) {
IssueGRpcResponse(NKikimrBlobStorage::TEvControllerReplaceConfigResponse::OngoingCommit, "ongoing commit");
} else {
IssueGRpcResponse(NKikimrBlobStorage::TEvControllerReplaceConfigResponse::InvalidRequest, "configuration v2 is disabled", true);
Expand Down Expand Up @@ -400,6 +403,8 @@ namespace NKikimr::NBsController {
validateConfigEv->Record.SetYAML(record.GetClusterYaml());
validateConfigEv->Record.SetAllowUnknownFields(record.GetAllowUnknownFields());
validateConfigEv->Record.SetBypassMetadataChecks(record.GetBypassMetadataChecks());
STLOG(PRI_DEBUG, BS_CONTROLLER, BSC36, "Sending TEvControllerValidateConfigRequest to console",
(ConsolePipe, ConsolePipe));
NTabletPipe::SendData(Self.SelfId(), ConsolePipe, validateConfigEv.release());
}

Expand Down Expand Up @@ -451,8 +456,8 @@ namespace NKikimr::NBsController {
auto& record = ev->Get()->Record;
switch (auto status = record.GetStatus()) {
case NKikimrBlobStorage::TEvControllerValidateConfigResponse::IdPipeServerMismatch:
NTabletPipe::CloseAndForgetClient(Self.SelfId(), ConsolePipe);
MakeGetBlock();
NeedRetrySession = true;
return;

case NKikimrBlobStorage::TEvControllerValidateConfigResponse::ConfigNotValid:
Expand Down Expand Up @@ -531,22 +536,25 @@ namespace NKikimr::NBsController {
}

void TBlobStorageController::TConsoleInteraction::Handle(TEvBlobStorage::TEvGetBlockResult::TPtr& ev) {
auto* msg = ev->Get();

STLOG(PRI_DEBUG, BS_CONTROLLER, BSC37, "TEvGetBlockResult received", (ConsolePipe, ConsolePipe),
(Working, Working), (Status, msg->Status), (BlockedGeneration, msg->BlockedGeneration),
(Generation, Self.Executor()->Generation()));

if (!Working) {
return;
}
auto* msg = ev->Get();
auto status = msg->Status;

auto blockedGeneration = msg->BlockedGeneration;
auto generation = Self.Executor()->Generation();
switch (status) {
switch (msg->Status) {
case NKikimrProto::OK:
if (generation <= blockedGeneration) {
Self.HandlePoison(TActivationContext::AsActorContext());
return;
return Self.HandlePoison(TActivationContext::AsActorContext());
}
if (generation == blockedGeneration + 1 && NeedRetrySession) {
MakeRetrySession();
return;
if (generation == blockedGeneration + 1 && !ConsolePipe) {
return Start();
}
Y_VERIFY_DEBUG_S(generation == blockedGeneration + 1, "BlockedGeneration#" << blockedGeneration
<< " Tablet generation#" << generation);
Expand Down
2 changes: 0 additions & 2 deletions ydb/core/mind/bscontroller/console_interaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ namespace NKikimr::NBsController {
ui64 ExpectedValidationTimeoutCookie = 0;
TBackoffTimer GetBlockBackoff{1, 1000};
ui32 BlockedGeneration = 0;
bool NeedRetrySession = false;
bool Working = false;
bool CommitInProgress = false;
std::optional<bool> SwitchEnableConfigV2;
Expand All @@ -58,7 +57,6 @@ namespace NKikimr::NBsController {

void MakeCommitToConsole(TString& config, ui32 configVersion);
void MakeGetBlock();
void MakeRetrySession();

void IssueGRpcResponse(NKikimrBlobStorage::TEvControllerReplaceConfigResponse::EStatus status,
std::optional<TString> errorReason = std::nullopt, bool disabledConfigV2 = false);
Expand Down
Loading