You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "siddhantsangwan (via GitHub)" <gi...@apache.org> on 2023/09/08 19:37:28 UTC

[GitHub] [ozone] siddhantsangwan commented on a diff in pull request #5261: HDDS-9257. LegacyReplicationManager: Unhealthy replicas could block under replication handling

siddhantsangwan commented on code in PR #5261:
URL: https://github.com/apache/ozone/pull/5261#discussion_r1320263332


##########
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:
   I think this part requires some modification. If we're deleting a quasi closed replica, we need to ensure it's sequence id is actually less than the container. Otherwise we should delete an UNHEALTHY replica.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org