Skip to content

Commit 216adeb

Browse files
authored
Fix of the error of incorrect metering exceeding the reserved topic size (#5004)
1 parent 53f75b6 commit 216adeb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ydb/core/persqueue/partition.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ ui64 TPartition::MeteringDataSize(const TActorContext& /*ctx*/) const {
235235
// We assume that DataKyesBody contains an up-to-date set of blobs, their relevance is
236236
// maintained by the background process. However, the last block may contain several irrelevant
237237
// messages. Because of them, we throw out the size of the entire blob.
238-
ui64 size = Size() - DataKeysBody[0].Size;
239-
Y_DEBUG_ABORT_UNLESS(size >= 0, "Metering data size must be positive");
240-
return std::max<ui64>(size, 0);
238+
auto size = Size();
239+
auto lastBlobSize = DataKeysBody[0].Size;
240+
Y_DEBUG_ABORT_UNLESS(size >= lastBlobSize, "Metering data size must be positive");
241+
return size >= lastBlobSize ? size - lastBlobSize : 0;
241242
}
242243

243244
ui64 TPartition::ReserveSize() const {
@@ -257,7 +258,9 @@ ui64 TPartition::GetUsedStorage(const TActorContext& ctx) {
257258
const auto duration = now - LastUsedStorageMeterTimestamp;
258259
LastUsedStorageMeterTimestamp = now;
259260

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

0 commit comments

Comments
 (0)