apoorvmittal10 commented on code in PR #17322:
URL: https://github.com/apache/kafka/pull/17322#discussion_r1805427341
##########
core/src/main/java/kafka/server/share/SharePartition.java:
##########
@@ -1058,36 +1084,57 @@ private void
maybeCompleteInitialization(CompletableFuture<Void> future) {
private AcquiredRecords acquireNewBatchRecords(
String memberId,
+ Iterable<? extends RecordBatch> batches,
long firstOffset,
- long lastOffset
+ long lastOffset,
+ int maxFetchRecords
) {
lock.writeLock().lock();
try {
+ // If same batch is fetched and previous batch is removed from the
cache then we need to
+ // update the batch first offset to endOffset, only if enfOffset
is passed the firstOffset.
+ // For an initial start of the share fetch from a topic partition
the endOffset will be initialized
+ // to 0 but firstOffset can be higher than 0.
+ long firstAcquiredOffset = firstOffset;
+ if (cachedState.isEmpty() && endOffset > firstAcquiredOffset) {
+ firstAcquiredOffset = endOffset;
+ }
+
+ // Check how many messages can be acquired from the batch.
+ long lastAcquiredOffset = lastOffset;
+ if (maxFetchRecords < lastAcquiredOffset - firstAcquiredOffset +
1) {
+ // The max messages to acquire is less than the complete
available batches hence
+ // limit the acquired records. The last offset shall be the
batches last offset
+ // which falls under the max messages limit. As the max fetch
records is the soft
+ // limit, the last offset can be higher than the max messages.
+ lastAcquiredOffset =
findLastOffsetFromBatchWithRequestOffset(batches, firstAcquiredOffset +
maxFetchRecords - 1);
Review Comment:
Yeah for compacted it might be not accurate. We have one open issue to
handle and test for compacted topics. Compacted topics complete support might
be 4.1 release.
--
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]