Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
BarkovBG committed Mar 13, 2024
1 parent f04a2a8 commit 1047df7
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 34 deletions.
52 changes: 30 additions & 22 deletions cloud/blockstore/libs/storage/volume/partition_requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -905,23 +905,27 @@ class TPartitionRequestActor final
ui32 requestNo,
NProto::TDescribeBlocksResponse* dst)
{
const uint32_t startIndex = srcRange.GetStartIndex();
uint32_t blocksCount = 0;
const ui32 startIndex = srcRange.GetStartIndex();
ui32 blocksCount = 0;

while (blocksCount < srcRange.GetBlocksCount()) {
auto rangeBlocksCount = std::min(
BlocksPerStripe,
srcRange.GetBlocksCount() - blocksCount);

NProto::TFreshBlockRange dstRange;
dstRange.SetStartIndex(RelativeToGlobalIndex(
const auto index = RelativeToGlobalIndex(
BlocksPerStripe,
startIndex + blocksCount,
PartitionsCount,
PartitionRequests[requestNo].PartitionId));
PartitionRequests[requestNo].PartitionId);

const auto stripeRange = GetStripeRange(BlocksPerStripe, index);

const auto rangeBlocksCount = std::min(
static_cast<ui64>(stripeRange.End) - index + 1,
static_cast<ui64>(srcRange.GetBlocksCount()) - blocksCount);

NProto::TFreshBlockRange dstRange;
dstRange.SetStartIndex(index);
dstRange.SetBlocksCount(rangeBlocksCount);
uint64_t bytesCount = static_cast<uint64_t>(rangeBlocksCount) * BlockSize / 8;
for (uint64_t i = 0; i < bytesCount; i++) {
const ui64 bytesCount = static_cast<ui64>(rangeBlocksCount) * BlockSize;
for (ui64 i = 0; i < bytesCount; i++) {
dstRange.MutableBlocksContent()->append(srcRange.GetBlocksContent()[i]);
}

Expand All @@ -936,22 +940,26 @@ class TPartitionRequestActor final
ui32 requestNo,
NProto::TBlobPiece *dstBlobPiece)
{
const uint32_t blobOffset = srcRange.GetBlobOffset();
const uint32_t blockIndex = srcRange.GetBlockIndex();
uint32_t blocksCount = 0;
const ui32 blobOffset = srcRange.GetBlobOffset();
const ui32 blockIndex = srcRange.GetBlockIndex();
ui32 blocksCount = 0;

while (blocksCount < srcRange.GetBlocksCount()) {
auto rangeBlocksCount = std::min(
const auto index = RelativeToGlobalIndex(
BlocksPerStripe,
srcRange.GetBlocksCount() - blocksCount);
blockIndex + blocksCount,
PartitionsCount,
PartitionRequests[requestNo].PartitionId);

const auto stripeRange = GetStripeRange(BlocksPerStripe, index);

const auto rangeBlocksCount = std::min(
static_cast<ui64>(stripeRange.End) - index + 1,
static_cast<ui64>(srcRange.GetBlocksCount()) - blocksCount);

NProto::TRangeInBlob dstRange;
dstRange.SetBlobOffset(blobOffset + blocksCount);
dstRange.SetBlockIndex(RelativeToGlobalIndex(
BlocksPerStripe,
blockIndex + blocksCount,
PartitionsCount,
PartitionRequests[requestNo].PartitionId));
dstRange.SetBlockIndex(index);
dstRange.SetBlocksCount(rangeBlocksCount);

blocksCount += rangeBlocksCount;
Expand Down Expand Up @@ -1172,4 +1180,4 @@ STFUNC(TPartitionRequestActor<TMethod>::StateWork)
}
}

} // namespace NCloud::NBlockStore::NStorage
} // namespace NCloud::NBlockStore::NStorage
Original file line number Diff line number Diff line change
Expand Up @@ -822,4 +822,4 @@ BLOCKSTORE_FORWARD_REQUEST(GetScanDiskStatus, TEvVolume)

#undef BLOCKSTORE_FORWARD_REQUEST

} // namespace NCloud::NBlockStore::NStorage
} // namespace NCloud::NBlockStore::NStorage
51 changes: 40 additions & 11 deletions cloud/blockstore/libs/storage/volume/volume_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,6 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
client1.ReconnectPipe();
client1.AddClient(clientInfo);
volume.WaitReady();

runtime->DispatchEvents({}, TDuration::Seconds(1));
UNIT_ASSERT(evRangeMigrated);

