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


##########
core/src/main/java/kafka/server/share/SharePartition.java:
##########
@@ -1596,9 +1628,45 @@ private ShareAcquiredRecords acquireNewBatchRecords(
         }
     }
 
+    private AcquiredRecords filterShareAcquiredRecordsInRecordLimitMode(int 
maxFetchRecords, List<AcquiredRecords> acquiredRecords) {
+        // Only acquire one single batch in record limit mode.
+        AcquiredRecords records = acquiredRecords.get(0);
+        InFlightBatch inFlightBatch = cachedState.get(records.firstOffset());
+        long lastOffset = records.firstOffset() + maxFetchRecords - 1;
+        if (inFlightBatch != null) {
+            // Initialize the offset state map if not already initialized.
+            inFlightBatch.maybeInitializeOffsetStateUpdate();
+            List<PersisterBatch> persisterBatches = new ArrayList<>();
+            CompletableFuture<Void> future = new CompletableFuture<>();
+            NavigableMap<Long, InFlightState> offsetStateMap = 
inFlightBatch.offsetState();
+            for (Map.Entry<Long, InFlightState> offsetState : 
offsetStateMap.tailMap(lastOffset, false).entrySet()) {
+                if (offsetState.getValue().state() == RecordState.ACQUIRED) {

Review Comment:
   1. Done.
   2. I don't think we need to adjust it. The `endOffset` should remain aligned 
with the batch's boundary and avoid moving backward since it's already set to 
`lastAcquiredOffset` in `acquireNewBatchRecords`. However, I'm happy to 
reconsider if you have a different perspective.



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