swamirishi commented on code in PR #3802: URL: https://github.com/apache/ozone/pull/3802#discussion_r991908073
########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/health/RatisReplicationCheckHandler.java: ########## @@ -0,0 +1,198 @@ +/* + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.DatanodeDetails; +import org.apache.hadoop.hdds.scm.ContainerPlacementStatus; +import org.apache.hadoop.hdds.scm.PlacementPolicy; +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.ContainerHealthResult; +import org.apache.hadoop.hdds.scm.container.replication.ContainerReplicaOp; +import org.apache.hadoop.hdds.scm.container.replication.RatisContainerReplicaCount; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType.RATIS; + +/** + * Class to determine the health state of a Ratis Container. Given the container + * and current replica details, along with replicas pending add and delete, + * this class will return a ContainerHealthResult indicating if the container + * is healthy, or under / over replicated etc. + */ +public class RatisReplicationCheckHandler extends AbstractCheck { + public static final Logger LOG = + LoggerFactory.getLogger(RatisReplicationCheckHandler.class); + + /** + * PlacementPolicy which is used to identify where a container + * should be replicated. + */ + private final PlacementPolicy ratisContainerPlacement; + + public RatisReplicationCheckHandler(PlacementPolicy containerPlacement) { + this.ratisContainerPlacement = containerPlacement; + } + + @Override + public boolean handle(ContainerCheckRequest request) { + if (request.getContainerInfo().getReplicationType() != RATIS) { + // This handler is only for Ratis containers. + return false; + } + ReplicationManagerReport report = request.getReport(); + ContainerInfo container = request.getContainerInfo(); + ContainerHealthResult health = checkHealth(request); + if (health.getHealthState() == ContainerHealthResult.HealthState.HEALTHY) { + // If the container is healthy, there is nothing else to do in this + // handler so return as unhandled so any further handlers will be tried. + return false; + } + if (health.getHealthState() + == ContainerHealthResult.HealthState.UNDER_REPLICATED) { + report.incrementAndSample( + ReplicationManagerReport.HealthState.UNDER_REPLICATED, + container.containerID()); + ContainerHealthResult.UnderReplicatedHealthResult underHealth + = ((ContainerHealthResult.UnderReplicatedHealthResult) health); + if (underHealth.isUnrecoverable()) { + report.incrementAndSample(ReplicationManagerReport.HealthState.MISSING, + container.containerID()); + } + if (underHealth.isMisReplicated()) { + report.incrementAndSample( + ReplicationManagerReport.HealthState.MIS_REPLICATED, + container.containerID()); + } + // TODO - if it is unrecoverable, should we return false to other + // handlers can be tried? + if (!underHealth.isUnrecoverable() && + (underHealth.isMisReplicatedAfterPending() || + !underHealth.isSufficientlyReplicatedAfterPending())) { + request.getReplicationQueue().enqueue(underHealth); + } + return true; + } + if (health.getHealthState() + == ContainerHealthResult.HealthState.OVER_REPLICATED) { + report.incrementAndSample( + ReplicationManagerReport.HealthState.OVER_REPLICATED, + container.containerID()); + ContainerHealthResult.OverReplicatedHealthResult overHealth + = ((ContainerHealthResult.OverReplicatedHealthResult) health); + if (!overHealth.isSufficientlyReplicatedAfterPending()) { + request.getReplicationQueue().enqueue(overHealth); + } + return true; + } + return false; + } + + public ContainerHealthResult checkHealth(ContainerCheckRequest request) { Review Comment: Probably could add @visibleForTesting if you want to add unit tests or could even change the access specifier using replication using reflection. -- 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]
