Skip to content

Commit

Permalink
fix blob size after compression; implement 'identity' compression alg…
Browse files Browse the repository at this point in the history
…orithm (needed to check correctness of the refactoring)
  • Loading branch information
SvartMetal committed Dec 29, 2024
1 parent bd09273 commit b1b5d6c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
35 changes: 31 additions & 4 deletions cloud/filestore/libs/storage/tablet/model/blob_compression.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
#include "blob_compression.h"

#include "binary_reader.h"
#include "binary_writer.h"

namespace NCloud::NFileStore::NStorage {

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

struct TBlobCompressionInfo::TImpl
{
TByteVector Bytes;
ui32 CompressedBlobSize = 0;

TImpl(ui32 compressedBlobSize, IAllocator* alloc)
: Bytes(alloc)
, CompressedBlobSize(compressedBlobSize)
{
TBinaryWriter writer(alloc);
writer.Write<ui32>(CompressedBlobSize);
Bytes = writer.Finish();
}

explicit TImpl(TByteVector bytes)
: Bytes(std::move(bytes))
{}
{
TBinaryReader reader(Bytes);
CompressedBlobSize = reader.Read<ui32>();
}

TCompressedRange CompressedRange(TUncompressedRange range) const
{
Expand All @@ -25,6 +41,12 @@ struct TBlobCompressionInfo::TImpl

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

TBlobCompressionInfo::TBlobCompressionInfo(
ui32 compressedBlobSize,
IAllocator* alloc)
: Impl(new TImpl(compressedBlobSize, alloc))
{}

TBlobCompressionInfo::TBlobCompressionInfo(TByteVector bytes)
: Impl(new TImpl(std::move(bytes)))
{}
Expand All @@ -36,6 +58,12 @@ bool TBlobCompressionInfo::BlobCompressed() const
return !!Impl;
}

ui32 TBlobCompressionInfo::CompressedBlobSize() const
{
Y_ABORT_UNLESS(Impl);
return Impl->CompressedBlobSize;
}

TCompressedRange TBlobCompressionInfo::CompressedRange(
TUncompressedRange range) const
{
Expand All @@ -59,9 +87,8 @@ TBlobCompressionInfo TryCompressBlob(
{
Y_UNUSED(chunkSize);
Y_UNUSED(codec);
Y_UNUSED(content);
Y_UNUSED(alloc);
return {};

return TBlobCompressionInfo(static_cast<ui32>(content->size()), alloc);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions cloud/filestore/libs/storage/tablet/model/blob_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ class TBlobCompressionInfo
public:
TBlobCompressionInfo() = default;

TBlobCompressionInfo(ui32 compressedBlobSize, IAllocator* alloc);

explicit TBlobCompressionInfo(TByteVector bytes);

bool BlobCompressed() const;

ui32 CompressedBlobSize() const;

TCompressedRange CompressedRange(TUncompressedRange range) const;

const TByteVector& GetEncoded() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ void TCompactionActor::WriteBlob(const TActorContext& ctx)
BlobCodec,
&blobContent,
BlobCompressionInfoAllocator);
// TODO: fix blob.BlobId BlobSize
if (blob.BlobCompressionInfo.BlobCompressed()) {
blob.BlobId.SetBlobSize(
blob.BlobCompressionInfo.CompressedBlobSize());
}
}

request->Blobs.emplace_back(blob.BlobId, std::move(blobContent));
Expand Down
5 changes: 5 additions & 0 deletions cloud/storage/core/libs/tablet/model/partial_blob_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class TPartialBlobId
return UniqueId_.BlobSize;
}

void SetBlobSize(ui32 size)
{
UniqueId_.BlobSize = size;
}

ui32 PartId() const
{
return UniqueId_.PartId;
Expand Down

0 comments on commit b1b5d6c

Please sign in to comment.