Interface SplitEnumerator<SplitT extends SourceSplit,CheckpointT>
-
- All Superinterfaces:
AutoCloseable,CheckpointListener
- All Known Implementing Classes:
IteratorSourceEnumerator
@Public public interface SplitEnumerator<SplitT extends SourceSplit,CheckpointT> extends AutoCloseable, CheckpointListener
The interface for a split enumerator responsible for discovering the source splits, and assigning them to theSourceReader.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddReader(int subtaskId)Add a new source reader with the given subtask ID.voidaddSplitsBack(List<SplitT> splits, int subtaskId)Add splits back to the split enumerator.voidclose()Called to close the enumerator, in case it holds on to any resources, like threads or network connections.default voidhandleSourceEvent(int subtaskId, SourceEvent sourceEvent)Handles a custom source event from the source reader.voidhandleSplitRequest(int subtaskId, String requesterHostname)Handles the request for a split.default voidnotifyCheckpointComplete(long checkpointId)We have an empty default implementation here because most source readers do not have to implement the method.CheckpointTsnapshotState(long checkpointId)Creates a snapshot of the state of this split enumerator, to be stored in a checkpoint.voidstart()Start the split enumerator.-
Methods inherited from interface org.apache.flink.api.common.state.CheckpointListener
notifyCheckpointAborted
-
-
-
-
Method Detail
-
start
void start()
Start the split enumerator.The default behavior does nothing.
-
handleSplitRequest
void handleSplitRequest(int subtaskId, @Nullable String requesterHostname)Handles the request for a split. This method is called when the reader with the given subtask id calls theSourceReaderContext.sendSplitRequest()method.- Parameters:
subtaskId- the subtask id of the source reader who sent the source event.requesterHostname- Optional, the hostname where the requesting task is running. This can be used to make split assignments locality-aware.
-
addSplitsBack
void addSplitsBack(List<SplitT> splits, int subtaskId)
Add splits back to the split enumerator. This will only happen when aSourceReaderfails and there are splits assigned to it after the last successful checkpoint.- Parameters:
splits- The splits to add back to the enumerator for reassignment.subtaskId- The id of the subtask to which the returned splits belong.
-
addReader
void addReader(int subtaskId)
Add a new source reader with the given subtask ID.- Parameters:
subtaskId- the subtask ID of the new source reader.
-
snapshotState
CheckpointT snapshotState(long checkpointId) throws Exception
Creates a snapshot of the state of this split enumerator, to be stored in a checkpoint.The snapshot should contain the latest state of the enumerator: It should assume that all operations that happened before the snapshot have successfully completed. For example all splits assigned to readers via
SplitEnumeratorContext.assignSplit(SourceSplit, int)andSplitEnumeratorContext.assignSplits(SplitsAssignment)) don't need to be included in the snapshot anymore.This method takes the ID of the checkpoint for which the state is snapshotted. Most implementations should be able to ignore this parameter, because for the contents of the snapshot, it doesn't matter for which checkpoint it gets created. This parameter can be interesting for source connectors with external systems where those systems are themselves aware of checkpoints; for example in cases where the enumerator notifies that system about a specific checkpoint being triggered.
- Parameters:
checkpointId- The ID of the checkpoint for which the snapshot is created.- Returns:
- an object containing the state of the split enumerator.
- Throws:
Exception- when the snapshot cannot be taken.
-
close
void close() throws IOExceptionCalled to close the enumerator, in case it holds on to any resources, like threads or network connections.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
notifyCheckpointComplete
default void notifyCheckpointComplete(long checkpointId) throws ExceptionWe have an empty default implementation here because most source readers do not have to implement the method.- Specified by:
notifyCheckpointCompletein interfaceCheckpointListener- Parameters:
checkpointId- The ID of the checkpoint that has been completed.- Throws:
Exception- This method can propagate exceptions, which leads to a failure/recovery for the task. Note that this will NOT lead to the checkpoint being revoked.- See Also:
CheckpointListener.notifyCheckpointComplete(long)
-
handleSourceEvent
default void handleSourceEvent(int subtaskId, SourceEvent sourceEvent)Handles a custom source event from the source reader.This method has a default implementation that does nothing, because it is only required to be implemented by some sources, which have a custom event protocol between reader and enumerator. The common events for reader registration and split requests are not dispatched to this method, but rather invoke the
addReader(int)andhandleSplitRequest(int, String)methods.- Parameters:
subtaskId- the subtask id of the source reader who sent the source event.sourceEvent- the source event from the source reader.
-
-