DL1231 commented on code in PR #20837:
URL: https://github.com/apache/kafka/pull/20837#discussion_r2544029799
##########
core/src/main/java/kafka/server/share/SharePartition.java:
##########
@@ -1885,7 +1908,21 @@ private int acquireSubsetBatchRecords(
continue;
}
- InFlightState updateResult =
offsetState.getValue().tryUpdateState(RecordState.ACQUIRED,
DeliveryCountOps.INCREASE,
+ int recordDeliveryCount =
offsetState.getValue().deliveryCount();
+ // On last delivery attempt, submit acquired records,
+ // bad record will be delivered alone next time
+ if (maxDeliveryCount > 2 && recordDeliveryCount ==
maxDeliveryCount - 1 && acquiredCount > 0) {
+ hasBadRecord = true;
+ break;
+ }
Review Comment:
Consider a batch of 500 records (offsets 0-499) with the following state:
<pre>
offset 0 1 2 3
4 5 ...
deliveryCount 2 3 4 1
1 4 ...
state AVAILABLE AVAILABLE AVAILABLE AVAILABLE
AVAILABLE AVAILABLE ...
</pre>
Scenario Walkthrough:
- First Acquisition:
1. Acquires offset 0 and 1 successfully.
2. When it's about to acquire offset 2 (which is a last-attempt record), the
former check (lines 1912-1917)) triggers.
3. It stops and returns the already-acquired records (offsets 0, 1). Offset
2 is not acquired.
- Second Acquisition:
1. It now acquires offset 2.
2. The latter check (lines 1944-1949) triggers immediately because offset 2
is a last-attempt record. It returns, ensuring offset 2 is delivered alone.
**If the former check is removed**:
The first acquisition would become offsets 0-2.
**If the latter check is removed**:
The first acquisition would be offsets 0-1, and the second acquisition would
be offsets 2-4.
--
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]