humkum commented on a change in pull request #4071:
URL: https://github.com/apache/rocketmq/pull/4071#discussion_r839177009



##########
File path: 
store/src/main/java/org/apache/rocketmq/store/queue/BatchConsumeQueue.java
##########
@@ -710,6 +710,10 @@ public long getOffsetInQueueByTime(final long timestamp) {
         try {
             ByteBuffer byteBuffer = sbr.getByteBuffer();
             int left = targetMinOffset.getIndexPos(), right = 
targetMaxOffset.getIndexPos();
+            long maxQueueTimestamp = byteBuffer.getLong(right + 
MSG_STORE_TIME_OFFSET_INDEX);
+            if (timestamp >= maxQueueTimestamp) {
+                return byteBuffer.getLong(right + MSG_BASE_OFFSET_INDEX);
+            }
             int mid = binarySearchRight(byteBuffer, left, right, 
CQ_STORE_UNIT_SIZE, MSG_STORE_TIME_OFFSET_INDEX, timestamp);
             if (mid != -1) {

Review comment:
       Yes. Thanks for your reminder. If there return -1, it will get the min 
offset of this queue because of the logic the first picture shows. What's more, 
it's unnecessary to binary search if the target timestamp is already larger 
than the max timestamp in CQ.




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