|
24 | 24 | import com.google.common.base.Preconditions; |
25 | 25 | import com.google.common.collect.Sets; |
26 | 26 | import java.util.HashSet; |
| 27 | +import java.util.List; |
27 | 28 | import java.util.Map; |
28 | 29 | import java.util.Set; |
29 | 30 | import java.util.UUID; |
|
35 | 36 | import org.apache.hadoop.hdds.protocol.DatanodeDetails; |
36 | 37 | import org.apache.hadoop.hdds.protocol.proto.HddsProtos; |
37 | 38 | import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState; |
| 39 | +import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType; |
38 | 40 | import org.apache.hadoop.hdds.scm.container.ContainerID; |
39 | 41 | import org.apache.hadoop.hdds.scm.container.ContainerInfo; |
40 | 42 | import org.apache.hadoop.hdds.scm.container.ContainerManager; |
@@ -92,7 +94,32 @@ protected synchronized boolean validate() { |
92 | 94 | if (validateBasedOnReportProcessing()) { |
93 | 95 | return getCurrentContainerThreshold() >= safeModeCutoff; |
94 | 96 | } |
95 | | - return false; |
| 97 | + |
| 98 | + final List<ContainerInfo> containers = containerManager.getContainers( |
| 99 | + ReplicationType.EC); |
| 100 | + |
| 101 | + return containers.stream() |
| 102 | + .filter(this::isClosed) |
| 103 | + .map(ContainerInfo::containerID) |
| 104 | + .noneMatch(this::isMissing); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Checks if the container has at least the minimum required number of replicas. |
| 109 | + */ |
| 110 | + private boolean isMissing(ContainerID id) { |
| 111 | + try { |
| 112 | + int minReplica = getMinReplica(id.getId()); |
| 113 | + return containerManager.getContainerReplicas(id).size() < minReplica; |
| 114 | + } catch (ContainerNotFoundException ex) { |
| 115 | + /* |
| 116 | + * This should never happen, in case this happens the container |
| 117 | + * somehow got removed from SCM. |
| 118 | + * Safemode rule doesn't have to log/fix this. We will just exclude this |
| 119 | + * from the rule validation. |
| 120 | + */ |
| 121 | + return false; |
| 122 | + } |
96 | 123 | } |
97 | 124 |
|
98 | 125 | @VisibleForTesting |
|
0 commit comments