Skip to content

Commit

Permalink
[improve][ml] Optimization method getNumberOfEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
hanmz committed Nov 7, 2024
1 parent 576d341 commit 815e3b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ public boolean hasMoreEntries() {

@Override
public long getNumberOfEntries() {
if (readPosition.compareTo(ledger.getLastPosition().getNext()) > 0) {
if (readPosition.compareTo(ledger.getLastPosition()) > 0) {
if (log.isDebugEnabled()) {
log.debug("[{}] [{}] Read position {} is ahead of last position {}. There are no entries to read",
ledger.getName(), name, readPosition, ledger.getLastPosition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ void readFromClosedLedger() throws Exception {
void testNumberOfEntries() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));

ManagedCursor c0 = ledger.openCursor("c0");
assertEquals(c0.getNumberOfEntries(), 0);
assertFalse(c0.hasMoreEntries());

ManagedCursor c1 = ledger.openCursor("c1");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
ManagedCursor c2 = ledger.openCursor("c2");
Expand Down

0 comments on commit 815e3b5

Please sign in to comment.