You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2025/03/26 16:22:06 UTC
(pulsar) branch branch-3.3 updated: [fix][ml] Return 1 when bytes size is 0 or negative for entry count estimation (#24131)
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-3.3 by this push:
new 7bee990d4c6 [fix][ml] Return 1 when bytes size is 0 or negative for entry count estimation (#24131)
7bee990d4c6 is described below
commit 7bee990d4c6ca616c6d5341749d2e90f1011ad47
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Wed Mar 26 18:19:01 2025 +0200
[fix][ml] Return 1 when bytes size is 0 or negative for entry count estimation (#24131)
(cherry picked from commit 82d3902120da67107d98d66ea95f8706dc0562be)
---
.../org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java | 4 ++--
.../apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java | 8 +++++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java
index e9fe5999dcd..bb5bfe7c5f4 100644
--- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java
+++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java
@@ -72,8 +72,8 @@ class EntryCountEstimator {
Long lastLedgerId, long lastLedgerTotalEntries,
long lastLedgerTotalSize) {
if (maxSizeBytes <= 0) {
- // If the specified maximum size is invalid (e.g., non-positive), return 0
- return 0;
+ // If the specified maximum size is invalid (e.g., non-positive), return 1
+ return 1;
}
// If the maximum size is Long.MAX_VALUE, return the maximum number of entries
diff --git a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java
index 666ff08c315..e6c77b73596 100644
--- a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java
+++ b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java
@@ -82,7 +82,13 @@ public class EntryCountEstimatorTest {
@Test
public void testZeroMaxSize() {
int result = estimateEntryCountByBytesSize(0);
- assertEquals(result, 0, "Should return 0 when max size is 0");
+ assertEquals(result, 1, "Should return 1 when max size is 0");
+ }
+
+ @Test
+ public void testNegativeMaxSize() {
+ int result = estimateEntryCountByBytesSize(-1);
+ assertEquals(result, 1, "Should return 1 when max size is negative");
}
@Test