Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Status

Current stateUnder Discussion

...

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Table of Contents

Motivation

There exists use-case where the users want to stop a Flink job gracefully based on the content of de-serialized records observed in the sourceKafkaSource. For example, users might want to use a Flink job to process stock transaction data from an unbounded Kafka topic in topic in real time. Suppose the stock market closes at 4 pm, users would want the Flink job to stop once the job has processed all the transaction data of that day. 

...

This FLIP aims to address this use-case so that users who currently depend on KafkaDeserializationSchema::isEndOfStream() can migrate their Flink job from FlinkKafkaConsumer to KafkaSource.

Public Interfaces

1) Adds the EofOnRecordEvaluator interface to the package org.apache.flink.connector.base.source.reader.

...

Code Block
languagejava
public class KafkaSourceBuilder<OUT> {
    ... // Skip the existing methods

    /**
     * Sets the optional {@link EofOnRecordEvaluator eofOnRecordEvaluator} for KafkaSource.
     *
     * <p>When the evaluator is specified, it is invoked for each de-serialized record to determine
     * whether to stop consuming from the current split based. If a record is matched by the
     * evaluator, the source would not emit this record as well as the following records in the same
     * split.
     *
     * <p>Note that the evaluator works jointly with the stopping offsets specified by the {@link
     * #setBounded(OffsetsInitializer)} or the {@link #setUnbounded(OffsetsInitializer)}. The source
     * stops consuming from a split when any of these conditions is met.
     *
     * @param eofOnRecordEvaluator a {@link EofOnRecordEvaluator eofOnRecordEvaluator}
     * @return this KafkaSourceBuilder.
     */
    public KafkaSourceBuilder<OUT> setEofOnRecordEvaluator(
            EofOnRecordEvaluator<OUT> eofOnRecordEvaluator) {
        this.eofOnRecordEvaluator = eofOnRecordEvaluator;
        return this;
    }
} 


Proposed Changes

We expect user to specify the EOF-detection logic in an EofOnRecordEvaluator instance and pass this instance to KafkaSourceBuilder::setEofOnRecordEvaluator. Then KafkaSource would enforce the EOF-detection logic in the following way:

...

3) When every a record is matched by EofOnRecordEvaluator, SourceReaderBase stops emitting records from this split and informs SplitFetcherManager to stop fetching from this split.

Compatibility, Deprecation, and Migration Plan

The APIs added in this FLIP is backward compatible with the existing KafkaSource.

...

Users who currently uses FlinkKafkaConsumer together with KafkaDeserializationSchema::isEndOfStream(...) can migrate to KafkaSource by moving the isEndOfStream(...) logic into the EofOnRecordEvaluator added in this FLIP.

Test Plan

We will provide unit tests to validate the proposed changes.

Rejected Alternatives

1) Merge EofOnRecordEvaluator and stoppingOffsetsInitializer (currently provided via KafkaSourceBuilder's setBounded() or setUnbounded()) into one class.

...