You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/11/07 02:20:34 UTC

[GitHub] [rocketmq] caigy commented on a diff in pull request #5456: fix cmd resetOffsetByTime bug with batch messages #5445

caigy commented on code in PR #5456:
URL: https://github.com/apache/rocketmq/pull/5456#discussion_r1014951958


##########
store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java:
##########
@@ -1001,4 +1002,20 @@ public void swapMap(int reserveNum, long forceSwapIntervalMs, long normalSwapInt
     public void cleanSwappedMap(long forceCleanSwapIntervalMs) {
         mappedFileQueue.cleanSwappedMap(forceCleanSwapIntervalMs);
     }
+
+    private int getEarliestOffset(int targetOffset, ByteBuffer byteBuffer, long currentStoreTime) {
+        if (targetOffset == 0) {
+            return targetOffset;
+        }
+        int preOffset = targetOffset - CQ_STORE_UNIT_SIZE;
+        byteBuffer.position(preOffset);
+        long prePhyOffset = byteBuffer.getLong();
+        int preSize = byteBuffer.getInt();
+        long preStoreTime =
+                this.messageStore.getCommitLog().pickupStoreTimestamp(prePhyOffset, preSize);
+        if (currentStoreTime == preStoreTime) {
+            targetOffset = getEarliestOffset(preOffset, byteBuffer, preStoreTime);
+        }

Review Comment:
   If the batch is large, it may cause a deep recursion. Would it be better to turn this recursion into iteration?



-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org