use of org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType.MOVE in project ozone by apache.
the class ReplicationManager method deleteSrcDnForMove.
/**
* if the container is in inflightMove, handle move.
* This function assumes replication has been completed
*
* @param cif ContainerInfo
* @param replicaSet An Set of replicas, which may have excess replicas
*/
private void deleteSrcDnForMove(final ContainerInfo cif, final Set<ContainerReplica> replicaSet) {
final ContainerID cid = cif.containerID();
MoveDataNodePair movePair = moveScheduler.getMoveDataNodePair(cid);
if (movePair == null) {
return;
}
final DatanodeDetails srcDn = movePair.getSrc();
ContainerReplicaCount replicaCount = getContainerReplicaCount(cif, replicaSet);
if (!replicaSet.stream().anyMatch(r -> r.getDatanodeDetails().equals(srcDn))) {
// if the target is present but source disappears somehow,
// we can consider move is successful.
compleleteMoveFutureWithResult(cid, MoveResult.COMPLETED);
moveScheduler.completeMove(cid.getProtobuf());
return;
}
int replicationFactor = cif.getReplicationConfig().getRequiredNodes();
ContainerPlacementStatus currentCPS = getPlacementStatus(replicaSet, replicationFactor);
Set<ContainerReplica> newReplicaSet = replicaSet.stream().collect(Collectors.toSet());
newReplicaSet.removeIf(r -> r.getDatanodeDetails().equals(srcDn));
ContainerPlacementStatus newCPS = getPlacementStatus(newReplicaSet, replicationFactor);
if (replicaCount.isOverReplicated() && isPlacementStatusActuallyEqual(currentCPS, newCPS)) {
sendDeleteCommand(cif, srcDn, true);
} else {
// if source and target datanode are both in the replicaset,
// but we can not delete source datanode for now (e.g.,
// there is only 3 replicas or not policy-statisfied , etc.),
// we just complete the future without sending a delete command.
LOG.info("can not remove source replica after successfully " + "replicated to target datanode");
compleleteMoveFutureWithResult(cid, MoveResult.DELETE_FAIL_POLICY);
moveScheduler.completeMove(cid.getProtobuf());
}
}
Aggregations