Skip to content

Commit

Permalink
check range
Browse files Browse the repository at this point in the history
  • Loading branch information
Sazonov99 committed Jan 31, 2025
1 parent 822f023 commit 044bd29
Show file tree
Hide file tree
Showing 42 changed files with 2,171 additions and 0 deletions.
1 change: 1 addition & 0 deletions cloud/blockstore/libs/service/auth_scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ TPermissionList GetRequestPermissions(EBlockStoreRequest requestType)
case EBlockStoreRequest::ZeroBlocks:
case EBlockStoreRequest::ReadBlocksLocal:
case EBlockStoreRequest::WriteBlocksLocal:
case EBlockStoreRequest::CheckRange:
return CreatePermissionList({});

case EBlockStoreRequest::MountVolume:
Expand Down
1 change: 1 addition & 0 deletions cloud/blockstore/libs/service/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ using TWriteBlocksLocalResponse = TWriteBlocksResponse;
xxx(CreateVolumeFromDevice, __VA_ARGS__) \
xxx(ResumeDevice, __VA_ARGS__) \
xxx(QueryAgentsInfo, __VA_ARGS__) \
xxx(CheckRange, __VA_ARGS__) \
// BLOCKSTORE_GRPC_STORAGE_SERVICE

#define BLOCKSTORE_ENDPOINT_SERVICE(xxx, ...) \
Expand Down
1 change: 1 addition & 0 deletions cloud/blockstore/libs/service/request_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ constexpr bool IsControlRequest(EBlockStoreRequest requestType)
case EBlockStoreRequest::ReadBlocksLocal:
case EBlockStoreRequest::WriteBlocksLocal:
case EBlockStoreRequest::QueryAvailableStorage:
case EBlockStoreRequest::CheckRange:
return false;
case EBlockStoreRequest::CreateVolume:
case EBlockStoreRequest::DestroyVolume:
Expand Down
1 change: 1 addition & 0 deletions cloud/blockstore/libs/storage/api/partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace NCloud::NBlockStore::NStorage::NPartition {
xxx(GetRebuildMetadataStatus, __VA_ARGS__) \
xxx(ScanDisk, __VA_ARGS__) \
xxx(GetScanDiskStatus, __VA_ARGS__) \
xxx(CheckRange, __VA_ARGS__) \
// BLOCKSTORE_PARTITION_REQUESTS_FWD_VOLUME

////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions cloud/blockstore/libs/storage/api/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ struct TEvService
EvAddTagsRequest = EvBegin + 91,
EvAddTagsResponse = EvBegin + 92,

EvCheckRangeRequest = EvBegin + 93,
EvCheckRangeResponse = EvBegin + 94,

EvEnd
};

Expand Down
5 changes: 5 additions & 0 deletions cloud/blockstore/libs/storage/api/volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace NCloud::NBlockStore::NStorage {
xxx(ChangeStorageConfig, __VA_ARGS__) \
xxx(GetStorageConfig, __VA_ARGS__) \
xxx(GracefulShutdown, __VA_ARGS__) \
xxx(CheckRange, __VA_ARGS__) \

// BLOCKSTORE_VOLUME_REQUESTS

Expand Down Expand Up @@ -65,6 +66,7 @@ namespace NCloud::NBlockStore::NStorage {
xxx(GetRebuildMetadataStatus, __VA_ARGS__) \
xxx(ScanDisk, __VA_ARGS__) \
xxx(GetScanDiskStatus, __VA_ARGS__) \
xxx(CheckRange, __VA_ARGS__) \
// BLOCKSTORE_VOLUME_HANDLED_RESPONSES

// responses for the requests forwarded from service which are forwarded back
Expand Down Expand Up @@ -335,6 +337,9 @@ struct TEvVolume
EvGracefulShutdownRequest = EvBegin + 60,
EvGracefulShutdownResponse = EvBegin + 61,

EvCheckRangeRequest = EvBegin + 62,
EvCheckRangeResponse = EvBegin + 63,

EvEnd
};

Expand Down
6 changes: 6 additions & 0 deletions cloud/blockstore/libs/storage/partition/part_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ class TPartitionActor final
TDuration retryTimeout,
TBlockBuffer blockBuffer);

NActors::IActorPtr CreateCheckRangeActor(
NActors::TActorId tablet,
ui64 startIndex,
ui64 blocksCount,
TEvVolume::TEvCheckRangeRequest::TPtr ev);

private:
STFUNC(StateBoot);
STFUNC(StateInit);
Expand Down
218 changes: 218 additions & 0 deletions cloud/blockstore/libs/storage/partition/part_actor_checkrange.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
#include "part_actor.h"

#include <cloud/blockstore/libs/service/context.h>
#include <cloud/blockstore/libs/storage/core/config.h>
#include <cloud/blockstore/libs/storage/core/probes.h>

#include <contrib/ydb/library/actors/core/actor_bootstrapped.h>

#include <util/datetime/base.h>
#include <util/generic/algorithm.h>
#include <util/generic/guid.h>
#include <util/generic/string.h>
#include <util/generic/vector.h>
#include <util/generic/xrange.h>
#include <util/stream/str.h>

