codelipenghui commented on code in PR #20980:
URL: https://github.com/apache/pulsar/pull/20980#discussion_r1293045876


##########
pulsar-broker/src/main/java/org/apache/pulsar/compaction/TwoPhaseCompactor.java:
##########
@@ -122,27 +122,36 @@ private void phaseOneLoop(RawReader reader,
                 () -> FutureUtil.createTimeoutException("Timeout", getClass(), 
"phaseOneLoop(...)"));
 
         future.thenAcceptAsync(m -> {
-            try {
+            try (m) {
                 MessageId id = m.getMessageId();
                 boolean deletedMessage = false;
                 boolean replaceMessage = false;
                 mxBean.addCompactionReadOp(reader.getTopic(), 
m.getHeadersAndPayload().readableBytes());
-                if (RawBatchConverter.isReadableBatch(m)) {
+                MessageMetadata metadata = 
Commands.parseMessageMetadata(m.getHeadersAndPayload());
+                if (RawBatchConverter.isReadableBatch(metadata)) {
                     try {
+                        int numMessagesInBatch = 
metadata.getNumMessagesInBatch();
+                        int deleteCnt = 0;
                         for (ImmutableTriple<MessageId, String, Integer> e : 
extractIdsAndKeysAndSizeFromBatch(m)) {
+                             boolean singleDeletedMessage = false;
+                             boolean singleReplaceMessage = false;

Review Comment:
   It looks like we don't need add above 2 variables to make the code more 
easily to read
   
   ```java
   for (ImmutableTriple<MessageId, String, Integer> e : 
extractIdsAndKeysAndSizeFromBatch(m)) {
       if (e != null) {
           if (e.getRight() > 0) {
               MessageId old = latestForKey.put(e.getMiddle(), e.getLeft());
               if (old != null) {
                   mxBean.addCompactionRemovedEvent(reader.getTopic());
               }
           } else {
               latestForKey.remove(e.getMiddle());
               deleteCnt++;
               mxBean.addCompactionRemovedEvent(reader.getTopic());
           }
       }
   }
   ```



-- 
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