Skip to content

Commit 7bee990

Browse files
committed
[fix][ml] Return 1 when bytes size is 0 or negative for entry count estimation (#24131)
(cherry picked from commit 82d3902)
1 parent 5b1a643 commit 7bee990

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ static int internalEstimateEntryCountByBytesSize(int maxEntries, long maxSizeByt
7272
Long lastLedgerId, long lastLedgerTotalEntries,
7373
long lastLedgerTotalSize) {
7474
if (maxSizeBytes <= 0) {
75-
// If the specified maximum size is invalid (e.g., non-positive), return 0
76-
return 0;
75+
// If the specified maximum size is invalid (e.g., non-positive), return 1
76+
return 1;
7777
}
7878

7979
// If the maximum size is Long.MAX_VALUE, return the maximum number of entries

Diff for: managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/EntryCountEstimatorTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ private int estimateEntryCountByBytesSize(long maxSizeBytes) {
8282
@Test
8383
public void testZeroMaxSize() {
8484
int result = estimateEntryCountByBytesSize(0);
85-
assertEquals(result, 0, "Should return 0 when max size is 0");
85+
assertEquals(result, 1, "Should return 1 when max size is 0");
86+
}
87+
88+
@Test
89+
public void testNegativeMaxSize() {
90+
int result = estimateEntryCountByBytesSize(-1);
91+
assertEquals(result, 1, "Should return 1 when max size is negative");
8692
}
8793

8894
@Test

0 commit comments

Comments
 (0)