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


##########
core/src/main/java/kafka/server/share/SharePartition.java:
##########
@@ -1614,9 +1649,50 @@ 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());
+        if (inFlightBatch != null) {
+            long lastOffset = records.firstOffset() + maxFetchRecords - 1;
+            // 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) {
+                    // These records were not actually acquired so update the 
offset status back to available.
+                    InFlightState updateResult = 
offsetState.getValue().startStateTransition(
+                        RecordState.AVAILABLE,
+                        DeliveryCountOps.DECREASE,
+                        this.maxDeliveryCount,
+                        EMPTY_MEMBER_ID
+                    );
+                    if (updateResult == null) {
+                        log.error("Unable to update records status for the 
offset: {} in batch: {} for the share partition: {}-{}", offsetState.getKey(), 
inFlightBatch,
+                            groupId, topicIdPartition);
+                        continue;
+                    }
+                    persisterBatches.add(new PersisterBatch(updateResult, new 
PersisterStateBatch(offsetState.getKey(),
+                        offsetState.getKey(), updateResult.state().id(), 
(short) updateResult.deliveryCount())));
+                } else {
+                    log.error("Unexpected record state {} for offset: {} in 
batch: {} in share partition: {}-{}",
+                        offsetState.getValue().state(), offsetState.getKey(), 
inFlightBatch, groupId, topicIdPartition);
+                }
+            }
+            rollbackOrProcessStateUpdates(future, null, persisterBatches);

Review Comment:
   Hmm, when we convert any record's state from `AVAILABLE` to `ACQUIRED`, we 
do not persist it. So why do we need to send this info to persister when we are 
converting the records back from `ACQUIRED` to `AVAILABLE`? I think we should 
only convert the record's state from `ACQUIRED` to `AVAILABLE` without any 
rollback?



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