Class SourceReaderBase<E,T,SplitT extends org.apache.flink.api.connector.source.SourceSplit,SplitStateT>
- java.lang.Object
-
- org.apache.flink.connector.base.source.reader.SourceReaderBase<E,T,SplitT,SplitStateT>
-
- Type Parameters:
E- The rich element type that contains information for split state update or timestamp extraction.T- The final element type to emit.SplitT- the immutable split type.SplitStateT- the mutable type of split state.
- All Implemented Interfaces:
AutoCloseable,org.apache.flink.api.common.state.CheckpointListener,org.apache.flink.api.connector.source.SourceReader<T,SplitT>
- Direct Known Subclasses:
SingleThreadMultiplexSourceReaderBase
@PublicEvolving public abstract class SourceReaderBase<E,T,SplitT extends org.apache.flink.api.connector.source.SourceSplit,SplitStateT> extends Object implements org.apache.flink.api.connector.source.SourceReader<T,SplitT>
An abstract implementation ofSourceReaderwhich provides some synchronization between the mail box main thread and the SourceReader internal threads. This class allows user to just provide aSplitReaderand snapshot the split state.This implementation provides the following metrics out of the box:
OperatorIOMetricGroup.getNumRecordsInCounter()
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.flink.configuration.ConfigurationconfigThe raw configurations that may be used by subclasses.protected org.apache.flink.api.connector.source.SourceReaderContextcontextThe context of this source reader.protected RecordEvaluator<T>eofRecordEvaluatorprotected SourceReaderOptionsoptionsThe configuration for the reader.protected RecordEmitter<E,T,SplitStateT>recordEmitterThe record emitter to handle the records read by the SplitReaders.protected SplitFetcherManager<E,SplitT>splitFetcherManagerThe split fetcher manager to run split fetchers.
-
Constructor Summary
Constructors Constructor Description SourceReaderBase(SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)The primary constructor for the source reader.SourceReaderBase(SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, RecordEvaluator<T> eofRecordEvaluator, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)SourceReaderBase(FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> elementsQueue, SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)Deprecated.SourceReaderBase(FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> elementsQueue, SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, RecordEvaluator<T> eofRecordEvaluator, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)Deprecated.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddSplits(List<SplitT> splits)voidclose()intgetNumberOfCurrentlyAssignedSplits()Gets the number of splits the reads has currently assigned.voidhandleSourceEvents(org.apache.flink.api.connector.source.SourceEvent sourceEvent)protected abstract SplitStateTinitializedState(SplitT split)When new splits are added to the reader.CompletableFuture<Void>isAvailable()voidnotifyNoMoreSplits()protected abstract voidonSplitFinished(Map<String,SplitStateT> finishedSplitIds)Handles the finished splits to clean the state if needed.voidpauseOrResumeSplits(Collection<String> splitsToPause, Collection<String> splitsToResume)org.apache.flink.core.io.InputStatuspollNext(org.apache.flink.api.connector.source.ReaderOutput<T> output)List<SplitT>snapshotState(long checkpointId)voidstart()protected abstract SplitTtoSplitType(String splitId, SplitStateT splitState)Convert a mutable SplitStateT to immutable SplitT.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Field Detail
-
recordEmitter
protected final RecordEmitter<E,T,SplitStateT> recordEmitter
The record emitter to handle the records read by the SplitReaders.
-
splitFetcherManager
protected final SplitFetcherManager<E,SplitT extends org.apache.flink.api.connector.source.SourceSplit> splitFetcherManager
The split fetcher manager to run split fetchers.
-
options
protected final SourceReaderOptions options
The configuration for the reader.
-
config
protected final org.apache.flink.configuration.Configuration config
The raw configurations that may be used by subclasses.
-
context
protected org.apache.flink.api.connector.source.SourceReaderContext context
The context of this source reader.
-
eofRecordEvaluator
@Nullable protected final RecordEvaluator<T> eofRecordEvaluator
-
-
Constructor Detail
-
SourceReaderBase
@Deprecated public SourceReaderBase(FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> elementsQueue, SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)
Deprecated.
-
SourceReaderBase
@Deprecated public SourceReaderBase(FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> elementsQueue, SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, @Nullable RecordEvaluator<T> eofRecordEvaluator, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)
Deprecated.
-
SourceReaderBase
public SourceReaderBase(SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)
The primary constructor for the source reader.The reader will use a handover queue sized as configured via
SourceReaderOptions.ELEMENT_QUEUE_CAPACITY.
-
SourceReaderBase
public SourceReaderBase(SplitFetcherManager<E,SplitT> splitFetcherManager, RecordEmitter<E,T,SplitStateT> recordEmitter, @Nullable RecordEvaluator<T> eofRecordEvaluator, org.apache.flink.configuration.Configuration config, org.apache.flink.api.connector.source.SourceReaderContext context)
-
-
Method Detail
-
start
public void start()
-
pollNext
public org.apache.flink.core.io.InputStatus pollNext(org.apache.flink.api.connector.source.ReaderOutput<T> output) throws Exception
-
isAvailable
public CompletableFuture<Void> isAvailable()
-
notifyNoMoreSplits
public void notifyNoMoreSplits()
-
handleSourceEvents
public void handleSourceEvents(org.apache.flink.api.connector.source.SourceEvent sourceEvent)
-
pauseOrResumeSplits
public void pauseOrResumeSplits(Collection<String> splitsToPause, Collection<String> splitsToResume)
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
getNumberOfCurrentlyAssignedSplits
public int getNumberOfCurrentlyAssignedSplits()
Gets the number of splits the reads has currently assigned.These are the splits that have been added via
addSplits(List)and have not yet been finished by returning them from theSplitReader.fetch()as part ofRecordsWithSplitIds.finishedSplits().
-
onSplitFinished
protected abstract void onSplitFinished(Map<String,SplitStateT> finishedSplitIds)
Handles the finished splits to clean the state if needed.
-
initializedState
protected abstract SplitStateT initializedState(SplitT split)
When new splits are added to the reader. The initialize the state of the new splits.- Parameters:
split- a newly added split.
-
toSplitType
protected abstract SplitT toSplitType(String splitId, SplitStateT splitState)
Convert a mutable SplitStateT to immutable SplitT.- Parameters:
splitState- splitState.- Returns:
- an immutable Split state.
-
-