315157973 commented on a change in pull request #13533:
URL: https://github.com/apache/pulsar/pull/13533#discussion_r775808367



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactedTopicImpl.java
##########
@@ -311,9 +310,8 @@ private static int comparePositionAndMessageId(PositionImpl 
p, MessageIdData m)
             .compare(p.getEntryId(), m.getEntryId()).result();
     }
 
-    @VisibleForTesting
-    PositionImpl getCompactionHorizon() {
-        return this.compactionHorizon;
+    public synchronized Optional<Position> getCompactionHorizon() {

Review comment:
       Why should we use `synchronized ` ?

##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1729,7 +1729,10 @@ private void getLargestBatchIndexWhenPossible(
         ManagedLedgerImpl ml = (ManagedLedgerImpl) 
persistentTopic.getManagedLedger();
 
         // If it's not pointing to a valid entry, respond messageId of the 
current position.
-        if (lastPosition.getEntryId() == -1) {
+        // If the compaction cursor reach the end of the topic, respond 
messageId from compacted ledger
+        Optional<Position> compactionHorizon = 
persistentTopic.getCompactedTopic().getCompactionHorizon();
+        if (lastPosition.getEntryId() == -1 || (compactionHorizon.isPresent()
+                        && lastPosition.compareTo((PositionImpl) 
compactionHorizon.get()) <= 0)) {

Review comment:
       Should it be `lastPosition.compareTo((PositionImpl) 
compactionHorizon.get()) >= 0` ?
   Does the unit test cover this?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to