Search in sources :

Example 1 with KafkaPartitionSplitReader

use of org.apache.flink.connector.kafka.source.reader.KafkaPartitionSplitReader in project flink by apache.

the class KafkaSourceFetcherManager method enqueueOffsetsCommitTask.

private void enqueueOffsetsCommitTask(SplitFetcher<ConsumerRecord<byte[], byte[]>, KafkaPartitionSplit> splitFetcher, Map<TopicPartition, OffsetAndMetadata> offsetsToCommit, OffsetCommitCallback callback) {
    KafkaPartitionSplitReader kafkaReader = (KafkaPartitionSplitReader) splitFetcher.getSplitReader();
    splitFetcher.enqueueTask(new SplitFetcherTask() {

        @Override
        public boolean run() throws IOException {
            kafkaReader.notifyCheckpointComplete(offsetsToCommit, callback);
            return true;
        }

        @Override
        public void wakeUp() {
        }
    });
}
Also used : IOException(java.io.IOException) SplitFetcherTask(org.apache.flink.connector.base.source.reader.fetcher.SplitFetcherTask) KafkaPartitionSplitReader(org.apache.flink.connector.kafka.source.reader.KafkaPartitionSplitReader)

Example 2 with KafkaPartitionSplitReader

use of org.apache.flink.connector.kafka.source.reader.KafkaPartitionSplitReader in project flink by apache.

the class KafkaSource method createReader.

@VisibleForTesting
SourceReader<OUT, KafkaPartitionSplit> createReader(SourceReaderContext readerContext, Consumer<Collection<String>> splitFinishedHook) throws Exception {
    FutureCompletingBlockingQueue<RecordsWithSplitIds<ConsumerRecord<byte[], byte[]>>> elementsQueue = new FutureCompletingBlockingQueue<>();
    deserializationSchema.open(new DeserializationSchema.InitializationContext() {

        @Override
        public MetricGroup getMetricGroup() {
            return readerContext.metricGroup().addGroup("deserializer");
        }

        @Override
        public UserCodeClassLoader getUserCodeClassLoader() {
            return readerContext.getUserCodeClassLoader();
        }
    });
    final KafkaSourceReaderMetrics kafkaSourceReaderMetrics = new KafkaSourceReaderMetrics(readerContext.metricGroup());
    Supplier<KafkaPartitionSplitReader> splitReaderSupplier = () -> new KafkaPartitionSplitReader(props, readerContext, kafkaSourceReaderMetrics);
    KafkaRecordEmitter<OUT> recordEmitter = new KafkaRecordEmitter<>(deserializationSchema);
    return new KafkaSourceReader<>(elementsQueue, new KafkaSourceFetcherManager(elementsQueue, splitReaderSupplier::get, splitFinishedHook), recordEmitter, toConfiguration(props), readerContext, kafkaSourceReaderMetrics);
}
Also used : KafkaSourceFetcherManager(org.apache.flink.connector.kafka.source.reader.fetcher.KafkaSourceFetcherManager) MetricGroup(org.apache.flink.metrics.MetricGroup) KafkaSourceReaderMetrics(org.apache.flink.connector.kafka.source.metrics.KafkaSourceReaderMetrics) KafkaSourceReader(org.apache.flink.connector.kafka.source.reader.KafkaSourceReader) RecordsWithSplitIds(org.apache.flink.connector.base.source.reader.RecordsWithSplitIds) KafkaRecordDeserializationSchema(org.apache.flink.connector.kafka.source.reader.deserializer.KafkaRecordDeserializationSchema) DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema) UserCodeClassLoader(org.apache.flink.util.UserCodeClassLoader) FutureCompletingBlockingQueue(org.apache.flink.connector.base.source.reader.synchronization.FutureCompletingBlockingQueue) KafkaRecordEmitter(org.apache.flink.connector.kafka.source.reader.KafkaRecordEmitter) KafkaPartitionSplitReader(org.apache.flink.connector.kafka.source.reader.KafkaPartitionSplitReader) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Aggregations

KafkaPartitionSplitReader (org.apache.flink.connector.kafka.source.reader.KafkaPartitionSplitReader)2 IOException (java.io.IOException)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 DeserializationSchema (org.apache.flink.api.common.serialization.DeserializationSchema)1 RecordsWithSplitIds (org.apache.flink.connector.base.source.reader.RecordsWithSplitIds)1 SplitFetcherTask (org.apache.flink.connector.base.source.reader.fetcher.SplitFetcherTask)1 FutureCompletingBlockingQueue (org.apache.flink.connector.base.source.reader.synchronization.FutureCompletingBlockingQueue)1 KafkaSourceReaderMetrics (org.apache.flink.connector.kafka.source.metrics.KafkaSourceReaderMetrics)1 KafkaRecordEmitter (org.apache.flink.connector.kafka.source.reader.KafkaRecordEmitter)1 KafkaSourceReader (org.apache.flink.connector.kafka.source.reader.KafkaSourceReader)1 KafkaRecordDeserializationSchema (org.apache.flink.connector.kafka.source.reader.deserializer.KafkaRecordDeserializationSchema)1 KafkaSourceFetcherManager (org.apache.flink.connector.kafka.source.reader.fetcher.KafkaSourceFetcherManager)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 UserCodeClassLoader (org.apache.flink.util.UserCodeClassLoader)1