You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/03/27 13:36:52 UTC

[GitHub] zhaijack commented on issue #1452: reachedEndOfTopic is called twice if a topic has been terminated before subscription

zhaijack commented on issue #1452: reachedEndOfTopic is called twice if a topic has been terminated before subscription
URL: https://github.com/apache/incubator-pulsar/issues/1452#issuecomment-376527587
 
 
   looked into the code. Seems the 2 calling happens like this:
   1st call happened when create consumer in `PersistentSubscription.java`
   ```
      public synchronized void addConsumer(Consumer consumer) throws BrokerServiceException {
           ...
           if (topic.getManagedLedger().isTerminated() && cursor.getNumberOfEntriesInBacklog() == 0) {
               // Immediately notify the consumer that there are no more available messages
               consumer.reachedEndOfTopic();    
                           < ====1,  Here is the first time
           }
          ...
           dispatcher.addConsumer(consumer);   < ==== 2, add into dispatcher
       }
   ```
   
   Since consumer has been added into dispatcher, then second call is in dispatcher readEntriesFailed:
   ```
       public synchronized void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
           ....
           if (exception instanceof NoMoreEntriesToReadException) {
               if (cursor.getNumberOfEntriesInBacklog() == 0) {
                   // Topic has been terminated and there are no more entries to read
                   // Notify the consumer only if all the messages were already acknowledged
                   consumers.forEach(Consumer::reachedEndOfTopic);     
                               < ==== second call
               }
           } 
             ...
   }
   ```
   
   Seems both are valid?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services