Skip to content
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

[merge to stable 23-3] NBSNEBIUS-41: don't release NRD session on retriable errors (#430) #497

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ TString LogDevices(const TVector<NProto::TDeviceConfig>& devices)
for (const auto& d: devices) {
sb << d.GetDeviceUUID() << "@" << d.GetAgentId() << " ";
}
sb << ")";
return sb;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include <cloud/blockstore/libs/kikimr/events.h>

#include <util/string/join.h>
#include <util/generic/cast.h>

namespace NCloud::NBlockStore::NStorage {

using namespace NActors;
Expand Down Expand Up @@ -52,23 +55,20 @@ class TAcquireDiskActor final

void StartAcquireDisk(const TActorContext& ctx);
void FinishAcquireDisk(const TActorContext& ctx);

void CancelAcquireOperation(const TActorContext& ctx, NProto::TError error);
void FinishAcquireDisk(const TActorContext& ctx, NProto::TError error);

void ReplyAndDie(const TActorContext& ctx, NProto::TError error);

void OnAcquireResponse(const TActorContext& ctx, NProto::TError error);
void OnReleaseResponse(
void OnAcquireResponse(
const TActorContext& ctx,
ui64 cookie,
ui32 nodeId,
NProto::TError error);

template <typename R>
void SendRequests(const TActorContext& ctx);

private:
STFUNC(StateAcquire);
STFUNC(StateRelease);
STFUNC(StateFinish);

void HandlePoisonPill(
Expand All @@ -79,10 +79,6 @@ class TAcquireDiskActor final
const TEvDiskAgent::TEvAcquireDevicesResponse::TPtr& ev,
const TActorContext& ctx);

void HandleReleaseDevicesResponse(
const TEvDiskAgent::TEvReleaseDevicesResponse::TPtr& ev,
const TActorContext& ctx);

void HandleStartAcquireDiskResponse(
const TEvDiskRegistryPrivate::TEvStartAcquireDiskResponse::TPtr& ev,
const TActorContext& ctx);
Expand All @@ -95,10 +91,6 @@ class TAcquireDiskActor final
const TEvDiskAgent::TEvAcquireDevicesRequest::TPtr& ev,
const TActorContext& ctx);

void HandleReleaseDevicesUndelivery(
const TEvDiskAgent::TEvReleaseDevicesRequest::TPtr& ev,
const TActorContext& ctx);

void HandleWakeup(
const TEvents::TEvWakeup::TPtr& ev,
const TActorContext& ctx);
Expand Down Expand Up @@ -150,6 +142,14 @@ void TAcquireDiskActor::FinishAcquireDisk(const TActorContext& ctx)
NCloud::Send(ctx, Owner, std::make_unique<TType>(DiskId, ClientId));
}

void TAcquireDiskActor::FinishAcquireDisk(
const TActorContext& ctx,
NProto::TError error)
{
AcquireError = std::move(error);
FinishAcquireDisk(ctx);
}

