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
   #### Actual behavior
   #### 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: 
   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 
           if (lastMessageIdInBroker.compareTo(lastDequeuedMessage) > 0 &&
               ((MessageIdImpl)lastMessageIdInBroker).getEntryId() != -1) {
           } else {
               getLastMessageIdAsync().thenAccept(messageId -> {
                   lastMessageIdInBroker = messageId;
                   if (lastMessageIdInBroker.compareTo(lastDequeuedMessage) > 0 
                       ((MessageIdImpl)lastMessageIdInBroker).getEntryId() != 
-1) {
                   } else {
               }).exceptionally(e -> {
                   log.error("[{}][{}] Failed getLastMessageId command", topic, 
                   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:

With regards,
Apache Git Services

Reply via email to