umamaheswararao commented on code in PR #3743:
URL: https://github.com/apache/ozone/pull/3743#discussion_r967298900


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java:
##########
@@ -187,15 +188,22 @@ public ReplicationManager(final ConfigurationSource conf,
         TimeUnit.MILLISECONDS);
     this.containerReplicaPendingOps = replicaPendingOps;
     this.legacyReplicationManager = legacyReplicationManager;
-    this.ecContainerHealthCheck = new ECContainerHealthCheck();
+    this.ecReplicationCheckHandler = new ECReplicationCheckHandler();
     this.nodeManager = nodeManager;
     this.underRepQueue = createUnderReplicatedQueue();
     this.overRepQueue = new LinkedList<>();
     this.maintenanceRedundancy = rmConf.maintenanceRemainingRedundancy;
     ecUnderReplicationHandler = new ECUnderReplicationHandler(
-        containerPlacement, conf, nodeManager);
+        ecReplicationCheckHandler, containerPlacement, conf, nodeManager);
     ecOverReplicationHandler =
-        new ECOverReplicationHandler(containerPlacement, nodeManager);
+        new ECOverReplicationHandler(ecReplicationCheckHandler,
+            containerPlacement, nodeManager);
+
+    // Chain together the series of checks that are needed to validate the
+    // containers when they are checked by RM.
+    containerCheckChain = new OpenContainerHandler(this);
+    containerCheckChain.addNext(new ClosedWithMismatchedReplicasHandler(this));
+    containerCheckChain.addNext(ecReplicationCheckHandler);

Review Comment:
   I am missing something here. When we addNext, the current default 
implementation in returning HealthCheck back, but we are not using it here. 
Adding two times will replace previous one?
   
     @Override
     public HealthCheck addNext(HealthCheck healthCheck) {
       successor = healthCheck;
       return healthCheck;
     }
   
   You mean to set the next one on previously returned handler object?



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/health/HealthCheck.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.scm.container.replication.ContainerCheckRequest;
+
+/**
+ * Interface used by Container Health Check Handlers.
+ */
+public interface HealthCheck {
+
+  /**
+   * Handle the container and apply the given check to it. This may result in
+   * commands getting generated to correct container states, or nothing
+   * happening if the container is healthy.
+   * @param request ContainerCheckRequest object representing the container
+   * @return True if the request was handled or false if it was not and should
+   *         be handled by the next handler in the chain.
+   */
+  boolean handle(ContainerCheckRequest request);
+
+  /**
+   * Starting from this HealthCheck, call the handle method. If it returns
+   * false, indicating the request was not handled, then forward the request to
+   * the next handler in the chain via its handleChain method. Repeating until
+   * the request is handled, or there are no further handlers to try.
+   * @param request
+   * @return True if the request was handled or false if not handler handled 
it.
+   */
+  boolean handleChain(ContainerCheckRequest request);
+

Review Comment:
   Could you add doc for addNext as well?



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java:
##########
@@ -419,85 +431,33 @@ public long getScmTerm() throws NotLeaderException {
     return scmContext.getTermOfLeader();
   }
 
-  protected ContainerHealthResult processContainer(ContainerInfo containerInfo,
+  protected void processContainer(ContainerInfo containerInfo,
       Queue<ContainerHealthResult.UnderReplicatedHealthResult> underRep,
       Queue<ContainerHealthResult.OverReplicatedHealthResult> overRep,
       ReplicationManagerReport report) throws ContainerNotFoundException {
 
     ContainerID containerID = containerInfo.containerID();
     Set<ContainerReplica> replicas = containerManager.getContainerReplicas(
         containerID);
-
-    if (containerInfo.getState() == HddsProtos.LifeCycleState.OPEN) {
-      if (!isOpenContainerHealthy(containerInfo, replicas)) {
-        report.incrementAndSample(
-            HealthState.OPEN_UNHEALTHY, containerID);
-        eventPublisher.fireEvent(SCMEvents.CLOSE_CONTAINER, containerID);
-        return new ContainerHealthResult.UnHealthyResult(containerInfo);
-      }
-      return new ContainerHealthResult.HealthyResult(containerInfo);
-    }
-
-    if (containerInfo.getState() == HddsProtos.LifeCycleState.CLOSED) {
-      List<ContainerReplica> unhealthyReplicas = replicas.stream()
-          .filter(r -> !compareState(containerInfo.getState(), r.getState()))
-          .collect(Collectors.toList());
-
-      if (unhealthyReplicas.size() > 0) {
-        handleUnhealthyReplicas(containerInfo, unhealthyReplicas);
-      }
-    }
-
     List<ContainerReplicaOp> pendingOps =
         containerReplicaPendingOps.getPendingOps(containerID);
-    ContainerHealthResult health = ecContainerHealthCheck.checkHealth(
-        containerInfo, replicas, pendingOps, maintenanceRedundancy);
-      // TODO - should the report have a HEALTHY state, rather than just bad
-      //        states? It would need to be added to legacy RM too.
-    if (health.getHealthState()
-        == ContainerHealthResult.HealthState.UNDER_REPLICATED) {
-      report.incrementAndSample(HealthState.UNDER_REPLICATED, containerID);
-      ContainerHealthResult.UnderReplicatedHealthResult underHealth
-          = ((ContainerHealthResult.UnderReplicatedHealthResult) health);
-      if (underHealth.isUnrecoverable()) {
-        // TODO - do we need a new health state for unrecoverable EC?
-        report.incrementAndSample(HealthState.MISSING, containerID);
-      }
-      if (!underHealth.isSufficientlyReplicatedAfterPending() &&
-          !underHealth.isUnrecoverable()) {
-        underRep.add(underHealth);
-      }
-    } else if (health.getHealthState()
-        == ContainerHealthResult.HealthState.OVER_REPLICATED) {
-      report.incrementAndSample(HealthState.OVER_REPLICATED, containerID);
-      ContainerHealthResult.OverReplicatedHealthResult overHealth
-          = ((ContainerHealthResult.OverReplicatedHealthResult) health);
-      if (!overHealth.isSufficientlyReplicatedAfterPending()) {
-        overRep.add(overHealth);
-      }
-    }
-    return health;
-  }
 
-  /**
-   * Handles unhealthy container.
-   * A container is inconsistent if any of the replica state doesn't
-   * match the container state. We have to take appropriate action
-   * based on state of the replica.
-   *
-   * @param container ContainerInfo
-   * @param unhealthyReplicas List of ContainerReplica
-   */
-  private void handleUnhealthyReplicas(final ContainerInfo container,
-      List<ContainerReplica> unhealthyReplicas) {
-    Iterator<ContainerReplica> iterator = unhealthyReplicas.iterator();
-    while (iterator.hasNext()) {
-      final ContainerReplica replica = iterator.next();
-      final ContainerReplicaProto.State state = replica.getState();
-      if (state == State.OPEN || state == State.CLOSING) {
-        sendCloseCommand(container, replica.getDatanodeDetails(), true);
-        iterator.remove();
-      }

Review Comment:
   May be we could pass ContainerCheckRequest to processContainer method? 
instead of passing each individual ques and again passing them into 
ContainerCheckRequest? All params passed into this method wrapped into the 
request object.
   



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