ivankelly opened a new issue #1517: Reader#hasMessageAvailable can report false when it should be true URL: https://github.com/apache/incubator-pulsar/issues/1517 #### Expected behavior true #### Actual behavior false #### Steps to reproduce 1. Write to a topic 2. Restart the broker 2. Create a Reader reading from very start of topic 4. Call hasMessageAvailable, will return false Test case: https://github.com/ivankelly/incubator-pulsar/commit/362ab39eb341e58dede568cc0c7e9321a967adfd This is happening, because managed ledger getLastPosition() uses lastConfirmedEntry, which is set to ```<ledgerId>:-1```, when a new new ledger is created (as happens on restart). When the client gets this, and the client hasn't already received a message, ``` public CompletableFuture<Boolean> hasMessageAvailableAsync() { final CompletableFuture<Boolean> booleanFuture = new CompletableFuture<>(); if (lastMessageIdInBroker.compareTo(lastDequeuedMessage) > 0 && ((MessageIdImpl)lastMessageIdInBroker).getEntryId() != -1) { booleanFuture.complete(true); } else { getLastMessageIdAsync().thenAccept(messageId -> { lastMessageIdInBroker = messageId; if (lastMessageIdInBroker.compareTo(lastDequeuedMessage) > 0 && ((MessageIdImpl)lastMessageIdInBroker).getEntryId() != -1) { booleanFuture.complete(true); } else { booleanFuture.complete(false); } }).exceptionally(e -> { log.error("[{}][{}] Failed getLastMessageId command", topic, subscription); booleanFuture.completeExceptionally(e.getCause()); return null; }); } return booleanFuture; } ``` The method gets ```<ledgerId>:-1``` from the broker, which hits the false clause every time. The solution would be to check in managed ledger if nothing has been written, and if so, find the last entry in the last non-empty ledger. I wanted to check why it wasn't done like this before implementing though. @zhaijack @merlimat @sijie
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services