dalelane commented on code in PR #293:
URL: 
https://github.com/apache/flink-connector-kafka/pull/293#discussion_r3883665982


##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/source/reader/KafkaPartitionSplitReader.java:
##########
@@ -298,6 +307,58 @@ long getConsumerPosition(TopicPartition tp, String msg) {
         return retryOnWakeup(() -> consumer.position(tp), msg);
     }
 
+    private void trackLastFetchedRecordOffsets(ConsumerRecords<byte[], byte[]> 
consumerRecords) {
+        for (TopicPartition tp : consumerRecords.partitions()) {
+            List<ConsumerRecord<byte[], byte[]>> partitionRecords = 
consumerRecords.records(tp);
+            if (!partitionRecords.isEmpty()) {
+                lastFetchedOffsets.put(
+                        tp, partitionRecords.get(partitionRecords.size() - 
1).offset());
+            }
+        }
+    }
+
+    /**
+     * Advances the offsets to commit over the entries that the Kafka consumer 
read but never
+     * delivered, such as transaction control markers and records of aborted 
transactions.
+     *
+     * <p>{@link KafkaRecordEmitter} derives the offset to commit from the 
records it receives, so
+     * the offset stops at the first entry that Kafka does not deliver, for as 
long as the partition
+     * is idle. The consumer's own position accounts for those entries, so it 
is the offset that
+     * external tooling expects to see.
+     *
+     * <p>This relies on {@link #lastKnownPositions}, populated as a side 
effect of the regular
+     * {@link #fetch()} poll loop, rather than querying the consumer for the 
position again here.
+     * {@link #notifyCheckpointComplete} runs on this same split fetcher 
thread, but at a point
+     * outside that poll loop, so this allows us to avoid a separate blocking 
call to the consumer.
+     */
+    private Map<TopicPartition, OffsetAndMetadata> reconcileOffsetsToCommit(
+            Map<TopicPartition, OffsetAndMetadata> offsetsToCommit) {
+        Map<TopicPartition, OffsetAndMetadata> reconciled = new 
HashMap<>(offsetsToCommit);
+        Set<TopicPartition> assignment = consumer.assignment();
+        offsetsToCommit.forEach(
+                (tp, offsetAndMetadata) -> {
+                    if (!assignment.contains(tp) || 
stoppingOffsets.containsKey(tp)) {

Review Comment:
   I think we need it to protect against the offset going backwards, but you've 
got me doubting myself now :) 
   
   I'll see if I can come up with a test scenario that properly depends on the 
check



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