Skip to content

Commit

Permalink
issue-324: implemented LazyBlockBuffer and using it in TIndexTabletAc…
Browse files Browse the repository at this point in the history
…tor::HandleDescribeData (#523)
  • Loading branch information
qkrorlqr authored and Maxim Deb Natkh committed Feb 21, 2024
1 parent f9c1ed8 commit 6f7d720
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
63 changes: 63 additions & 0 deletions cloud/filestore/libs/storage/model/block_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,64 @@ class TBlockBuffer final
}
};

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

class TLazyBlockBuffer final
: public IBlockBuffer
{
private:
const TByteRange ByteRange;
TString UnalignedHead;
TVector<TString> Blocks;
TString UnalignedTail;

public:
explicit TLazyBlockBuffer(TByteRange byteRange)
: ByteRange(byteRange)
, Blocks(ByteRange.BlockCount())
{
}

TStringBuf GetUnalignedHead() override
{
if (!UnalignedHead) {
UnalignedHead.ReserveAndResize(ByteRange.UnalignedHeadLength());
}

return UnalignedHead;
}

TStringBuf GetUnalignedTail() override
{
if (!UnalignedTail) {
UnalignedTail.ReserveAndResize(ByteRange.UnalignedTailLength());
}

return UnalignedTail;
}

TStringBuf GetBlock(size_t index) override
{
auto& block = Blocks[index];
if (!block) {
block.ReserveAndResize(ByteRange.BlockSize);
}

return block;
}

void SetBlock(size_t index, TStringBuf block) override
{
Y_ABORT_UNLESS(block.size() == ByteRange.BlockSize);
Blocks[index] = block;
}

void ClearBlock(size_t index) override
{
Blocks[index].clear();
}
};

} // namespace

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -78,6 +136,11 @@ IBlockBufferPtr CreateBlockBuffer(TByteRange byteRange, TString buffer)
return std::make_shared<TBlockBuffer>(byteRange, std::move(buffer));
}

IBlockBufferPtr CreateLazyBlockBuffer(TByteRange byteRange)
{
return std::make_shared<TLazyBlockBuffer>(byteRange);
}

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

void CopyFileData(
Expand Down
1 change: 1 addition & 0 deletions cloud/filestore/libs/storage/model/block_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct IBlockBuffer

IBlockBufferPtr CreateBlockBuffer(TByteRange byteRange);
IBlockBufferPtr CreateBlockBuffer(TByteRange byteRange, TString buffer);
IBlockBufferPtr CreateLazyBlockBuffer(TByteRange byteRange);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void ApplyFreshDataRange(
targetBuffer);

// NB: we assume that underlying target data is a continuous buffer
// TODO: don't make such an assumption - use GetBlock(i) API
memcpy(
targetData,
sourceFreshData.GetContent().data() +
Expand Down
5 changes: 3 additions & 2 deletions cloud/filestore/libs/storage/service/service_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1546,8 +1546,9 @@ Y_UNIT_TEST_SUITE(TStorageServiceTest)
service.ReadData(headers, fs, nodeId, handle, 0, data.Size());
UNIT_ASSERT_VALUES_EQUAL(readDataResult->Record.GetBuffer(), data);

// fresh blocks
data = TString(4_KB, 'a');
// fresh blocks - adding multiple adjacent blocks is important here to
// catch some subtle bugs
data = TString(8_KB, 'a');
service.WriteData(headers, fs, nodeId, handle, 0, data);
readDataResult =
service.ReadData(headers, fs, nodeId, handle, 0, data.Size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,7 @@ void TIndexTabletActor::HandleDescribeData(
requestInfo->StartedTs = ctx.Now();

TByteRange alignedByteRange = byteRange.AlignedSuperRange();
// TODO: implement a block buffer with lazy block allocation and use it
// here
auto blockBuffer = CreateBlockBuffer(alignedByteRange);
auto blockBuffer = CreateLazyBlockBuffer(alignedByteRange);

ExecuteTx<TReadData>(
ctx,
Expand Down

0 comments on commit 6f7d720

Please sign in to comment.