org.apache.flink.runtime.executiongraph.JobMasterPartitionTrackerWrapper Maven / Gradle / Ivy
/*
* 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.executiongraph;
import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.runtime.clusterframework.types.ResourceID;
import org.apache.flink.runtime.io.network.partition.BlockingShuffleType;
import org.apache.flink.runtime.io.network.partition.JobMasterPartitionTracker;
import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
import java.util.Collection;
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
* YarnShuffleWrapper for {@link JobMasterPartitionTracker}.
*/
public class JobMasterPartitionTrackerWrapper {
private final BlockingShuffleType shuffleType;
private final boolean radicalShuffleFailoverEnabled;
private final JobMasterPartitionTracker partitionTracker;
public JobMasterPartitionTrackerWrapper(
JobMasterPartitionTracker jobMasterPartitionTracker,
BlockingShuffleType shuffleType,
boolean radicalShuffleFailoverEnabled) {
this.partitionTracker = checkNotNull(jobMasterPartitionTracker);
this.shuffleType = shuffleType;
this.radicalShuffleFailoverEnabled = radicalShuffleFailoverEnabled;
}
public void startTrackingProducedPartitions(
ExecutionAttemptID executionAttemptID,
Collection intermediateResultPartitions,
TaskManagerLocation taskManagerLocation) {
checkNotNull(executionAttemptID);
checkNotNull(intermediateResultPartitions);
checkNotNull(taskManagerLocation);
if (isRadicalShuffleFailoverEnabled()) {
ResourceID resourceID = getResourceIDFromTaskManagerLocation(taskManagerLocation);
for (IntermediateResultPartition resultPartition : intermediateResultPartitions) {
if (resultPartition.getResultType() == ResultPartitionType.BLOCKING) {
partitionTracker.startTrackingPartition(
resourceID,
new ResultPartitionID(resultPartition.getPartitionId(), executionAttemptID));
}
}
}
}
public void stopTrackingProducedPartitions(
ExecutionAttemptID executionAttemptID,
Collection intermediateResultPartitions) {
checkNotNull(executionAttemptID);
checkNotNull(intermediateResultPartitions);
if (isRadicalShuffleFailoverEnabled()) {
for (IntermediateResultPartition resultPartition : intermediateResultPartitions) {
partitionTracker.stopTrackingPartition(
new ResultPartitionID(resultPartition.getPartitionId(), executionAttemptID));
}
}
}
public void markPartitionsFailedWithSameLocation(TaskManagerLocation taskManagerLocation) {
checkNotNull(taskManagerLocation);
if (isRadicalShuffleFailoverEnabled()) {
ResourceID resourceID = getResourceIDFromTaskManagerLocation(taskManagerLocation);
// mark partition failed.
Collection resultPartitionIds = partitionTracker.getTrackedPartitions(resourceID);
for (ResultPartitionID resultPartitionID : resultPartitionIds) {
partitionTracker.markPartitionFailed(resultPartitionID);
}
}
}
public boolean isPartitionFailed(ResultPartitionID resultPartitionID) {
checkNotNull(resultPartitionID);
if (isRadicalShuffleFailoverEnabled()) {
return partitionTracker.isPartitionFailed(resultPartitionID);
}
return false;
}
@VisibleForTesting
public Collection getTrackedPartitionsByLocation(ResourceID resourceID) {
return partitionTracker.getTrackedPartitions(resourceID);
}
@VisibleForTesting
public boolean isRadicalShuffleFailoverEnabled() {
return shuffleType == BlockingShuffleType.YARN && radicalShuffleFailoverEnabled;
}
public static ResourceID getResourceIDFromTaskManagerLocation(TaskManagerLocation location) {
return new ResourceID(location.address().getHostAddress());
}
}