rakeshadr commented on code in PR #10157:
URL: https://github.com/apache/ozone/pull/10157#discussion_r3432818600
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/BackgroundPipelineCreator.java:
##########
@@ -255,6 +236,59 @@ private void createPipelines() throws RuntimeException {
LOG.debug("BackgroundPipelineCreator createPipelines finished.");
}
+ @VisibleForTesting
+ List<ReplicationConfig> getReplicationConfigs(boolean autoCreateFactorOne) {
Review Comment:
can you add javadoc describing the behavior
##########
hadoop-hdds/common/src/main/resources/ozone-default.xml:
##########
@@ -1700,6 +1710,15 @@
If enabled, SCM will auto create RATIS factor ONE pipeline.
</description>
</property>
+ <property>
+ <name>ozone.scm.pipeline.creation.ec.ratis.three.enabled</name>
Review Comment:
_One suggestion to make this generic config:_
Config keys should name the feature, not the exception condition. The
description is the right place for "when does this apply." If requires, in
future we can leverage safemode rule tied to RATIS/THREE pipeline availability.
Means, we can reuse this config directly in RATIS/THREE pipeline creation &
reads cleanly from this single flag rather than deriving it from EC default
config.
```
<name>ozone.scm.pipeline.creation.ratis.three</name>
<value>true</value>
<tag>OZONE, SCM, PIPELINE</tag>
<description>
When true, SCM creates RATIS/THREE pipelines in the background and
requires them during safemode. Applies only when the cluster default
replication (ozone.replication.type) is EC. For RATIS-default clusters
this flag has no effect.
</description>
```
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/safemode/TestSafeModeRuleFactory.java:
##########
@@ -56,7 +56,7 @@ public void testLoadedSafeModeRules() {
// as the rules are hardcoded in SafeModeRuleFactory.
Review Comment:
Can we add a few more tests to improve maintainability.
Note: generated via LLM please validate before adding.
```
@Test
public void testIllegalState() {
resetInstance();
assertThrows(IllegalStateException.class,
SafeModeRuleFactory::getInstance);
}
// EC-default + flag=false: HealthyPipeline and OneReplica rules are
skipped.
// Expected rules: RatisContainer, ECContainer, DataNode, ECMinDataNode =
4.
@Test
public void testRuleCountForEcDefaultWithRatisThreeFlagDisabled() {
resetInstance();
SCMSafeModeManager safeModeManager = mock(SCMSafeModeManager.class);
when(safeModeManager.getSafeModeMetrics()).thenReturn(mock(SafeModeMetrics.class));
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(HddsConfigKeys.HDDS_SCM_SAFEMODE_RULE_REFRESH_INTERVAL, "0s");
conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
HddsProtos.ReplicationType.EC.name());
conf.set(OzoneConfigKeys.OZONE_REPLICATION, "rs-3-2-1024k");
conf.setBoolean(ScmConfigKeys.OZONE_SCM_EC_PIPELINE_CREATE_RATIS_THREE,
false);
SafeModeRuleFactory.initialize(conf, SCMContext.emptyContext(), new
EventQueue(),
mock(PipelineManager.class), mock(ContainerManager.class),
mock(NodeManager.class));
SafeModeRuleFactory factory = SafeModeRuleFactory.getInstance();
factory.addSafeModeManager(safeModeManager);
assertEquals(4, factory.getSafeModeRules().size(),
"EC-default with flag=false should have 4 rules (no RATIS/THREE
pipeline rules)");
}
// EC-default + flag=true: RATIS/THREE pipeline rules are included.
// Expected rules: RatisContainer, ECContainer, DataNode, ECMinDataNode,
// HealthyPipeline, OneReplica = 6.
@Test
public void testRuleCountForEcDefaultWithRatisThreeFlagEnabled() {
resetInstance();
SCMSafeModeManager safeModeManager = mock(SCMSafeModeManager.class);
when(safeModeManager.getSafeModeMetrics()).thenReturn(mock(SafeModeMetrics.class));
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(HddsConfigKeys.HDDS_SCM_SAFEMODE_RULE_REFRESH_INTERVAL, "0s");
conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
HddsProtos.ReplicationType.EC.name());
conf.set(OzoneConfigKeys.OZONE_REPLICATION, "rs-3-2-1024k");
conf.setBoolean(ScmConfigKeys.OZONE_SCM_EC_PIPELINE_CREATE_RATIS_THREE,
true);
SafeModeRuleFactory.initialize(conf, SCMContext.emptyContext(), new
EventQueue(),
mock(PipelineManager.class), mock(ContainerManager.class),
mock(NodeManager.class));
SafeModeRuleFactory factory = SafeModeRuleFactory.getInstance();
factory.addSafeModeManager(safeModeManager);
assertEquals(6, factory.getSafeModeRules().size(),
"EC-default with flag=true should have 6 rules (RATIS/THREE pipeline
rules included)");
}
private static void resetInstance() {
try {
Field instance =
SafeModeRuleFactory.class.getDeclaredField("instance");
instance.setAccessible(true);
instance.set(null, null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
```
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/safemode/TestECMinDataNodeSafeModeRule.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.safemode;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.node.NodeManager;
+import org.apache.hadoop.hdds.server.events.EventQueue;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for {@link ECMinDataNodeSafeModeRule}.
+ */
+public class TestECMinDataNodeSafeModeRule {
+
+ @Test
+ public void testDisabledForNonEcDefault() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
+ HddsProtos.ReplicationType.RATIS.name());
+
+ NodeManager nodeManager = mock(NodeManager.class);
+ SCMSafeModeManager safeModeManager = mock(SCMSafeModeManager.class);
+
when(safeModeManager.getSafeModeMetrics()).thenReturn(mock(SafeModeMetrics.class));
+
+ ECMinDataNodeSafeModeRule rule = new ECMinDataNodeSafeModeRule(
+ new EventQueue(), conf, nodeManager, safeModeManager);
+
+ assertFalse(rule.isEnabled());
+ assertTrue(rule.validate());
+ }
+
+ @Test
+ public void testEnabledForEcDefaultAndUsesRequiredNodeCount() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
+ HddsProtos.ReplicationType.EC.name());
+ conf.set(OzoneConfigKeys.OZONE_REPLICATION, "rs-3-2-1024k");
+
+ List<DatanodeDetails> enoughDns = new ArrayList<>();
+ List<DatanodeDetails> insufficientDns = new ArrayList<>();
+ for (int i = 0; i < 5; i++) {
+ enoughDns.add(mock(DatanodeDetails.class));
+ if (i < 4) {
+ insufficientDns.add(mock(DatanodeDetails.class));
+ }
+ }
+
+ NodeManager nodeManager = mock(NodeManager.class);
+ when(nodeManager.getNodes(any())).thenReturn(enoughDns, insufficientDns);
+ SCMSafeModeManager safeModeManager = mock(SCMSafeModeManager.class);
+
when(safeModeManager.getSafeModeMetrics()).thenReturn(mock(SafeModeMetrics.class));
+
+ ECMinDataNodeSafeModeRule rule = new ECMinDataNodeSafeModeRule(
+ new EventQueue(), conf, nodeManager, safeModeManager);
+ rule.setValidateBasedOnReportProcessing(false);
+
+ assertTrue(rule.isEnabled());
+ assertTrue(rule.validate());
+ assertFalse(rule.validate());
+ }
Review Comment:
Can we add a few more tests to improve maintainability.
Note: generated via LLM please validate before adding.
```
// rs-3-2 requires 5 nodes; fire 5 healthy DN registration events and
// verify the rule satisfies via the event-driven (report processing) path.
@Test
public void testProcessCountsHealthyDnsAndValidates()
throws NodeNotFoundException, InterruptedException {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
HddsProtos.ReplicationType.EC.name());
conf.set(OzoneConfigKeys.OZONE_REPLICATION, "rs-3-2-1024k");
NodeManager nodeManager = mock(NodeManager.class);
when(nodeManager.getNodeStatus(any(DatanodeDetails.class)))
.thenReturn(NodeStatus.inServiceHealthy());
SCMSafeModeManager safeModeManager = mock(SCMSafeModeManager.class);
when(safeModeManager.getSafeModeMetrics()).thenReturn(mock(SafeModeMetrics.class));
when(safeModeManager.getInSafeMode()).thenReturn(true);
EventQueue eventQueue = new EventQueue();
ECMinDataNodeSafeModeRule rule = new ECMinDataNodeSafeModeRule(
eventQueue, conf, nodeManager, safeModeManager);
// Leave validateBasedOnReportProcessing=true (default) to use process()
path.
assertFalse(rule.validate());
assertEquals(0, rule.getRegisteredDns());
for (int i = 0; i < 5; i++) {
DatanodeDetails dn = MockDatanodeDetails.randomDatanodeDetails();
eventQueue.fireEvent(SCMEvents.NODE_REGISTRATION_CONT_REPORT,
new NodeRegistrationContainerReport(dn, null));
}
GenericTestUtils.waitFor(() -> rule.getRegisteredDns() == 5, 100, 5000);
assertTrue(rule.validate());
}
// An unhealthy DN registration event must not increment the count.
@Test
public void testProcessSkipsUnhealthyDn()
throws NodeNotFoundException, InterruptedException {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
HddsProtos.ReplicationType.EC.name());
conf.set(OzoneConfigKeys.OZONE_REPLICATION, "rs-3-2-1024k");
NodeManager nodeManager = mock(NodeManager.class);
// Return stale (not inServiceHealthy) for every DN.
when(nodeManager.getNodeStatus(any(DatanodeDetails.class)))
.thenReturn(NodeStatus.inServiceStale());
SCMSafeModeManager safeModeManager = mock(SCMSafeModeManager.class);
when(safeModeManager.getSafeModeMetrics()).thenReturn(mock(SafeModeMetrics.class));
when(safeModeManager.getInSafeMode()).thenReturn(true);
EventQueue eventQueue = new EventQueue();
ECMinDataNodeSafeModeRule rule = new ECMinDataNodeSafeModeRule(
eventQueue, conf, nodeManager, safeModeManager);
DatanodeDetails dn = MockDatanodeDetails.randomDatanodeDetails();
eventQueue.fireEvent(SCMEvents.NODE_REGISTRATION_CONT_REPORT,
new NodeRegistrationContainerReport(dn, null));
// Give the event queue time to process; count must stay 0.
Thread.sleep(500);
assertEquals(0, rule.getRegisteredDns());
assertFalse(rule.validate());
}
// Firing the same DN twice must only count it once.
@Test
public void testProcessDeduplicatesSameDn()
throws NodeNotFoundException, InterruptedException {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
HddsProtos.ReplicationType.EC.name());
conf.set(OzoneConfigKeys.OZONE_REPLICATION, "rs-3-2-1024k");
NodeManager nodeManager = mock(NodeManager.class);
when(nodeManager.getNodeStatus(any(DatanodeDetails.class)))
.thenReturn(NodeStatus.inServiceHealthy());
SCMSafeModeManager safeModeManager = mock(SCMSafeModeManager.class);
when(safeModeManager.getSafeModeMetrics()).thenReturn(mock(SafeModeMetrics.class));
when(safeModeManager.getInSafeMode()).thenReturn(true);
EventQueue eventQueue = new EventQueue();
ECMinDataNodeSafeModeRule rule = new ECMinDataNodeSafeModeRule(
eventQueue, conf, nodeManager, safeModeManager);
DatanodeDetails dn = MockDatanodeDetails.randomDatanodeDetails();
NodeRegistrationContainerReport report = new
NodeRegistrationContainerReport(dn, null);
eventQueue.fireEvent(SCMEvents.NODE_REGISTRATION_CONT_REPORT, report);
eventQueue.fireEvent(SCMEvents.NODE_REGISTRATION_CONT_REPORT, report);
GenericTestUtils.waitFor(() -> rule.getRegisteredDns() > 0, 100, 5000);
Thread.sleep(300);
assertEquals(1, rule.getRegisteredDns());
}
```
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/BackgroundPipelineCreator.java:
##########
@@ -255,6 +236,59 @@ private void createPipelines() throws RuntimeException {
LOG.debug("BackgroundPipelineCreator createPipelines finished.");
}
+ @VisibleForTesting
+ List<ReplicationConfig> getReplicationConfigs(boolean autoCreateFactorOne) {
+ List<ReplicationConfig> list = new ArrayList<>();
+ ReplicationConfig defaultReplicationConfig = getDefaultReplicationConfig();
+ if (defaultReplicationConfig == null) {
+ LOG.warn("Skipping background pipeline creation: default replication "
+ + "config is invalid.");
+ return list;
+ }
+ // TODO: #CLUTIL Different replication factor may need to be supported
+ HddsProtos.ReplicationType type =
+ defaultReplicationConfig.getReplicationType();
+ if (type == EC) {
Review Comment:
can you make it single statement instead of nested ifs.
`if (type == EC && createRatisThreeForEcDefault) {`
--
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]