errose28 commented on code in PR #5261:
URL: https://github.com/apache/ozone/pull/5261#discussion_r1320452758
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/LegacyReplicationManager.java:
##########
@@ -1141,8 +1141,103 @@ private void handleUnderReplicatedHealthy(final
ContainerInfo container,
List<ContainerReplica> replicationSources =
getReplicationSources(container,
replicaSet.getReplicas(), State.CLOSED, State.QUASI_CLOSED);
// This method will handle topology even if replicasNeeded <= 0.
- replicateAnyWithTopology(container, replicationSources,
- placementStatus, replicasNeeded);
+ try {
+ replicateAnyWithTopology(container, replicationSources,
+ placementStatus, replicasNeeded);
+ } catch (SCMException e) {
+ if (e.getResult()
+ .equals(SCMException.ResultCodes.FAILED_TO_FIND_SUITABLE_NODE) &&
+ replicasNeeded > 0) {
+ /*
+ If we reach here, the container is under replicated but placement
+ policy could not find any target Datanodes to host new replicas.
+ We can try unblocking under replication handling by removing any
+ unhealthy replicas. This will free up those datanodes, so they can host
+ healthy replicas.
+ */
+ deleteUnhealthyReplicaIfNeeded(container, replicaSet);
+ }
+ }
+ }
+
+ /**
+ * Finds and deletes an unhealthy replica (UNHEALTHY or QUASI_CLOSED) under
+ * certain conditions.
+ */
+ private void deleteUnhealthyReplicaIfNeeded(ContainerInfo container,
+ RatisContainerReplicaCount replicaCount) {
+ LOG.info("Finding an unhealthy replica to delete for container {} with " +
+ "replicas {} to unblock under replication handling.", container,
+ replicaCount.getReplicas());
+
+ int pendingDeletes = getInflightDel(container.containerID());
+ if (pendingDeletes > 0) {
+ LOG.debug("Container {} has {} pending deletes. Will not delete an " +
+ "unhealthy replica for this container.", container, pendingDeletes);
+ return;
+ }
+
+ List<ContainerReplica> replicas = replicaCount.getReplicas();
+ if (replicas.size() < 3) {
+ LOG.debug("Container {} has only {} replicas. Will not delete an " +
+ "unhealthy replica for this container.", container, replicas.size());
+ return;
+ }
+
+ LifeCycleState containerState = container.getState();
+ boolean foundMatchingReplica = false;
+ for (ContainerReplica replica : replicas) {
+ if (compareState(containerState, replica.getState())) {
+ foundMatchingReplica = true;
+ break;
+ }
+ }
+ if (!foundMatchingReplica) {
+ LOG.debug("No matching replica found for container {} with replicas " +
+ "{}. Will not delete any unhealthy replica for this container.",
+ container, replicas);
+ return;
+ }
+
+ List<ContainerReplica> deleteCandidates = new ArrayList<>();
+ // collect unhealthy replicas on in-service, healthy nodes
+ for (ContainerReplica replica : replicas) {
+ try {
+ NodeStatus nodeStatus =
+ nodeManager.getNodeStatus(replica.getDatanodeDetails());
+ if (!nodeStatus.isHealthy() || !nodeStatus.isInService()) {
+ continue;
+ }
+ } catch (NodeNotFoundException e) {
+ LOG.warn("Skipping replica {} when trying to unblock under " +
+ "replication handling.", replica, e);
+ continue;
+ }
+
+ if (replica.getState() == State.QUASI_CLOSED) {
+ deleteCandidates.add(replica);
+ } else if (replica.getState() == State.UNHEALTHY) {
+ deleteCandidates.add(replica);
+ }
+ }
+
+ if (containerState == LifeCycleState.CLOSED) {
+ deleteExcessLowestBcsIDs(container, deleteCandidates, 1);
+ return;
+ }
+
+ // if the container is quasi_closed, delete a replica only if it's seq id
+ // is less, and it doesn't have a unique origin node
+ if (containerState == LifeCycleState.QUASI_CLOSED) {
+ List<ContainerReplica> nonUniqueDeleteCandidates =
+ findNonUniqueDeleteCandidates(replicas, deleteCandidates);
+ deleteExcessLowestBcsIDs(container, nonUniqueDeleteCandidates, 1);
+ return;
Review Comment:
We shouldn't need to delete a quasi-closed replica here. We would get here
if we have at least one quasi-closed replica and unhealthy replicas on the rest
of the nodes. The quasi-closed replica is under-replicated, which is why we are
in `handleUnderReplicatedHealthy`, but it cannot be replicated because the rest
of the nodes have unhealthy replicas. So this case should only need to delete
unhealthy replicas. I think this would be handled automatically with my
[suggestion](https://github.com/apache/ozone/pull/5261#discussion_r1320440166)
above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]