-
Notifications
You must be signed in to change notification settings - Fork 4.6k
[Flink] Select bounded-source split assignment by estimated size #39874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Abacn
merged 3 commits into
apache:master
from
pkuzmickas:pkuzmickas/flink-source-assignment-by-size
Sep 2, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...am/runners/flink/translation/wrappers/streaming/io/source/FlinkSourceEnumeratorState.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.beam.runners.flink.translation.wrappers.streaming.io.source; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** Checkpoint state shared by the lazy and static source split assignment strategies. */ | ||
| public final class FlinkSourceEnumeratorState<T> implements Serializable { | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private final AssignmentMode assignmentMode; | ||
| private final ArrayList<FlinkSourceSplit<T>> pendingSplits; | ||
|
|
||
| /** Takes ownership of {@code pendingSplits}; the caller must not mutate it afterwards. */ | ||
| FlinkSourceEnumeratorState( | ||
| AssignmentMode assignmentMode, ArrayList<FlinkSourceSplit<T>> pendingSplits) { | ||
| this.assignmentMode = assignmentMode; | ||
| this.pendingSplits = pendingSplits; | ||
| } | ||
|
|
||
| AssignmentMode getAssignmentMode() { | ||
| return assignmentMode; | ||
| } | ||
|
|
||
| List<FlinkSourceSplit<T>> getPendingSplits() { | ||
| return Collections.unmodifiableList(pendingSplits); | ||
| } | ||
|
|
||
| enum AssignmentMode { | ||
| UNDECIDED, | ||
| LAZY, | ||
| STATIC | ||
| } | ||
| } | ||
103 changes: 103 additions & 0 deletions
103
.../flink/translation/wrappers/streaming/io/source/FlinkSourceEnumeratorStateSerializer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.beam.runners.flink.translation.wrappers.streaming.io.source; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
| import org.apache.beam.runners.flink.translation.utils.SerdeUtils; | ||
| import org.apache.beam.runners.flink.translation.wrappers.streaming.io.source.FlinkSourceEnumeratorState.AssignmentMode; | ||
| import org.apache.flink.core.io.SimpleVersionedSerializer; | ||
|
|
||
| /** Serializes source enumerator state and upgrades the map used by earlier runner versions. */ | ||
| final class FlinkSourceEnumeratorStateSerializer<T> | ||
| implements SimpleVersionedSerializer<FlinkSourceEnumeratorState<T>> { | ||
| // Version written by SerdeUtils.getNaiveObjectSerializer, which serialized the | ||
| // Map<Integer, List<FlinkSourceSplit<T>>> state used by earlier runner versions. | ||
| static final int LEGACY_MAP_VERSION = 0; | ||
| static final int VERSION = 1; | ||
|
|
||
| private final AssignmentMode legacyAssignmentMode; | ||
|
|
||
| FlinkSourceEnumeratorStateSerializer(AssignmentMode legacyAssignmentMode) { | ||
| this.legacyAssignmentMode = legacyAssignmentMode; | ||
| } | ||
|
|
||
| @Override | ||
| public int getVersion() { | ||
| return VERSION; | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] serialize(FlinkSourceEnumeratorState<T> state) throws IOException { | ||
| return SerdeUtils.serializeObject(state); | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| public FlinkSourceEnumeratorState<T> deserialize(int version, byte[] serialized) | ||
| throws IOException { | ||
| if (version == VERSION) { | ||
| Object deserialized = SerdeUtils.deserializeObject(serialized); | ||
| if (deserialized instanceof FlinkSourceEnumeratorState) { | ||
| return (FlinkSourceEnumeratorState<T>) deserialized; | ||
| } | ||
| throw new IOException( | ||
| "Expected source enumerator state of type FlinkSourceEnumeratorState for version " | ||
| + version | ||
| + ", but got: " | ||
| + describe(deserialized)); | ||
| } | ||
| if (version == LEGACY_MAP_VERSION) { | ||
| Object deserialized = SerdeUtils.deserializeObject(serialized); | ||
| if (deserialized instanceof Map) { | ||
| return upgradeLegacyState((Map<?, ?>) deserialized); | ||
| } | ||
| throw new IOException( | ||
| "Expected legacy source enumerator state of type Map for version " | ||
| + version | ||
| + ", but got: " | ||
| + describe(deserialized)); | ||
| } | ||
| throw new IOException( | ||
| String.format( | ||
| "Received source enumerator state version %d, but the highest supported version " | ||
| + "is %d.", | ||
| version, VERSION)); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private FlinkSourceEnumeratorState<T> upgradeLegacyState(Map<?, ?> legacyState) | ||
| throws IOException { | ||
| ArrayList<FlinkSourceSplit<T>> pendingSplits = new ArrayList<>(); | ||
| for (Object value : legacyState.values()) { | ||
| List<FlinkSourceSplit<T>> legacySplits = (List<FlinkSourceSplit<T>>) value; | ||
| if (legacySplits == null) { | ||
| throw new IOException("Legacy source enumerator state contains a null split list."); | ||
| } | ||
| pendingSplits.addAll(legacySplits); | ||
| } | ||
| return new FlinkSourceEnumeratorState<>(legacyAssignmentMode, pendingSplits); | ||
| } | ||
|
|
||
| private static String describe(@Nullable Object obj) { | ||
| return obj == null ? "null" : obj.getClass().getName(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is a dedicate FlinkSourceEnumeratorStateSerializer, why still need implements java.io.Serializable? If it's needed it suggests the Serializer isn't effective in some serialization paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FlinkSourceEnumeratorStateSerializerhandles checkpoint-format versioning and upgrades the previous map-based state. For the new version, the checkpoint data (the assignment mode and list of pending splits) still uses the existing Java object serialization, soFlinkSourceEnumeratorStateneeds to implementSerializable, as the previous state did. I avoided adding field-by-field encoding to the new serializer for simplicity. Please let me know if you had another approach in mind.