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


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/health/ClosedWithUnhealthyReplicasHandler.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.hadoop.hdds.scm.container.replication.health;
+
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.container.ContainerReplica;
+import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport;
+import org.apache.hadoop.hdds.scm.container.replication.ContainerCheckRequest;
+import org.apache.hadoop.hdds.scm.container.replication.ReplicationManager;
+import org.apache.ratis.protocol.exceptions.NotLeaderException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+
+/**
+ * Handler to process containers EC which are closed but have some replicas 
that
+ * are unhealthy.
+ */
+public class ClosedWithUnhealthyReplicasHandler extends AbstractCheck {
+
+  public static final Logger LOG =
+      LoggerFactory.getLogger(ClosedWithUnhealthyReplicasHandler.class);
+  private final ReplicationManager replicationManager;
+
+  public ClosedWithUnhealthyReplicasHandler(
+      ReplicationManager replicationManager) {
+    this.replicationManager = replicationManager;
+  }
+
+  /**
+   * Handles a closed EC container with unhealthy replicas. Note that if we
+   * reach here, there is no over, under, or mis replication. This handler
+   * will just send commands to delete the unhealthy replicas.
+   *
+   * <p>
+   * Consider the following set of replicas for a closed EC 3-2 container:
+   * Replica Index 1: Closed
+   * Replica Index 2: Closed
+   * Replica Index 3: Closed replica, Unhealthy replica (2 replicas)
+   * Replica Index 4: Closed
+   * Replica Index 5: Closed
+   *
+   * In this case, the unhealthy replica of index 3 should be deleted. This
+   * is not over replication because that unhealthy replica is not available.
+   * </p>
+   * @param request ContainerCheckRequest object representing the container
+   * @return true if this is a closed EC container with unhealthy replicas,
+   * else false
+   */
+  @Override
+  public boolean handle(ContainerCheckRequest request) {
+    ContainerInfo containerInfo = request.getContainerInfo();
+    if (containerInfo.getReplicationType() != HddsProtos.ReplicationType.EC) {
+      return false;
+    }
+    if (containerInfo.getState() != HddsProtos.LifeCycleState.CLOSED) {
+      return false;
+    }
+
+    Set<ContainerReplica> replicas = request.getContainerReplicas();
+    boolean foundUnhealthy = false;
+    // send delete commands for unhealthy replicas
+    for (ContainerReplica replica : replicas) {
+      if (replica.getState() == ContainerReplicaProto.State.UNHEALTHY) {

Review Comment:
   Yes, I was also thinking about having a check. I've added this check to the 
handler in the latest commit.



-- 
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]

Reply via email to