-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[FLINK-12612][coordination] Track stored partition on the TaskExecutor #8687
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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.flink.runtime.taskexecutor.partition; | ||
|
|
||
| import org.apache.flink.api.common.JobID; | ||
| import org.apache.flink.runtime.io.network.partition.ResultPartitionID; | ||
| import org.apache.flink.util.Preconditions; | ||
|
|
||
| import javax.annotation.concurrent.ThreadSafe; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| /** | ||
| * Thread-safe Utility for tracking partitions. | ||
zentol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| @ThreadSafe | ||
| public class PartitionTable { | ||
zentol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private final Map<JobID, Set<ResultPartitionID>> trackedPartitionsPerJob = new ConcurrentHashMap<>(8); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also consider per task
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be done yes. I'd revisit this once everything is in place and we can better gauge what would be the most appropriate mappings. |
||
|
|
||
| /** | ||
| * Returns whether any partitions are being tracked for the given job. | ||
| */ | ||
| public boolean hasTrackedPartitions(JobID jobId) { | ||
zentol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return trackedPartitionsPerJob.containsKey(jobId); | ||
zentol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Starts the tracking of the given partition for the given job. | ||
| */ | ||
| public void startTrackingPartitions(JobID jobId, Collection<ResultPartitionID> newPartitionIds) { | ||
| Preconditions.checkNotNull(jobId); | ||
| Preconditions.checkNotNull(newPartitionIds); | ||
|
|
||
| trackedPartitionsPerJob.compute(jobId, (ignored, partitionIds) -> { | ||
| if (partitionIds == null) { | ||
| partitionIds = new HashSet<>(8); | ||
| } | ||
| partitionIds.addAll(newPartitionIds); | ||
| return partitionIds; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Stops the tracking of all partition for the given job. | ||
| */ | ||
| public Collection<ResultPartitionID> stopTrackingPartitions(JobID jobId) { | ||
| Preconditions.checkNotNull(jobId); | ||
|
|
||
| Set<ResultPartitionID> storedPartitions = trackedPartitionsPerJob.remove(jobId); | ||
| return storedPartitions == null | ||
| ? Collections.emptyList() | ||
| : storedPartitions; | ||
| } | ||
|
|
||
| /** | ||
| * Stops the tracking of the given set of partitions for the given job. | ||
| */ | ||
| public void stopTrackingPartitions(JobID jobId, Collection<ResultPartitionID> partitionIds) { | ||
| Preconditions.checkNotNull(jobId); | ||
| Preconditions.checkNotNull(partitionIds); | ||
|
|
||
| // If the JobID is unknown we do not fail here, in line with ShuffleEnvironment#releaseFinishedPartitions | ||
| trackedPartitionsPerJob.computeIfPresent( | ||
| jobId, | ||
| (key, resultPartitionIDS) -> { | ||
| resultPartitionIDS.removeAll(partitionIds); | ||
| return resultPartitionIDS.isEmpty() | ||
| ? null | ||
| : resultPartitionIDS; | ||
| }); | ||
| } | ||
| } | ||
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.
Why do we need the
jobLeaderServiceif there are only partitions but no slots allocated to a given job?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.
I'm not sure; I'm just delayed all operations that were done before.
For the time being we could probably remove the job from the jobLeaderSerbice once the last slot was freed. After all, if a jobmaster failover occurs we remove all partitions anyway.
Long-term though, once we introduce a grace-period for reconnects and/or failovers, I would've expected that we want to continue to observe for leader changes.