chirag-wadhwa5 commented on code in PR #18696: URL: https://github.com/apache/kafka/pull/18696#discussion_r1936060418
########## core/src/main/java/kafka/server/share/SharePartition.java: ########## @@ -2160,6 +2234,43 @@ private long startOffsetDuringInitialization(long partitionDataStartOffset) thro } } + // Visible for testing + long findLastOffsetAcknowledged() { + lock.readLock().lock(); + long lastOffsetAcknowledged = -1; + try { + for (NavigableMap.Entry<Long, InFlightBatch> entry : cachedState.entrySet()) { + InFlightBatch inFlightBatch = entry.getValue(); + if (inFlightBatch.offsetState() == null) { + if (!isRecordStateAcknowledged(inFlightBatch.batchState())) { + return lastOffsetAcknowledged; + } + // If initialReadGapOffset.gapStartOffset is less than or equal to the last offset of the batch + // then we cannot identify the current inFlightBatch as acknowledged. All the offsets between + // initialReadGapOffset.gapStartOffset and initialReadGapOffset.endOffset should always be present + // in the cachedState + if (initialReadGapOffset != null && inFlightBatch.lastOffset() >= initialReadGapOffset.gapStartOffset()) { + return lastOffsetAcknowledged; + } Review Comment: Let's say the startOffset is 10 and the stateBatches are as follows in the cachedState -> 1) (10, 20) -> offset tracking is disabled, i.e. batch is not broken, state = acknowledged, 2) (21, 30) -> offset tracking is enabled, i,e. batch is broken. state for 21 to 25 is acknowledged, state for 26 to 30 is acquired In this situation, if findLastOffsetAcknowledged is called, then the ideal result should be 25, because the batch 21 to 30 is broken, so we can move the startOffset to any offset in this batch. But, if we have the `if(isInitialReadGapOffsetWindowActive() && inFlightBatch.lastOffset() >= initialReadGapOffset.gapStartOffset())` check before the if/else block, right inside the for loop, then we will not even reach the else block which does the offset tracking for broker batches, and we will return 20 -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org