JimmyWang6 commented on code in PR #20246:
URL: https://github.com/apache/kafka/pull/20246#discussion_r2461423297
##########
core/src/main/java/kafka/server/share/SharePartition.java:
##########
@@ -846,27 +861,45 @@ public ShareAcquiredRecords acquire(
inFlightBatch, groupId, topicIdPartition);
continue;
}
- // Schedule acquisition lock timeout for the batch.
- AcquisitionLockTimerTask acquisitionLockTimeoutTask =
scheduleAcquisitionLockTimeout(memberId, inFlightBatch.firstOffset(),
inFlightBatch.lastOffset());
- // Set the acquisition lock timeout task for the batch.
-
inFlightBatch.updateAcquisitionLockTimeout(acquisitionLockTimeoutTask);
+ long recordsAcquired = inFlightBatch.lastOffset() -
inFlightBatch.firstOffset() + 1;
+ if (isRecordLimitMode && recordsAcquired >
maxRecordsToAcquire) {
+ AcquiredRecords records =
filterShareAcquiredRecordsInRecordLimitMode((int) (maxRecordsToAcquire -
recordsAcquired),
+ List.of(new AcquiredRecords()
+ .setFirstOffset(inFlightBatch.firstOffset())
+ .setLastOffset(inFlightBatch.lastOffset())
+ .setDeliveryCount((short)
inFlightBatch.batchDeliveryCount())));
+ result.add(records);
+ acquiredCount += maxRecordsToAcquire;
+ break;
+ } else {
+ // Schedule acquisition lock timeout for the batch.
+ AcquisitionLockTimerTask acquisitionLockTimeoutTask =
scheduleAcquisitionLockTimeout(memberId, inFlightBatch.firstOffset(),
inFlightBatch.lastOffset());
+ // Set the acquisition lock timeout task for the batch.
+
inFlightBatch.updateAcquisitionLockTimeout(acquisitionLockTimeoutTask);
- result.add(new AcquiredRecords()
- .setFirstOffset(inFlightBatch.firstOffset())
- .setLastOffset(inFlightBatch.lastOffset())
- .setDeliveryCount((short)
inFlightBatch.batchDeliveryCount()));
- acquiredCount += (int) (inFlightBatch.lastOffset() -
inFlightBatch.firstOffset() + 1);
+ result.add(new AcquiredRecords()
+ .setFirstOffset(inFlightBatch.firstOffset())
+ .setLastOffset(inFlightBatch.lastOffset())
+ .setDeliveryCount((short)
inFlightBatch.batchDeliveryCount()));
+ acquiredCount += (int) recordsAcquired;
+ }
}
// Some of the request offsets are not found in the fetched
batches. Acquire the
// missing records as well.
if (acquiredCount < maxRecordsToAcquire &&
subMap.lastEntry().getValue().lastOffset() < lastOffsetToAcquire) {
log.trace("There exists another batch which needs to be
acquired as well");
- ShareAcquiredRecords shareAcquiredRecords =
acquireNewBatchRecords(memberId, fetchPartitionData.records.batches(),
+ int numRecordsRemaining = maxRecordsToAcquire - acquiredCount;
Review Comment:
Yes, I think the
`testAcquireMultipleRecordsWithOverlapAndNewBatchInRecordLimitMode` and
`estAcquireCachedStateInitialGapOverlapsWithActualPartitionGapInRecordLimitMode`
tests could cover this case.
--
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]