siddhantsangwan commented on code in PR #8061: URL: https://github.com/apache/ozone/pull/8061#discussion_r1992951110
########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/QuasiClosedStuckOverReplicationHandler.java: ########## @@ -0,0 +1,109 @@ +/* + * 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; + +import java.io.IOException; +import java.util.Comparator; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.hadoop.hdds.scm.container.ContainerInfo; +import org.apache.hadoop.hdds.scm.container.ContainerReplica; + +/** + * Class to correct over replicated QuasiClosed Stuck Ratis containers. + */ +public class QuasiClosedStuckOverReplicationHandler implements UnhealthyReplicationHandler { + + private static final org.slf4j.Logger LOG = + org.slf4j.LoggerFactory.getLogger(QuasiClosedStuckOverReplicationHandler.class); + private final ReplicationManager replicationManager; + private final ReplicationManagerMetrics metrics; + + public QuasiClosedStuckOverReplicationHandler(final ReplicationManager replicationManager) { + this.replicationManager = replicationManager; + this.metrics = replicationManager.getMetrics(); + } + + @Override + public int processAndSendCommands(Set<ContainerReplica> replicas, List<ContainerReplicaOp> pendingOps, + ContainerHealthResult result, int remainingMaintenanceRedundancy) + throws IOException { + + ContainerInfo containerInfo = result.getContainerInfo(); + LOG.debug("Handling over replicated QuasiClosed Stuck Ratis container {}", containerInfo); + + int pendingDelete = 0; + for (ContainerReplicaOp op : pendingOps) { + if (op.getOpType() == ContainerReplicaOp.PendingOpType.ADD) { + pendingDelete++; + } + } + + if (pendingDelete > 0) { + LOG.debug("Container {} has pending delete operations. No more over replication will be scheduled until they " + + "complete", containerInfo); + return 0; + } + + QuasiClosedStuckReplicaCount replicaCount = + new QuasiClosedStuckReplicaCount(replicas, remainingMaintenanceRedundancy); + + List<QuasiClosedStuckReplicaCount.MisReplicatedOrigin> misReplicatedOrigins + = replicaCount.getOverReplicatedOrigins(); + + if (misReplicatedOrigins.isEmpty()) { + LOG.debug("Container {} is not over replicated", containerInfo); + return 0; + } + + int totalCommandsSent = 0; + IOException firstException = null; + for (QuasiClosedStuckReplicaCount.MisReplicatedOrigin origin : misReplicatedOrigins) { + List<ContainerReplica> sortedReplicas = getSortedReplicas(origin.getSources()); Review Comment: Let's remove any replicas that are on stale Datanodes first and then check if the container is still over replicated? -- 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-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org