JimmyWang6 commented on code in PR #20246:
URL: https://github.com/apache/kafka/pull/20246#discussion_r2367213804


##########
core/src/main/java/kafka/server/share/SharePartition.java:
##########
@@ -2311,6 +2316,24 @@ long findLastOffsetAcknowledged() {
         return lastOffsetAcknowledged;
     }
 
+    /**
+     * Find the maximum offset from the first batch within the request offset 
for {@link ShareAcquireMode.STRICT} mode.
+     *
+     * @param batches The batches to search for the request offset.
+     * @param offset The request offset to find.
+     * @return The minimum value between the first batch's last offset and the 
request offset.
+     *         If no batches are available, returns the original request 
offset.
+     */
+    private long maxOffsetFromFirstBatch(
+        Iterable<? extends RecordBatch> batches,
+        long offset
+    ) {
+        for (RecordBatch batch : batches) {
+            return Math.min(batch.lastOffset(), offset);
+        }
+        return offset;
+    }

Review Comment:
   I have changed the code structure and polished the comments, and 2 test 
cases are added. As for 2 batches with 3 records each when maxFetchRecords are 
4, only 3 records in first batch will returned. I will add more unit tests if 
this mechanism looks good to you :)



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