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

Fix of the error of incorrect metering exceeding the reserved topic size #5001

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all 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
11 changes: 7 additions & 4 deletions ydb/core/persqueue/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,10 @@ ui64 TPartition::MeteringDataSize(const TActorContext& /*ctx*/) const {
// We assume that DataKyesBody contains an up-to-date set of blobs, their relevance is
// maintained by the background process. However, the last block may contain several irrelevant
// messages. Because of them, we throw out the size of the entire blob.
ui64 size = Size() - DataKeysBody[0].Size;
Y_DEBUG_ABORT_UNLESS(size >= 0, "Metering data size must be positive");
return std::max<ui64>(size, 0);
auto size = Size();
auto lastBlobSize = DataKeysBody[0].Size;
Y_DEBUG_ABORT_UNLESS(size >= lastBlobSize, "Metering data size must be positive");
return size >= lastBlobSize ? size - lastBlobSize : 0;
}

ui64 TPartition::ReserveSize() const {
Expand All @@ -308,7 +309,9 @@ ui64 TPartition::GetUsedStorage(const TActorContext& ctx) {
const auto duration = now - LastUsedStorageMeterTimestamp;
LastUsedStorageMeterTimestamp = now;

ui64 size = std::max<ui64>(MeteringDataSize(ctx) - ReserveSize(), 0);
auto dataSize = MeteringDataSize(ctx);
auto reservedSize = ReserveSize();
ui64 size = dataSize > reservedSize ? dataSize - reservedSize : 0;
return size * duration.MilliSeconds() / 1000 / 1_MB; // mb*seconds
}

Expand Down
Loading