Class SplitFetcherManager<E,SplitT extends SourceSplit>
- java.lang.Object
-
- org.apache.flink.connector.base.source.reader.fetcher.SplitFetcherManager<E,SplitT>
-
- Direct Known Subclasses:
SingleThreadFetcherManager
@PublicEvolving public abstract class SplitFetcherManager<E,SplitT extends SourceSplit> extends Object
A class responsible for starting theSplitFetcher
and manage the life cycles of them. This class works with theSourceReaderBase
.The split fetcher manager could be used to support different threading models by implementing the
addSplits(List)
method differently. For example, a single thread split fetcher manager would only start a single fetcher and assign all the splits to it. A one-thread-per-split fetcher may spawn a new thread every time a new split is assigned.
-
-
Constructor Summary
Constructors Constructor Description SplitFetcherManager(Supplier<SplitReader<E,SplitT>> splitReaderFactory, Configuration configuration)
Create a split fetcher manager.SplitFetcherManager(Supplier<SplitReader<E,SplitT>> splitReaderFactory, Configuration configuration, Consumer<Collection<String>> splitFinishedHook)
Create a split fetcher manager.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addSplits(List<SplitT> splitsToAdd)
void
checkErrors()
void
close(long timeoutMs)
Close the split fetcher manager.protected SplitFetcher<E,SplitT>
createSplitFetcher()
Synchronize method to ensure no fetcher is created after the split fetcher manager has closed.int
getNumAliveFetchers()
FutureCompletingBlockingQueue<RecordsWithSplitIds<E>>
getQueue()
Return the queue contains data produced by split fetchers.This method is Internal and only used inSourceReaderBase
.boolean
maybeShutdownFinishedFetchers()
Check and shutdown the fetchers that have completed their work.void
pauseOrResumeSplits(Collection<String> splitIdsToPause, Collection<String> splitIdsToResume)
abstract void
removeSplits(List<SplitT> splitsToRemove)
protected void
startFetcher(SplitFetcher<E,SplitT> fetcher)
-
-
-
Field Detail
-
fetchers
protected final Map<Integer,SplitFetcher<E,SplitT extends SourceSplit>> fetchers
A map keeping track of all the split fetchers.
-
-
Constructor Detail
-
SplitFetcherManager
public SplitFetcherManager(Supplier<SplitReader<E,SplitT>> splitReaderFactory, Configuration configuration)
Create a split fetcher manager.- Parameters:
splitReaderFactory
- a supplier that could be used to create split readers.configuration
- the configuration of this fetcher manager.
-
SplitFetcherManager
public SplitFetcherManager(Supplier<SplitReader<E,SplitT>> splitReaderFactory, Configuration configuration, Consumer<Collection<String>> splitFinishedHook)
Create a split fetcher manager.- Parameters:
splitReaderFactory
- a supplier that could be used to create split readers.configuration
- the configuration of this fetcher manager.splitFinishedHook
- Hook for handling finished splits in split fetchers.
-
-
Method Detail
-
pauseOrResumeSplits
public void pauseOrResumeSplits(Collection<String> splitIdsToPause, Collection<String> splitIdsToResume)
-
startFetcher
protected void startFetcher(SplitFetcher<E,SplitT> fetcher)
-
createSplitFetcher
protected SplitFetcher<E,SplitT> createSplitFetcher()
Synchronize method to ensure no fetcher is created after the split fetcher manager has closed.- Returns:
- the created split fetcher.
- Throws:
IllegalStateException
- if the split fetcher manager has closed.
-
maybeShutdownFinishedFetchers
public boolean maybeShutdownFinishedFetchers()
Check and shutdown the fetchers that have completed their work.- Returns:
- true if all the fetchers have completed the work, false otherwise.
-
getQueue
@Internal public FutureCompletingBlockingQueue<RecordsWithSplitIds<E>> getQueue()
Return the queue contains data produced by split fetchers.This method is Internal and only used inSourceReaderBase
.
-
close
public void close(long timeoutMs) throws Exception
Close the split fetcher manager.- Parameters:
timeoutMs
- the max time in milliseconds to wait.- Throws:
Exception
- when failed to close the split fetcher manager.
-
checkErrors
public void checkErrors()
-
getNumAliveFetchers
@VisibleForTesting public int getNumAliveFetchers()
-
-