void TAcquireDiskActor::PrepareRequest(NProto::TAcquireDevicesRequest& request)
{
request.MutableHeaders()->SetClientId(ClientId);
Expand All @@ -168,7 +168,6 @@ template <typename R>
void TAcquireDiskActor::SendRequests(const TActorContext& ctx)
{
auto it = Devices.begin();
ui32 cookie = 0;
while (it != Devices.end()) {
auto request = std::make_unique<R>();
PrepareRequest(request->Record);
Expand All @@ -181,42 +180,25 @@ void TAcquireDiskActor::SendRequests(const TActorContext& ctx)

++PendingRequests;

LOG_DEBUG(ctx, TBlockStoreComponents::DISK_REGISTRY_WORKER,
"[%s] Send an acquire request to node #%d. Devices: %s",
ClientId.c_str(),
nodeId,
JoinSeq(", ", request->Record.GetDeviceUUIDs()).c_str());

auto event = std::make_unique<IEventHandle>(
MakeDiskAgentServiceId(nodeId),
ctx.SelfID,
request.release(),
IEventHandle::FlagForwardOnNondelivery,
cookie++,
nodeId,
&ctx.SelfID // forwardOnNondelivery
);

ctx.Send(event.release());
}
}

void TAcquireDiskActor::CancelAcquireOperation(
const TActorContext& ctx,
NProto::TError error)
{
Become(&TThis::StateRelease);

AcquireError = std::move(error);

LOG_DEBUG(ctx, TBlockStoreComponents::DISK_REGISTRY_WORKER,
"[%s] Canceling acquire operation for disk %s, targets %s",
ClientId.c_str(),
DiskId.c_str(),
LogTargets().c_str());

if (Devices.empty()) {
ReplyAndDie(ctx, AcquireError);
return;
}

PendingRequests = 0;
SendRequests<TEvDiskAgent::TEvReleaseDevicesRequest>(ctx);
}

void TAcquireDiskActor::ReplyAndDie(const TActorContext& ctx, NProto::TError error)
{
auto response = std::make_unique<TEvDiskRegistry::TEvAcquireDiskResponse>(
Expand Down Expand Up @@ -259,94 +241,67 @@ void TAcquireDiskActor::HandlePoisonPill(

void TAcquireDiskActor::OnAcquireResponse(
const TActorContext& ctx,
ui32 nodeId,
NProto::TError error)
{
Y_ABORT_UNLESS(PendingRequests > 0);

if (HasError(error)) {
LOG_ERROR(ctx, TBlockStoreComponents::DISK_REGISTRY_WORKER,
"[%s] AcquireDevices %s error: %s",
"[%s] AcquireDevices on the node #%d %s error: %s",
ClientId.c_str(),
nodeId,
LogTargets().c_str(),
FormatError(error).c_str());

CancelAcquireOperation(ctx, std::move(error));
FinishAcquireDisk(ctx);
return;
}
if (GetErrorKind(error) != EErrorKind::ErrorRetriable) {
LOG_DEBUG(ctx, TBlockStoreComponents::DISK_REGISTRY_WORKER,
"[%s] Canceling acquire operation for disk %s, targets %s",
ClientId.c_str(),
DiskId.c_str(),
LogTargets().c_str());

Y_ABORT_UNLESS(PendingRequests > 0);
SendRequests<TEvDiskAgent::TEvReleaseDevicesRequest>(ctx);
}

if (--PendingRequests == 0) {
FinishAcquireDisk(ctx);
}
}
FinishAcquireDisk(ctx, std::move(error));

void TAcquireDiskActor::OnReleaseResponse(
const TActorContext& ctx,
ui64 cookie,
NProto::TError error)
{
if (HasError(error)) {
LOG_ERROR(ctx, TBlockStoreComponents::DISK_REGISTRY_WORKER,
"[%s] ReleaseDevices %s error: %s, %llu",
ClientId.c_str(),
LogTargets().c_str(),
FormatError(error).c_str(),
cookie);
return;
}

Y_ABORT_UNLESS(PendingRequests > 0);

if (--PendingRequests == 0) {
ReplyAndDie(ctx, AcquireError);
FinishAcquireDisk(ctx);
}
}

void TAcquireDiskActor::HandleAcquireDevicesResponse(
const TEvDiskAgent::TEvAcquireDevicesResponse::TPtr& ev,
const TActorContext& ctx)
{
OnAcquireResponse(ctx, ev->Get()->GetError());
}

void TAcquireDiskActor::HandleReleaseDevicesResponse(
const TEvDiskAgent::TEvReleaseDevicesResponse::TPtr& ev,
const TActorContext& ctx)
{
OnReleaseResponse(ctx, ev->Cookie, ev->Get()->GetError());
OnAcquireResponse(
ctx,
SafeIntegerCast<ui32>(ev->Cookie),
ev->Get()->GetError());
}

void TAcquireDiskActor::HandleAcquireDevicesUndelivery(
const TEvDiskAgent::TEvAcquireDevicesRequest::TPtr& ev,
const TActorContext& ctx)
{
Y_UNUSED(ev);

OnAcquireResponse(ctx, MakeError(E_REJECTED, "not delivered"));
}

void TAcquireDiskActor::HandleReleaseDevicesUndelivery(
const TEvDiskAgent::TEvReleaseDevicesRequest::TPtr& ev,
const TActorContext& ctx)
{
OnReleaseResponse(ctx, ev->Cookie, MakeError(E_REJECTED, "not delivered"));
OnAcquireResponse(
ctx,
SafeIntegerCast<ui32>(ev->Cookie),
MakeError(E_REJECTED, "not delivered"));
}

void TAcquireDiskActor::HandleWakeup(
const TEvents::TEvWakeup::TPtr& ev,
const TActorContext& ctx)
{
Y_UNUSED(ev);

const auto err = Sprintf(
"[%s] TAcquireDiskActor timeout, targets %s, pending requests: %d",
ClientId.c_str(),
LogTargets().c_str(),
PendingRequests);
LOG_ERROR(ctx, TBlockStoreComponents::DISK_REGISTRY_WORKER, err);

AcquireError = MakeError(E_REJECTED, err);

FinishAcquireDisk(ctx);
OnAcquireResponse(
ctx,
SafeIntegerCast<ui32>(ev->Cookie),
MakeError(E_REJECTED, "timeout"));
}

void TAcquireDiskActor::HandleStartAcquireDiskResponse(
Expand All @@ -364,16 +319,14 @@ void TAcquireDiskActor::HandleStartAcquireDiskResponse(
Devices = msg->Devices;

if (Devices.empty()) {
FinishAcquireDisk(ctx);
FinishAcquireDisk(ctx, MakeError(E_REJECTED, "nothing to acquire"));
return;
}

SortBy(Devices, [](auto& d) {
SortBy(Devices, [] (auto& d) {
return d.GetNodeId();
});

// TODO: setup rate limits

LOG_DEBUG(ctx, TBlockStoreComponents::DISK_REGISTRY_WORKER,
"[%s] Sending acquire devices requests for disk %s, targets %s",
ClientId.c_str(),
Expand All @@ -387,17 +340,7 @@ void TAcquireDiskActor::HandleFinishAcquireDiskResponse(
const TEvDiskRegistryPrivate::TEvFinishAcquireDiskResponse::TPtr& ev,
const TActorContext& ctx)
{
const auto* msg = ev->Get();
if (HasError(msg->GetError())) {
LOG_ERROR(ctx, TBlockStoreComponents::DISK_REGISTRY_WORKER,
"[%s] FinishAcquireDisk targets %s error: %s",
ClientId.c_str(),
LogTargets().c_str(),
FormatError(msg->GetError()).c_str());

CancelAcquireOperation(ctx, msg->GetError());
return;
}
Y_UNUSED(ev);

ReplyAndDie(ctx, AcquireError);
}
Expand Down Expand Up @@ -432,27 +375,6 @@ STFUNC(TAcquireDiskActor::StateAcquire)
}
}

STFUNC(TAcquireDiskActor::StateRelease)
{
switch (ev->GetTypeRewrite()) {
HFunc(TEvents::TEvPoisonPill, HandlePoisonPill);

HFunc(TEvDiskAgent::TEvReleaseDevicesResponse,
HandleReleaseDevicesResponse);
HFunc(TEvDiskAgent::TEvReleaseDevicesRequest,
HandleReleaseDevicesUndelivery);

HFunc(TEvents::TEvWakeup, HandleWakeup);

IgnoreFunc(TEvDiskAgent::TEvAcquireDevicesResponse);
IgnoreFunc(TEvDiskAgent::TEvAcquireDevicesRequest);

default:
HandleUnexpectedEvent(ev, TBlockStoreComponents::DISK_REGISTRY_WORKER);
break;
}
}

STFUNC(TAcquireDiskActor::StateFinish)
{
switch (ev->GetTypeRewrite()) {
Expand Down
Loading
Loading