Expand Down Expand Up @@ -3679,14 +3678,14 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
UNIT_ASSERT_VALUES_EQUAL(8, message1.BlobPiecesSize());

const auto& blobPiece1 = message1.GetBlobPieces(0);
UNIT_ASSERT_VALUES_EQUAL(512, blobPiece1.RangesSize());
UNIT_ASSERT_VALUES_EQUAL(513, blobPiece1.RangesSize());
const auto& range1 = blobPiece1.GetRanges(0);
UNIT_ASSERT_VALUES_EQUAL(0, range1.GetBlobOffset());
UNIT_ASSERT_VALUES_EQUAL(0, range1.GetBlockIndex());
UNIT_ASSERT_VALUES_EQUAL(2, range1.GetBlocksCount());
UNIT_ASSERT_VALUES_EQUAL(1, range1.GetBlockIndex());
UNIT_ASSERT_VALUES_EQUAL(1, range1.GetBlocksCount());

const auto& range2 = blobPiece1.GetRanges(1);
UNIT_ASSERT_VALUES_EQUAL(2, range2.GetBlobOffset());
UNIT_ASSERT_VALUES_EQUAL(1, range2.GetBlobOffset());
UNIT_ASSERT_VALUES_EQUAL(4, range2.GetBlockIndex());
UNIT_ASSERT_VALUES_EQUAL(2, range2.GetBlocksCount());

Expand All @@ -3706,9 +3705,41 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
UNIT_ASSERT_VALUES_EQUAL(256, message2.FreshBlockRangesSize());
UNIT_ASSERT_VALUES_EQUAL(0, message2.BlobPiecesSize());

const auto& freshBlockRange = message2.GetFreshBlockRanges(0);
UNIT_ASSERT_VALUES_EQUAL(9216, freshBlockRange.GetStartIndex());
UNIT_ASSERT_VALUES_EQUAL(1, freshBlockRange.GetBlocksCount());
const auto& freshBlockRange1 = message2.GetFreshBlockRanges(0);
UNIT_ASSERT_VALUES_EQUAL(9216, freshBlockRange1.GetStartIndex());
UNIT_ASSERT_VALUES_EQUAL(1, freshBlockRange1.GetBlocksCount());

TString actualContent;
for (size_t i = 0; i < message2.FreshBlockRangesSize(); ++i) {
const auto& freshRange = message2.GetFreshBlockRanges(i);
actualContent += freshRange.GetBlocksContent();
}

UNIT_ASSERT_VALUES_EQUAL(range.Size() * DefaultBlockSize, actualContent.size());
for (size_t i = 0; i < actualContent.size(); i++) {
UNIT_ASSERT_VALUES_EQUAL('Y', actualContent[i]);
}

range = TBlockRange64::WithLength(10000, 1);
volume.WriteBlocks(range, clientInfo.GetClientId(), 'Z');

request = volume.CreateDescribeBlocksRequest(
range,
clientInfo.GetClientId()
);

volume.SendToPipe(std::move(request));
const auto response3 = volume.RecvResponse<TEvVolume::TEvDescribeBlocksResponse>();
const auto& message3 = response3->Record;

UNIT_ASSERT(SUCCEEDED(response3->GetStatus()));
UNIT_ASSERT_VALUES_EQUAL(1, message3.FreshBlockRangesSize());
UNIT_ASSERT_VALUES_EQUAL(0, message3.BlobPiecesSize());

const auto& freshBlockRange2 = message3.GetFreshBlockRanges(0);
UNIT_ASSERT_VALUES_EQUAL(10000, freshBlockRange2.GetStartIndex());
UNIT_ASSERT_VALUES_EQUAL(1, freshBlockRange2.GetBlocksCount());

}

Y_UNIT_TEST(ShouldHandleGetUsedBlocksRequest)
Expand Down Expand Up @@ -3966,7 +3997,6 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
NProto::TStorageServiceConfig config;
config.SetMinChannelCount(4);
auto runtime = PrepareTestActorRuntime(config);

TVolumeClient volume(*runtime);
volume.UpdateVolumeConfig(
0,
Expand Down Expand Up @@ -4966,7 +4996,6 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
.Build();

TVolumeClient volume(*runtime);

volume.UpdateVolumeConfig(
0,
0,
Expand Down Expand Up @@ -8055,4 +8084,4 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
}
}

} // namespace NCloud::NBlockStore::NStorage
} // namespace NCloud::NBlockStore::NStorage

0 comments on commit 1047df7

Please sign in to comment.