Skip to content

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

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

Merged
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 @@ -235,9 +235,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 @@ -257,7 +258,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