Implementation:Apache Flink SplitsRemoval
| Knowledge Sources | |
|---|---|
| Domains | Connectors, Table_API |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
A concrete split change event representing the removal of splits from a split reader.
Description
SplitsRemoval is a concrete subclass of SplitsChange in the flink-connector-base module that represents the event of removing source splits from a SplitReader. It is a generic class parameterized by SplitT, wrapping a list of splits that should be removed from the reader. Unlike SplitsAddition, this class is annotated with @Internal, indicating it is not part of the public API and is intended for Flink's internal use only.
This class is specifically used when a RecordEvaluator reports the end of the stream, triggering the removal of splits. The Javadoc explicitly warns that the SplitsRemoval change between the enumerator and the reader may cause data loss, referencing an Apache mailing list discussion on this topic. The class provides a toString() method for debugging.
Usage
This class is primarily used internally by Flink's source framework. Connector developers may encounter it when implementing SplitReader.handleSplitsChanges(), where they need to handle split removal by cleaning up resources associated with the removed splits and reporting them as finished splits in RecordsWithSplitIds so that SourceReaderBase can properly clean up.
Code Reference
Source Location
- Repository: Apache_Flink
- File: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/splitreader/SplitsRemoval.java
- Lines: 1-48
Signature
@Internal
public class SplitsRemoval<SplitT> extends SplitsChange<SplitT>
Import
import org.apache.flink.connector.base.source.reader.splitreader.SplitsRemoval;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| splits | List<SplitT> | Yes | The list of splits to remove from the reader. Passed via the constructor. |
Outputs
| Name | Type | Description |
|---|---|---|
| splits() | List<SplitT> | Returns an unmodifiable list of the splits to be removed (inherited from SplitsChange). |
| toString() | String | Returns a formatted string representation: "SplitsRemoval:[<splits>]". |
Usage Examples
// Creating a SplitsRemoval event (typically done internally by Flink)
List<MySourceSplit> splitsToRemove = Arrays.asList(
new MySourceSplit("split-1", 100),
new MySourceSplit("split-2", 200)
);
SplitsRemoval<MySourceSplit> removal = new SplitsRemoval<>(splitsToRemove);
// Handling split removal inside a SplitReader implementation
@Override
public void handleSplitsChanges(SplitsChange<MySourceSplit> splitsChanges) {
if (splitsChanges instanceof SplitsAddition) {
assignedSplits.addAll(splitsChanges.splits());
} else if (splitsChanges instanceof SplitsRemoval) {
// Remove the splits and report them as finished so SourceReaderBase
// can clean up resources
Set<String> removedSplitIds = splitsChanges.splits().stream()
.map(MySourceSplit::splitId)
.collect(Collectors.toSet());
assignedSplits.removeIf(s -> removedSplitIds.contains(s.splitId()));
finishedSplitIds.addAll(removedSplitIds);
}
}
Related Pages
- Principle:Apache_Flink_Source_Connector_Framework
- Apache_Flink_SplitsChange - Parent abstract class
- Apache_Flink_SplitReader - Interface that consumes SplitsRemoval events
- Apache_Flink_SplitsAddition - Counterpart class for split addition