Skip to content

Commit 82d3902

Browse files
authored
[fix][ml] Return 1 when bytes size is 0 or negative for entry count estimation (#24131)
1 parent d5f126f commit 82d3902

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

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

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

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

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

8995
@Test

0 commit comments

Comments
 (0)