Skip to content

fix redirects for serverless databases #13856

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
24 changes: 18 additions & 6 deletions ydb/core/viewer/json_pipe_req.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,15 @@ void TViewerPipeClient::RequestDone(ui32 requests) {
if (!DelayedRequests.empty()) {
SendDelayedRequests();
}
if (Requests == 0) {
if (Requests == 0 && !PassedAway) {
ReplyAndPassAway();
}
}

void TViewerPipeClient::CancelAllRequests() {
DelayedRequests.clear();
}

void TViewerPipeClient::Handle(TEvTabletPipe::TEvClientConnected::TPtr& ev) {
if (ev->Get()->Status != NKikimrProto::OK) {
ui32 requests = FailPipeConnect(ev->Get()->TabletId);
Expand All @@ -826,12 +830,14 @@ void TViewerPipeClient::HandleResolveResource(TEvTxProxySchemeCache::TEvNavigate
Bootstrap(); // retry bootstrap without redirect this time
} else {
DatabaseBoardInfoResponse = MakeRequestStateStorageEndpointsLookup(SharedDatabase);
--Requests; // don't count this request
}
} else {
return ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", "Failed to resolve database - shared database not found"));
AddEvent("Failed to resolve database - shared database not found");
Direct = true;
Bootstrap(); // retry bootstrap without redirect this time
}
}
RequestDone();
}

void TViewerPipeClient::HandleResolveDatabase(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev) {
Expand All @@ -841,15 +847,18 @@ void TViewerPipeClient::HandleResolveDatabase(TEvTxProxySchemeCache::TEvNavigate
TSchemeCacheNavigate::TEntry& entry(DatabaseNavigateResponse->Get()->Request->ResultSet.front());
if (entry.DomainInfo && entry.DomainInfo->ResourcesDomainKey && entry.DomainInfo->DomainKey != entry.DomainInfo->ResourcesDomainKey) {
ResourceNavigateResponse = MakeRequestSchemeCacheNavigate(TPathId(entry.DomainInfo->ResourcesDomainKey));
--Requests; // don't count this request
Become(&TViewerPipeClient::StateResolveResource);
} else {
DatabaseBoardInfoResponse = MakeRequestStateStorageEndpointsLookup(CanonizePath(entry.Path));
--Requests; // don't count this request
}
} else {
return ReplyAndPassAway(GetHTTPBADREQUEST("text/plain", "Failed to resolve database - not found"));
AddEvent("Failed to resolve database - not found");
Direct = true;
Bootstrap(); // retry bootstrap without redirect this time
}
}
RequestDone();
}

void TViewerPipeClient::HandleResolve(TEvStateStorage::TEvBoardInfo::TPtr& ev) {
Expand All @@ -858,11 +867,11 @@ void TViewerPipeClient::HandleResolve(TEvStateStorage::TEvBoardInfo::TPtr& ev) {
if (DatabaseBoardInfoResponse->IsOk()) {
return ReplyAndPassAway(MakeForward(GetNodesFromBoardReply(DatabaseBoardInfoResponse->GetRef())));
} else {
AddEvent("Failed to resolve database nodes");
Direct = true;
Bootstrap(); // retry bootstrap without redirect this time
}
}
RequestDone();
}

void TViewerPipeClient::HandleTimeout() {
Expand All @@ -887,6 +896,7 @@ STATEFN(TViewerPipeClient::StateResolveResource) {

void TViewerPipeClient::RedirectToDatabase(const TString& database) {
DatabaseNavigateResponse = MakeRequestSchemeCacheNavigate(database);
--Requests; // don't count this request
Become(&TViewerPipeClient::StateResolveDatabase);
}

Expand All @@ -913,6 +923,8 @@ void TViewerPipeClient::PassAway() {
Send(TActivationContext::InterconnectProxy(nodeId), new TEvents::TEvUnsubscribe());
}
ClosePipes();
CancelAllRequests();
PassedAway = true;
TBase::PassAway();
}

Expand Down
2 changes: 2 additions & 0 deletions ydb/core/viewer/json_pipe_req.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TViewerPipeClient : public TActorBootstrapped<TViewerPipeClient> {
TString SharedDatabase;
bool Direct = false;
ui32 Requests = 0;
bool PassedAway = false;
ui32 MaxRequestsInFlight = 200;
NWilson::TSpan Span;
IViewer* Viewer = nullptr;
Expand Down Expand Up @@ -308,6 +309,7 @@ class TViewerPipeClient : public TActorBootstrapped<TViewerPipeClient> {
TString MakeForward(const std::vector<ui32>& nodes);

void RequestDone(ui32 requests = 1);
void CancelAllRequests();
void AddEvent(const TString& name);
void Handle(TEvTabletPipe::TEvClientConnected::TPtr& ev);
void HandleResolveDatabase(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev);
Expand Down
Loading