diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerReplicaCount.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerReplicaCount.java
index ec5a87a89090..e23c4e691e0f 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerReplicaCount.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerReplicaCount.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -6,9 +6,9 @@
* 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
- *
+ *
+ * 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.
@@ -22,238 +22,24 @@
import java.util.Set;
-import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.DECOMMISSIONED;
-import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.DECOMMISSIONING;
-import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.ENTERING_MAINTENANCE;
-import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.IN_MAINTENANCE;
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.IN_SERVICE;
/**
- * Immutable object that is created with a set of ContainerReplica objects and
- * the number of in flight replica add and deletes, the container replication
- * factor and the min count which must be available for maintenance. This
- * information can be used to determine if the container is over or under
- * replicated and also how many additional replicas need created or removed.
+ * Common interface for EC and non-EC container replica counts.
+ * TODO pull up more methods if needed
*/
-public class ContainerReplicaCount {
-
- private int healthyCount = 0;
- private int decommissionCount = 0;
- private int maintenanceCount = 0;
- private int inFlightAdd = 0;
- private int inFlightDel = 0;
- private int repFactor;
- private int minHealthyForMaintenance;
- private ContainerInfo container;
- private Set replica;
-
- public ContainerReplicaCount(ContainerInfo container,
- Set replica, int inFlightAdd,
- int inFlightDelete, int replicationFactor,
- int minHealthyForMaintenance) {
- this.healthyCount = 0;
- this.decommissionCount = 0;
- this.maintenanceCount = 0;
- this.inFlightAdd = inFlightAdd;
- this.inFlightDel = inFlightDelete;
- this.repFactor = replicationFactor;
- this.replica = replica;
- this.minHealthyForMaintenance
- = Math.min(this.repFactor, minHealthyForMaintenance);
- this.container = container;
-
- for (ContainerReplica cr : this.replica) {
- HddsProtos.NodeOperationalState state =
- cr.getDatanodeDetails().getPersistedOpState();
- if (state == DECOMMISSIONED || state == DECOMMISSIONING) {
- decommissionCount++;
- } else if (state == IN_MAINTENANCE || state == ENTERING_MAINTENANCE) {
- maintenanceCount++;
- } else {
- healthyCount++;
- }
- }
- }
-
- public int getHealthyCount() {
- return healthyCount;
- }
+public interface ContainerReplicaCount {
+ ContainerInfo getContainer();
- public int getDecommissionCount() {
- return decommissionCount;
- }
+ Set getReplicas();
- public int getMaintenanceCount() {
- return maintenanceCount;
- }
+ boolean isSufficientlyReplicated();
- public int getReplicationFactor() {
- return repFactor;
- }
+ boolean isOverReplicated();
- public ContainerInfo getContainer() {
- return container;
- }
+ int getDecommissionCount();
- public Set getReplica() {
- return replica;
- }
-
- @Override
- public String toString() {
- return "Container State: " + container.getState() +
- " Replica Count: " + replica.size() +
- " Healthy Count: " + healthyCount +
- " Decommission Count: " + decommissionCount +
- " Maintenance Count: " + maintenanceCount +
- " inFlightAdd Count: " + inFlightAdd +
- " inFightDel Count: " + inFlightDel +
- " ReplicationFactor: " + repFactor +
- " minMaintenance Count: " + minHealthyForMaintenance;
- }
-
- /**
- * Calculates the the delta of replicas which need to be created or removed
- * to ensure the container is correctly replicated when considered inflight
- * adds and deletes.
- *
- * When considering inflight operations, it is assumed any operation will
- * fail. However, to consider the worst case and avoid data loss, we always
- * assume a delete will succeed and and add will fail. In this way, we will
- * avoid scheduling too many deletes which could result in dataloss.
- *
- * Decisions around over-replication are made only on healthy replicas,
- * ignoring any in maintenance and also any inflight adds. InFlight adds are
- * ignored, as they may not complete, so if we have:
- *
- * H, H, H, IN_FLIGHT_ADD
- *
- * And then schedule a delete, we could end up under-replicated (add fails,
- * delete completes). It is better to let the inflight operations complete
- * and then deal with any further over or under replication.
- *
- * For maintenance replicas, assuming replication factor 3, and minHealthy
- * 2, it is possible for all 3 hosts to be put into maintenance, leaving the
- * following (H = healthy, M = maintenance):
- *
- * H, H, M, M, M
- *
- * Even though we are tracking 5 replicas, this is not over replicated as we
- * ignore the maintenance copies. Later, the replicas could look like:
- *
- * H, H, H, H, M
- *
- * At this stage, the container is over replicated by 1, so one replica can be
- * removed.
- *
- * For containers which have replication factor healthy replica, we ignore any
- * inflight add or deletes, as they may fail. Instead, wait for them to
- * complete and then deal with any excess or deficit.
- *
- * For under replicated containers we do consider inflight add and delete to
- * avoid scheduling more adds than needed. There is additional logic around
- * containers with maintenance replica to ensure minHealthyForMaintenance
- * replia are maintained.
- *
- * @return Delta of replicas needed. Negative indicates over replication and
- * containers should be removed. Positive indicates over replication
- * and zero indicates the containers has replicationFactor healthy
- * replica
- */
- public int additionalReplicaNeeded() {
- int delta = missingReplicas();
-
- if (delta < 0) {
- // Over replicated, so may need to remove a container. Do not consider
- // inFlightAdds, as they may fail, but do consider inFlightDel which
- // will reduce the over-replication if it completes.
- // Note this could make the delta positive if there are too many in flight
- // deletes, which will result in an additional being scheduled.
- return delta + inFlightDel;
- } else {
- // May be under or perfectly replicated.
- // We must consider in flight add and delete when calculating the new
- // containers needed, but we bound the lower limit at zero to allow
- // inflight operations to complete before handling any potential over
- // replication
- return Math.max(0, delta - inFlightAdd + inFlightDel);
- }
- }
-
- /**
- * Returns the count of replicas which need to be created or removed to
- * ensure the container is perfectly replicate. Inflight operations are not
- * considered here, but the logic to determine the missing or excess counts
- * for maintenance is present.
- *
- * Decisions around over-replication are made only on healthy replicas,
- * ignoring any in maintenance. For example, if we have:
- *
- * H, H, H, M, M
- *
- * This will not be consider over replicated until one of the Maintenance
- * replicas moves to Healthy.
- *
- * If the container is perfectly replicated, zero will be return.
- *
- * If it is under replicated a positive value will be returned, indicating
- * how many replicas must be added.
- *
- * If it is over replicated a negative value will be returned, indicating now
- * many replicas to remove.
- *
- * @return Zero if the container is perfectly replicated, a positive value
- * for under replicated and a negative value for over replicated.
- */
- private int missingReplicas() {
- int delta = repFactor - healthyCount;
-
- if (delta < 0) {
- // Over replicated, so may need to remove a container.
- return delta;
- } else if (delta > 0) {
- // May be under-replicated, depending on maintenance.
- delta = Math.max(0, delta - maintenanceCount);
- int neededHealthy =
- Math.max(0, minHealthyForMaintenance - healthyCount);
- delta = Math.max(neededHealthy, delta);
- return delta;
- } else { // delta == 0
- // We have exactly the number of healthy replicas needed.
- return delta;
- }
- }
-
- /**
- * Return true if the container is sufficiently replicated. Decommissioning
- * and Decommissioned containers are ignored in this check, assuming they will
- * eventually be removed from the cluster.
- * This check ignores inflight additions, as those replicas have not yet been
- * created and the create could fail for some reason.
- * The check does consider inflight deletes as there may be 3 healthy replicas
- * now, but once the delete completes it will reduce to 2.
- * We also assume a replica in Maintenance state cannot be removed, so the
- * pending delete would affect only the healthy replica count.
- *
- * @return True if the container is sufficiently replicated and False
- * otherwise.
- */
- public boolean isSufficientlyReplicated() {
- return missingReplicas() + inFlightDel <= 0;
- }
-
- /**
- * Return true is the container is over replicated. Decommission and
- * maintenance containers are ignored for this check.
- * The check ignores inflight additions, as they may fail, but it does
- * consider inflight deletes, as they would reduce the over replication when
- * they complete.
- *
- * @return True if the container is over replicated, false otherwise.
- */
- public boolean isOverReplicated() {
- return missingReplicas() + inFlightDel < 0;
- }
+ int getMaintenanceCount();
/**
* Returns true if the container is healthy, meaning all replica which are not
@@ -262,22 +48,21 @@ public boolean isOverReplicated() {
*
* @return true if the container is healthy, false otherwise
*/
- public boolean isHealthy() {
- return (container.getState() == HddsProtos.LifeCycleState.CLOSED
- || container.getState() == HddsProtos.LifeCycleState.QUASI_CLOSED)
- && replica.stream()
+ default boolean isHealthy() {
+ HddsProtos.LifeCycleState containerState = getContainer().getState();
+ return (containerState == HddsProtos.LifeCycleState.CLOSED
+ || containerState == HddsProtos.LifeCycleState.QUASI_CLOSED)
+ && getReplicas().stream()
.filter(r -> r.getDatanodeDetails().getPersistedOpState() == IN_SERVICE)
.allMatch(r -> LegacyReplicationManager.compareState(
- container.getState(), r.getState()));
+ containerState, r.getState()));
+
}
/**
- * Returns true is there are no replicas of a container available, ie the
- * set of container replica passed in the constructor has zero entries.
+ * Return true if there are insufficient replicas to recover this container.
*
- * @return true if there are no replicas, false otherwise.
+ * @return true if there are insufficient replicas, false otherwise.
*/
- public boolean isMissing() {
- return replica.size() == 0;
- }
+ boolean isUnrecoverable();
}
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ECContainerReplicaCount.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ECContainerReplicaCount.java
index fe3aafe404e8..822fb3a54889 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ECContainerReplicaCount.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ECContainerReplicaCount.java
@@ -59,7 +59,7 @@
* * Maintenance copies are not considered until they are back to IN_SERVICE
*/
-public class ECContainerReplicaCount {
+public class ECContainerReplicaCount implements ContainerReplicaCount {
private final ContainerInfo containerInfo;
private final ECReplicationConfig repConfig;
@@ -128,10 +128,26 @@ public ECContainerReplicaCount(ContainerInfo containerInfo,
}
}
+ @Override
+ public ContainerInfo getContainer() {
+ return containerInfo;
+ }
+
+ @Override
public Set getReplicas() {
return replicas;
}
+ @Override
+ public int getDecommissionCount() {
+ return decommissionIndexes.size();
+ }
+
+ @Override
+ public int getMaintenanceCount() {
+ return maintenanceIndexes.size();
+ }
+
/**
* Get a set containing all decommissioning indexes, or an empty set if none
* are decommissioning. Note it is possible for an index to be
@@ -184,7 +200,8 @@ public Set maintenanceIndexes() {
* Ie, less than EC Datanum containers are present.
* @return True if the container cannot be recovered, false otherwise.
*/
- public boolean unRecoverable() {
+ @Override
+ public boolean isUnrecoverable() {
Set distinct = new HashSet<>();
distinct.addAll(healthyIndexes.keySet());
distinct.addAll(decommissionIndexes.keySet());
@@ -292,6 +309,11 @@ public boolean isOverReplicated(boolean includePendingDelete) {
return false;
}
+ @Override
+ public boolean isOverReplicated() {
+ return isOverReplicated(false);
+ }
+
/**
* Return an unsorted list of any replica indexes which have more than one
* replica and are therefore over-replicated. Maintenance replicas are ignored
@@ -365,6 +387,11 @@ public boolean isSufficientlyReplicated(boolean includePendingAdd) {
>= repConfig.getData() + remainingMaintenanceRedundancy;
}
+ @Override
+ public boolean isSufficientlyReplicated() {
+ return isSufficientlyReplicated(false);
+ }
+
/**
* Check if there is an entry in the map for all expected replica indexes,
* and also that the count against each index is greater than zero.
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/RatisContainerReplicaCount.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/RatisContainerReplicaCount.java
new file mode 100644
index 000000000000..f7c5b28f0058
--- /dev/null
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/RatisContainerReplicaCount.java
@@ -0,0 +1,272 @@
+/**
+ * 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;
+
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+
+import java.util.Set;
+
+import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.DECOMMISSIONED;
+import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.DECOMMISSIONING;
+import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.ENTERING_MAINTENANCE;
+import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.IN_MAINTENANCE;
+
+/**
+ * Immutable object that is created with a set of ContainerReplica objects and
+ * the number of in flight replica add and deletes, the container replication
+ * factor and the min count which must be available for maintenance. This
+ * information can be used to determine if the container is over or under
+ * replicated and also how many additional replicas need created or removed.
+ */
+public class RatisContainerReplicaCount implements ContainerReplicaCount {
+
+ private int healthyCount;
+ private int decommissionCount;
+ private int maintenanceCount;
+ private final int inFlightAdd;
+ private final int inFlightDel;
+ private final int repFactor;
+ private final int minHealthyForMaintenance;
+ private final ContainerInfo container;
+ private final Set replica;
+
+ public RatisContainerReplicaCount(ContainerInfo container,
+ Set replica, int inFlightAdd,
+ int inFlightDelete, int replicationFactor,
+ int minHealthyForMaintenance) {
+ this.healthyCount = 0;
+ this.decommissionCount = 0;
+ this.maintenanceCount = 0;
+ this.inFlightAdd = inFlightAdd;
+ this.inFlightDel = inFlightDelete;
+ this.repFactor = replicationFactor;
+ this.replica = replica;
+ this.minHealthyForMaintenance
+ = Math.min(this.repFactor, minHealthyForMaintenance);
+ this.container = container;
+
+ for (ContainerReplica cr : this.replica) {
+ HddsProtos.NodeOperationalState state =
+ cr.getDatanodeDetails().getPersistedOpState();
+ if (state == DECOMMISSIONED || state == DECOMMISSIONING) {
+ decommissionCount++;
+ } else if (state == IN_MAINTENANCE || state == ENTERING_MAINTENANCE) {
+ maintenanceCount++;
+ } else {
+ healthyCount++;
+ }
+ }
+ }
+
+ public int getHealthyCount() {
+ return healthyCount;
+ }
+
+ @Override
+ public int getDecommissionCount() {
+ return decommissionCount;
+ }
+
+ @Override
+ public int getMaintenanceCount() {
+ return maintenanceCount;
+ }
+
+ public int getReplicationFactor() {
+ return repFactor;
+ }
+
+ @Override
+ public ContainerInfo getContainer() {
+ return container;
+ }
+
+ @Override
+ public Set getReplicas() {
+ return replica;
+ }
+
+ @Override
+ public String toString() {
+ return "Container State: " + container.getState() +
+ " Replica Count: " + replica.size() +
+ " Healthy Count: " + healthyCount +
+ " Decommission Count: " + decommissionCount +
+ " Maintenance Count: " + maintenanceCount +
+ " inFlightAdd Count: " + inFlightAdd +
+ " inFightDel Count: " + inFlightDel +
+ " ReplicationFactor: " + repFactor +
+ " minMaintenance Count: " + minHealthyForMaintenance;
+ }
+
+ /**
+ * Calculates the delta of replicas which need to be created or removed
+ * to ensure the container is correctly replicated when considered inflight
+ * adds and deletes.
+ *
+ * When considering inflight operations, it is assumed any operation will
+ * fail. However, to consider the worst case and avoid data loss, we always
+ * assume a delete will succeed and and add will fail. In this way, we will
+ * avoid scheduling too many deletes which could result in dataloss.
+ *
+ * Decisions around over-replication are made only on healthy replicas,
+ * ignoring any in maintenance and also any inflight adds. InFlight adds are
+ * ignored, as they may not complete, so if we have:
+ *
+ * H, H, H, IN_FLIGHT_ADD
+ *
+ * And then schedule a delete, we could end up under-replicated (add fails,
+ * delete completes). It is better to let the inflight operations complete
+ * and then deal with any further over or under replication.
+ *
+ * For maintenance replicas, assuming replication factor 3, and minHealthy
+ * 2, it is possible for all 3 hosts to be put into maintenance, leaving the
+ * following (H = healthy, M = maintenance):
+ *
+ * H, H, M, M, M
+ *
+ * Even though we are tracking 5 replicas, this is not over replicated as we
+ * ignore the maintenance copies. Later, the replicas could look like:
+ *
+ * H, H, H, H, M
+ *
+ * At this stage, the container is over replicated by 1, so one replica can be
+ * removed.
+ *
+ * For containers which have replication factor healthy replica, we ignore any
+ * inflight add or deletes, as they may fail. Instead, wait for them to
+ * complete and then deal with any excess or deficit.
+ *
+ * For under replicated containers we do consider inflight add and delete to
+ * avoid scheduling more adds than needed. There is additional logic around
+ * containers with maintenance replica to ensure minHealthyForMaintenance
+ * replia are maintained.
+ *
+ * @return Delta of replicas needed. Negative indicates over replication and
+ * containers should be removed. Positive indicates over replication
+ * and zero indicates the containers has replicationFactor healthy
+ * replica
+ */
+ public int additionalReplicaNeeded() {
+ int delta = missingReplicas();
+
+ if (delta < 0) {
+ // Over replicated, so may need to remove a container. Do not consider
+ // inFlightAdds, as they may fail, but do consider inFlightDel which
+ // will reduce the over-replication if it completes.
+ // Note this could make the delta positive if there are too many in flight
+ // deletes, which will result in an additional being scheduled.
+ return delta + inFlightDel;
+ } else {
+ // May be under or perfectly replicated.
+ // We must consider in flight add and delete when calculating the new
+ // containers needed, but we bound the lower limit at zero to allow
+ // inflight operations to complete before handling any potential over
+ // replication
+ return Math.max(0, delta - inFlightAdd + inFlightDel);
+ }
+ }
+
+ /**
+ * Returns the count of replicas which need to be created or removed to
+ * ensure the container is perfectly replicate. Inflight operations are not
+ * considered here, but the logic to determine the missing or excess counts
+ * for maintenance is present.
+ *
+ * Decisions around over-replication are made only on healthy replicas,
+ * ignoring any in maintenance. For example, if we have:
+ *
+ * H, H, H, M, M
+ *
+ * This will not be consider over replicated until one of the Maintenance
+ * replicas moves to Healthy.
+ *
+ * If the container is perfectly replicated, zero will be return.
+ *
+ * If it is under replicated a positive value will be returned, indicating
+ * how many replicas must be added.
+ *
+ * If it is over replicated a negative value will be returned, indicating now
+ * many replicas to remove.
+ *
+ * @return Zero if the container is perfectly replicated, a positive value
+ * for under replicated and a negative value for over replicated.
+ */
+ private int missingReplicas() {
+ int delta = repFactor - healthyCount;
+
+ if (delta < 0) {
+ // Over replicated, so may need to remove a container.
+ return delta;
+ } else if (delta > 0) {
+ // May be under-replicated, depending on maintenance.
+ delta = Math.max(0, delta - maintenanceCount);
+ int neededHealthy =
+ Math.max(0, minHealthyForMaintenance - healthyCount);
+ delta = Math.max(neededHealthy, delta);
+ return delta;
+ } else { // delta == 0
+ // We have exactly the number of healthy replicas needed.
+ return delta;
+ }
+ }
+
+ /**
+ * Return true if the container is sufficiently replicated. Decommissioning
+ * and Decommissioned containers are ignored in this check, assuming they will
+ * eventually be removed from the cluster.
+ * This check ignores inflight additions, as those replicas have not yet been
+ * created and the create could fail for some reason.
+ * The check does consider inflight deletes as there may be 3 healthy replicas
+ * now, but once the delete completes it will reduce to 2.
+ * We also assume a replica in Maintenance state cannot be removed, so the
+ * pending delete would affect only the healthy replica count.
+ *
+ * @return True if the container is sufficiently replicated and False
+ * otherwise.
+ */
+ @Override
+ public boolean isSufficientlyReplicated() {
+ return missingReplicas() + inFlightDel <= 0;
+ }
+
+ /**
+ * Return true is the container is over replicated. Decommission and
+ * maintenance containers are ignored for this check.
+ * The check ignores inflight additions, as they may fail, but it does
+ * consider inflight deletes, as they would reduce the over replication when
+ * they complete.
+ *
+ * @return True if the container is over replicated, false otherwise.
+ */
+ @Override
+ public boolean isOverReplicated() {
+ return missingReplicas() + inFlightDel < 0;
+ }
+
+ /**
+ * Returns true is there are no replicas of the container available, ie the
+ * set of container replicas has zero entries.
+ *
+ * @return true if there are no replicas, false otherwise.
+ */
+ @Override
+ public boolean isUnrecoverable() {
+ return getReplicas().isEmpty();
+ }
+}
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECContainerHealthCheck.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECContainerHealthCheck.java
index 8e86564823cc..b79fc03d0721 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECContainerHealthCheck.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECContainerHealthCheck.java
@@ -71,7 +71,7 @@ public ContainerHealthResult checkHealth(ContainerInfo container,
return new ContainerHealthResult.UnderReplicatedHealthResult(
container, remainingRedundancy, dueToDecommission,
replicaCount.isSufficientlyReplicated(true),
- replicaCount.unRecoverable());
+ replicaCount.isUnrecoverable());
}
if (replicaCount.isOverReplicated(false)) {
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationHandler.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationHandler.java
index 3bf016124d47..64cdadf266cd 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationHandler.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationHandler.java
@@ -118,7 +118,7 @@ public Map> processAndCreateCommands(
container.getContainerID(), replicaCount.getReplicas());
return emptyMap();
}
- if (replicaCount.unRecoverable()) {
+ if (replicaCount.isUnrecoverable()) {
LOG.warn("The container {} is unrecoverable. The available replicas" +
" are: {}.", container.containerID(), replicaCount.getReplicas());
return emptyMap();
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/LegacyReplicationManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/LegacyReplicationManager.java
index 79e11bab5a3e..33e697867c06 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/LegacyReplicationManager.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/LegacyReplicationManager.java
@@ -34,6 +34,7 @@
import org.apache.hadoop.hdds.scm.PlacementPolicy;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.RatisContainerReplicaCount;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.ContainerManager;
import org.apache.hadoop.hdds.scm.container.ContainerNotFoundException;
@@ -492,7 +493,7 @@ protected void processContainer(ContainerInfo container,
return;
}
- ContainerReplicaCount replicaSet =
+ RatisContainerReplicaCount replicaSet =
getContainerReplicaCount(container, replicas);
ContainerPlacementStatus placementStatus = getPlacementStatus(
replicas, container.getReplicationConfig().getRequiredNodes());
@@ -524,7 +525,7 @@ protected void processContainer(ContainerInfo container,
if (!sufficientlyReplicated) {
report.incrementAndSample(
HealthState.UNDER_REPLICATED, container.containerID());
- if (replicaSet.isMissing()) {
+ if (replicaSet.isUnrecoverable()) {
report.incrementAndSample(HealthState.MISSING,
container.containerID());
}
@@ -990,9 +991,9 @@ public ContainerReplicaCount getContainerReplicaCount(ContainerInfo container)
* @return ContainerReplicaCount representing the current state of the
* container
*/
- private ContainerReplicaCount getContainerReplicaCount(
+ private RatisContainerReplicaCount getContainerReplicaCount(
ContainerInfo container, Set replica) {
- return new ContainerReplicaCount(
+ return new RatisContainerReplicaCount(
container,
replica,
getInflightAdd(container.containerID()),
@@ -1122,10 +1123,10 @@ private void forceCloseContainer(final ContainerInfo container,
* current replica count and inflight adds and deletes
*/
private void handleUnderReplicatedContainer(final ContainerInfo container,
- final ContainerReplicaCount replicaSet,
+ final RatisContainerReplicaCount replicaSet,
final ContainerPlacementStatus placementStatus) {
LOG.debug("Handling under-replicated container: {}", container);
- Set replicas = replicaSet.getReplica();
+ Set replicas = replicaSet.getReplicas();
try {
if (replicaSet.isSufficientlyReplicated()
@@ -1236,9 +1237,9 @@ private void handleUnderReplicatedContainer(final ContainerInfo container,
* current replica count and inflight adds and deletes
*/
private void handleOverReplicatedContainer(final ContainerInfo container,
- final ContainerReplicaCount replicaSet) {
+ final RatisContainerReplicaCount replicaSet) {
- final Set replicas = replicaSet.getReplica();
+ final Set replicas = replicaSet.getReplicas();
final ContainerID id = container.containerID();
final int replicationFactor =
container.getReplicationConfig().getRequiredNodes();
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java
index fc643af51baa..a6d00983aa43 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java
@@ -32,6 +32,7 @@
import org.apache.hadoop.hdds.scm.container.ContainerNotFoundException;
import org.apache.hadoop.hdds.scm.container.ContainerReplica;
import org.apache.hadoop.hdds.scm.container.ContainerReplicaCount;
+import org.apache.hadoop.hdds.scm.container.ECContainerReplicaCount;
import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport;
import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport.HealthState;
import org.apache.hadoop.hdds.scm.ha.SCMContext;
@@ -337,7 +338,11 @@ private synchronized void run() {
*/
public ContainerReplicaCount getContainerReplicaCount(ContainerID containerID)
throws ContainerNotFoundException {
- return legacyReplicationManager.getContainerReplicaCount(containerID);
+ ContainerInfo container = containerManager.getContainer(containerID);
+ if (container.getReplicationType() == EC) {
+ return getECContainerReplicaCount(container);
+ }
+ return legacyReplicationManager.getContainerReplicaCount(container);
}
/**
@@ -493,6 +498,16 @@ public boolean isContainerReplicatingOrDeleting(ContainerID containerID) {
.isContainerReplicatingOrDeleting(containerID);
}
+ private ECContainerReplicaCount getECContainerReplicaCount(
+ ContainerInfo containerInfo) throws ContainerNotFoundException {
+ Set replicas = containerManager.getContainerReplicas(
+ containerInfo.containerID());
+ List pendingOps =
+ containerReplicaPendingOps.getPendingOps(containerInfo.containerID());
+ // TODO: define maintenance redundancy for EC (HDDS-6975)
+ return new ECContainerReplicaCount(containerInfo, replicas, pendingOps, 0);
+ }
+
/**
* Wrap the call to nodeManager.getNodeStatus, catching any
* NodeNotFoundException and instead throwing an IllegalStateException.
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeAdminMonitorImpl.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeAdminMonitorImpl.java
index f096f4e83f2d..fc5e2c73062e 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeAdminMonitorImpl.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeAdminMonitorImpl.java
@@ -304,7 +304,7 @@ private boolean checkContainersReplicatedOnNode(DatanodeDetails dn)
if (underReplicated < CONTAINER_DETAILS_LOGGING_LIMIT
|| LOG.isDebugEnabled()) {
LOG.info("Under Replicated Container {} {}; {}",
- cid, replicaSet, replicaDetails(replicaSet.getReplica()));
+ cid, replicaSet, replicaDetails(replicaSet.getReplicas()));
}
underReplicated++;
}
@@ -315,7 +315,7 @@ private boolean checkContainersReplicatedOnNode(DatanodeDetails dn)
if (unhealthy < CONTAINER_DETAILS_LOGGING_LIMIT
|| LOG.isDebugEnabled()) {
LOG.info("Unhealthy Container {} {}; {}",
- cid, replicaSet, replicaDetails(replicaSet.getReplica()));
+ cid, replicaSet, replicaDetails(replicaSet.getReplicas()));
}
unhealthy++;
}
diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestECContainerReplicaCount.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestECContainerReplicaCount.java
index 94c1dd5e4b60..37e105fbee24 100644
--- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestECContainerReplicaCount.java
+++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestECContainerReplicaCount.java
@@ -70,7 +70,7 @@ public void testPerfectlyReplicatedContainer() {
new ECContainerReplicaCount(container, replica,
Collections.emptyList(), 1);
Assertions.assertTrue(rcnt.isSufficientlyReplicated(false));
- Assertions.assertFalse(rcnt.unRecoverable());
+ Assertions.assertFalse(rcnt.isUnrecoverable());
}
@Test
@@ -467,14 +467,14 @@ public void testMissing() {
ECContainerReplicaCount rcnt =
new ECContainerReplicaCount(container, new HashSet<>(),
Collections.emptyList(), 1);
- Assertions.assertTrue(rcnt.unRecoverable());
+ Assertions.assertTrue(rcnt.isUnrecoverable());
Assertions.assertEquals(5, rcnt.unavailableIndexes(true).size());
Set replica = ReplicationTestUtil
.createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_MAINTENANCE, 2));
rcnt = new ECContainerReplicaCount(container, replica,
Collections.emptyList(), 1);
- Assertions.assertTrue(rcnt.unRecoverable());
+ Assertions.assertTrue(rcnt.isUnrecoverable());
Assertions.assertEquals(3, rcnt.unavailableIndexes(true).size());
Assertions.assertEquals(0, rcnt.additionalMaintenanceCopiesNeeded());
@@ -485,7 +485,7 @@ public void testMissing() {
rcnt = new ECContainerReplicaCount(container, replica,
Collections.emptyList(), 1);
// Not missing as the decommission replicas are still online
- Assertions.assertFalse(rcnt.unRecoverable());
+ Assertions.assertFalse(rcnt.isUnrecoverable());
Assertions.assertEquals(0, rcnt.unavailableIndexes(true).size());
}
diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestContainerReplicaCount.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestRatisContainerReplicaCount.java
similarity index 68%
rename from hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestContainerReplicaCount.java
rename to hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestRatisContainerReplicaCount.java
index 542084f4816f..5e5767c8ec02 100644
--- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestContainerReplicaCount.java
+++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/states/TestRatisContainerReplicaCount.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -23,8 +23,7 @@
import org.apache.hadoop.hdds.scm.container.ContainerID;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.ContainerReplica;
-import org.apache.hadoop.hdds.scm.container.ContainerReplicaCount;
-import org.junit.jupiter.api.BeforeEach;
+import org.apache.hadoop.hdds.scm.container.RatisContainerReplicaCount;
import org.junit.jupiter.api.Test;
import java.util.HashSet;
@@ -48,149 +47,145 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
- * Class used to test the ContainerReplicaCount class.
+ * Class used to test the RatisContainerReplicaCount class.
*/
-public class TestContainerReplicaCount {
-
- @BeforeEach
- public void setup() {
- }
+class TestRatisContainerReplicaCount {
@Test
- public void testThreeHealthyReplica() {
+ void testThreeHealthyReplica() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, true, 0, false);
}
@Test
- public void testTwoHealthyReplica() {
+ void testTwoHealthyReplica() {
Set replica = registerNodes(IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, false, 1, false);
}
@Test
- public void testOneHealthyReplica() {
+ void testOneHealthyReplica() {
Set replica = registerNodes(IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, false, 2, false);
}
@Test
- public void testTwoHealthyAndInflightAdd() {
+ void testTwoHealthyAndInflightAdd() {
Set replica = registerNodes(IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 1, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 1, 0, 3, 2);
validate(rcnt, false, 0, false);
}
- @Test
/**
* This does not schedule a container to be removed, as the inFlight add may
* fail and then the delete would make things under-replicated. Once the add
* completes there will be 4 healthy and it will get taken care of then.
*/
- public void testThreeHealthyAndInflightAdd() {
+ @Test
+ void testThreeHealthyAndInflightAdd() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 1, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 1, 0, 3, 2);
validate(rcnt, true, 0, false);
}
- @Test
/**
* As the inflight delete may fail, but as it will make the the container
* under replicated, we go ahead and schedule another replica to be added.
*/
- public void testThreeHealthyAndInflightDelete() {
+ @Test
+ void testThreeHealthyAndInflightDelete() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 1, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 1, 3, 2);
validate(rcnt, false, 1, false);
}
- @Test
/**
* This is NOT sufficiently replicated as the inflight add may fail and the
* inflight del could succeed, leaving only 2 healthy replicas.
*/
- public void testThreeHealthyAndInflightAddAndInFlightDelete() {
+ @Test
+ void testThreeHealthyAndInflightAddAndInFlightDelete() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 1, 1, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 1, 1, 3, 2);
validate(rcnt, false, 0, false);
}
@Test
- public void testFourHealthyReplicas() {
+ void testFourHealthyReplicas() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, true, -1, true);
}
@Test
- public void testFourHealthyReplicasAndInFlightDelete() {
+ void testFourHealthyReplicasAndInFlightDelete() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 1, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 1, 3, 2);
validate(rcnt, true, 0, false);
}
@Test
- public void testFourHealthyReplicasAndTwoInFlightDelete() {
+ void testFourHealthyReplicasAndTwoInFlightDelete() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 2, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 2, 3, 2);
validate(rcnt, false, 1, false);
}
@Test
- public void testOneHealthyReplicaRepFactorOne() {
+ void testOneHealthyReplicaRepFactorOne() {
Set replica = registerNodes(IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 1, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 1, 2);
validate(rcnt, true, 0, false);
}
@Test
- public void testOneHealthyReplicaRepFactorOneInFlightDelete() {
+ void testOneHealthyReplicaRepFactorOneInFlightDelete() {
Set replica = registerNodes(IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 1, 1, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 1, 1, 2);
validate(rcnt, false, 1, false);
}
@Test
- public void testTwoHealthyReplicaTwoInflightAdd() {
+ void testTwoHealthyReplicaTwoInflightAdd() {
Set replica = registerNodes(IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 2, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 2, 0, 3, 2);
validate(rcnt, false, 0, false);
}
@@ -199,70 +194,70 @@ public void testTwoHealthyReplicaTwoInflightAdd() {
*/
@Test
- public void testThreeHealthyAndTwoDecommission() {
+ void testThreeHealthyAndTwoDecommission() {
Set replica = registerNodes(IN_SERVICE, IN_SERVICE,
IN_SERVICE, DECOMMISSIONING, DECOMMISSIONING);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, true, 0, false);
}
@Test
- public void testOneDecommissionedReplica() {
+ void testOneDecommissionedReplica() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, DECOMMISSIONING);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, false, 1, false);
}
@Test
- public void testTwoHealthyOneDecommissionedneInFlightAdd() {
+ void testTwoHealthyOneDecommissionedneInFlightAdd() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, DECOMMISSIONED);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 1, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 1, 0, 3, 2);
validate(rcnt, false, 0, false);
}
@Test
- public void testAllDecommissioned() {
+ void testAllDecommissioned() {
Set replica =
registerNodes(DECOMMISSIONED, DECOMMISSIONED, DECOMMISSIONED);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, false, 3, false);
}
@Test
- public void testAllDecommissionedRepFactorOne() {
+ void testAllDecommissionedRepFactorOne() {
Set replica = registerNodes(DECOMMISSIONED);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 1, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 1, 2);
validate(rcnt, false, 1, false);
}
@Test
- public void testAllDecommissionedRepFactorOneInFlightAdd() {
+ void testAllDecommissionedRepFactorOneInFlightAdd() {
Set replica = registerNodes(DECOMMISSIONED);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 1, 0, 1, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 1, 0, 1, 2);
validate(rcnt, false, 0, false);
}
@Test
- public void testOneHealthyOneDecommissioningRepFactorOne() {
+ void testOneHealthyOneDecommissioningRepFactorOne() {
Set replica = registerNodes(DECOMMISSIONED, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 1, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 1, 2);
validate(rcnt, true, 0, false);
}
@@ -271,136 +266,136 @@ public void testOneHealthyOneDecommissioningRepFactorOne() {
*/
@Test
- public void testOneHealthyTwoMaintenanceMinRepOfTwo() {
+ void testOneHealthyTwoMaintenanceMinRepOfTwo() {
Set replica =
registerNodes(IN_SERVICE, IN_MAINTENANCE, IN_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, false, 1, false);
}
@Test
- public void testOneHealthyThreeMaintenanceMinRepOfTwo() {
+ void testOneHealthyThreeMaintenanceMinRepOfTwo() {
Set replica = registerNodes(IN_SERVICE,
IN_MAINTENANCE, IN_MAINTENANCE, ENTERING_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, false, 1, false);
}
@Test
- public void testOneHealthyTwoMaintenanceMinRepOfOne() {
+ void testOneHealthyTwoMaintenanceMinRepOfOne() {
Set replica =
registerNodes(IN_SERVICE, IN_MAINTENANCE, ENTERING_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 1);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 1);
validate(rcnt, true, 0, false);
}
@Test
- public void testOneHealthyThreeMaintenanceMinRepOfTwoInFlightAdd() {
+ void testOneHealthyThreeMaintenanceMinRepOfTwoInFlightAdd() {
Set replica = registerNodes(IN_SERVICE,
IN_MAINTENANCE, ENTERING_MAINTENANCE, IN_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 1, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 1, 0, 3, 2);
validate(rcnt, false, 0, false);
}
@Test
- public void testAllMaintenance() {
+ void testAllMaintenance() {
Set replica =
registerNodes(IN_MAINTENANCE, ENTERING_MAINTENANCE, IN_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, false, 2, false);
}
- @Test
/**
* As we have exactly 3 healthy, but then an excess of maintenance copies
* we ignore the over-replication caused by the maintenance copies until they
* come back online, and then deal with them.
*/
- public void testThreeHealthyTwoInMaintenance() {
+ @Test
+ void testThreeHealthyTwoInMaintenance() {
Set replica = registerNodes(IN_SERVICE, IN_SERVICE,
IN_SERVICE, IN_MAINTENANCE, ENTERING_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, true, 0, false);
}
- @Test
/**
* This is somewhat similar to testThreeHealthyTwoInMaintenance() except now
* one of the maintenance copies has become healthy and we will need to remove
* the over-replicated healthy container.
*/
- public void testFourHealthyOneInMaintenance() {
+ @Test
+ void testFourHealthyOneInMaintenance() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE, IN_SERVICE,
IN_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
validate(rcnt, true, -1, true);
}
@Test
- public void testOneMaintenanceMinRepOfTwoRepFactorOne() {
+ void testOneMaintenanceMinRepOfTwoRepFactorOne() {
Set replica = registerNodes(IN_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 1, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 1, 2);
validate(rcnt, false, 1, false);
}
@Test
- public void testOneMaintenanceMinRepOfTwoRepFactorOneInFlightAdd() {
+ void testOneMaintenanceMinRepOfTwoRepFactorOneInFlightAdd() {
Set replica = registerNodes(IN_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 1, 0, 1, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 1, 0, 1, 2);
validate(rcnt, false, 0, false);
}
@Test
- public void testOneHealthyOneMaintenanceRepFactorOne() {
+ void testOneHealthyOneMaintenanceRepFactorOne() {
Set replica = registerNodes(IN_MAINTENANCE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 1, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 1, 2);
validate(rcnt, true, 0, false);
}
@Test
- public void testTwoDecomTwoMaintenanceOneInflightAdd() {
+ void testTwoDecomTwoMaintenanceOneInflightAdd() {
Set replica =
registerNodes(DECOMMISSIONED, DECOMMISSIONING,
IN_MAINTENANCE, ENTERING_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 1, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 1, 0, 3, 2);
validate(rcnt, false, 1, false);
}
@Test
- public void testHealthyContainerIsHealthy() {
+ void testHealthyContainerIsHealthy() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
assertTrue(rcnt.isHealthy());
}
@Test
- public void testIsHealthyWithDifferentReplicaStateNotHealthy() {
+ void testIsHealthyWithDifferentReplicaStateNotHealthy() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_SERVICE);
for (ContainerReplica r : replica) {
@@ -418,33 +413,33 @@ public void testIsHealthyWithDifferentReplicaStateNotHealthy() {
break;
}
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
assertFalse(rcnt.isHealthy());
}
@Test
- public void testIsHealthyWithMaintReplicaIsHealthy() {
+ void testIsHealthyWithMaintReplicaIsHealthy() {
Set replica =
registerNodes(IN_SERVICE, IN_SERVICE, IN_MAINTENANCE,
ENTERING_MAINTENANCE);
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
assertTrue(rcnt.isHealthy());
}
@Test
- public void testContainerWithNoReplicasIsMissing() {
+ void testContainerWithNoReplicasIsMissing() {
Set replica = new HashSet<>();
ContainerInfo container = createContainer(HddsProtos.LifeCycleState.CLOSED);
- ContainerReplicaCount rcnt =
- new ContainerReplicaCount(container, replica, 0, 0, 3, 2);
- assertTrue(rcnt.isMissing());
+ RatisContainerReplicaCount rcnt =
+ new RatisContainerReplicaCount(container, replica, 0, 0, 3, 2);
+ assertTrue(rcnt.isUnrecoverable());
assertFalse(rcnt.isSufficientlyReplicated());
}
- private void validate(ContainerReplicaCount rcnt,
+ private void validate(RatisContainerReplicaCount rcnt,
boolean sufficientlyReplicated, int replicaDelta,
boolean overReplicated) {
assertEquals(sufficientlyReplicated, rcnt.isSufficientlyReplicated());
diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/node/TestDatanodeAdminMonitor.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/node/TestDatanodeAdminMonitor.java
index 2f7c1c603d01..15f62c3aa385 100644
--- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/node/TestDatanodeAdminMonitor.java
+++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/node/TestDatanodeAdminMonitor.java
@@ -24,6 +24,7 @@
import org.apache.hadoop.hdds.protocol.proto
.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto;
import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.RatisContainerReplicaCount;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.ContainerNotFoundException;
import org.apache.hadoop.hdds.scm.container.ContainerReplica;
@@ -453,7 +454,7 @@ private ContainerReplicaCount generateReplicaCount(ContainerID containerID,
.setState(containerState)
.build();
- return new ContainerReplicaCount(container, replicas, 0, 0, 3, 2);
+ return new RatisContainerReplicaCount(container, replicas, 0, 0, 3, 2);
}
/**