namespace NCloud::NBlockStore::NStorage::NPartition {

using namespace NActors;

using namespace NKikimr;

LWTRACE_USING(BLOCKSTORE_STORAGE_PROVIDER);

namespace {

////////////////////////////////////////////////////////////////////////////////

class TCheckRangeActor final: public TActorBootstrapped<TCheckRangeActor>
{
private:
const TActorId Tablet;
const ui64 StartIndex;
const ui64 BlocksCount;
const TEvVolume::TEvCheckRangeRequest::TPtr Ev;

public:
TCheckRangeActor(
const TActorId& tablet,
ui64 startIndex,
ui64 blocksCount,
TEvVolume::TEvCheckRangeRequest::TPtr&& ev);

void Bootstrap(const TActorContext& ctx);

private:
void ReplyAndDie(
const TActorContext& ctx,
const NProto::TError& error = {});

void HandleReadBlocksResponse(
const TEvService::TEvReadBlocksResponse::TPtr& ev,
const TActorContext& ctx);

void SendReadBlocksRequest(const TActorContext& ctx);

private:
STFUNC(StateWork);

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

void HandlePoisonPill(
const TEvents::TEvPoisonPill::TPtr& ev,
const TActorContext& ctx);
};

////////////////////////////////////////////////////////////////////////////////

TCheckRangeActor::TCheckRangeActor(
const TActorId& tablet,
ui64 startIndex,
ui64 blocksCount,
TEvVolume::TEvCheckRangeRequest::TPtr&& ev)
: Tablet(tablet)
, StartIndex(startIndex)
, BlocksCount(blocksCount)
, Ev(std::move(ev))
{}

void TCheckRangeActor::Bootstrap(const TActorContext& ctx)
{
SendReadBlocksRequest(ctx);
Become(&TThis::StateWork);
}

void TCheckRangeActor::SendReadBlocksRequest(const TActorContext& ctx)
{
auto request = std::make_unique<TEvService::TEvReadBlocksRequest>();

request->Record.SetStartIndex(StartIndex);
request->Record.SetBlocksCount(BlocksCount);

auto* headers = request->Record.MutableHeaders();

headers->SetIsBackgroundRequest(true);
NCloud::Send(ctx, Tablet, std::move(request));
}

void TCheckRangeActor::ReplyAndDie(
const TActorContext& ctx,
const NProto::TError& error)
{
auto response =
std::make_unique<TEvVolume::TEvCheckRangeResponse>(std::move(error));

NCloud::Reply(ctx, *Ev, std::move(response));

Die(ctx);
}

////////////////////////////////////////////////////////////////////////////////

STFUNC(TCheckRangeActor::StateWork)
{
switch (ev->GetTypeRewrite()) {
HFunc(TEvents::TEvPoisonPill, HandlePoisonPill);
HFunc(TEvents::TEvWakeup, HandleWakeup);
HFunc(TEvService::TEvReadBlocksResponse, HandleReadBlocksResponse);
default:
HandleUnexpectedEvent(ev, TBlockStoreComponents::PARTITION_WORKER);
break;
}
}

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

void TCheckRangeActor::HandlePoisonPill(
const TEvents::TEvPoisonPill::TPtr& ev,
const TActorContext& ctx)
{
Y_UNUSED(ev);

auto error = MakeError(E_REJECTED, "tablet is shutting down");

ReplyAndDie(ctx, error);
}

void TCheckRangeActor::HandleReadBlocksResponse(
const TEvService::TEvReadBlocksResponse::TPtr& ev,
const TActorContext& ctx)
{
const auto* msg = ev->Get();
auto error = MakeError(S_OK);

if (HasError(msg->Record.GetError())) {
auto errorMessage = msg->Record.GetError().GetMessage();
LOG_ERROR(
ctx,
TBlockStoreComponents::VOLUME,
"reading error has occurred: " + errorMessage + " message " +
msg->Record.GetError().message());
auto errorCode =
msg->Record.GetError().code() == E_ARGUMENT ? E_ARGUMENT : E_IO;
error = MakeError(errorCode, msg->Record.GetError().GetMessage());
}

ReplyAndDie(ctx, error);
}

} // namespace

//////////////////////////////////////////////////////////////////

NActors::IActorPtr TPartitionActor::CreateCheckRangeActor(
NActors::TActorId tablet,
ui64 startIndex,
ui64 blocksCount,
TEvVolume::TEvCheckRangeRequest::TPtr ev)
{
return std::make_unique<NPartition::TCheckRangeActor>(
std::move(tablet),
startIndex,
blocksCount,
std::move(ev));
}

void NPartition::TPartitionActor::HandleCheckRange(
const TEvVolume::TEvCheckRangeRequest::TPtr& ev,
const TActorContext& ctx)
{
const auto* msg = ev->Get();

if (msg->Record.GetBlocksCount() >
Config->GetBytesPerStripe() / State->GetBlockSize())
{
auto err = MakeError(
E_ARGUMENT,
"Too many blocks requested: " +
std::to_string(msg->Record.GetBlocksCount()) +
" Max blocks per request : " +
std::to_string(
Config->GetBytesPerStripe() / State->GetBlockSize()));
auto response =
std::make_unique<TEvVolume::TEvCheckRangeResponse>(std::move(err));
NCloud::Reply(ctx, *ev, std::move(response));
return;
}

const auto actorId = NCloud::Register(
ctx,
CreateCheckRangeActor(
SelfId(),
msg->Record.GetStartIndex(),
msg->Record.GetBlocksCount(),
std::move(ev)));

Actors.Insert(actorId);
}

} // namespace NCloud::NBlockStore::NStorage::NPartition
Loading

0 comments on commit 044bd29

Please sign in to comment.