Copilot commented on code in PR #10157:
URL: https://github.com/apache/ozone/pull/10157#discussion_r3420602135
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/BackgroundPipelineCreator.java:
##########
@@ -204,42 +209,18 @@ private boolean skipCreation(ReplicationConfig
replicationConfig,
}
private void createPipelines() throws RuntimeException {
- // TODO: #CLUTIL Different replication factor may need to be supported
- HddsProtos.ReplicationType type = HddsProtos.ReplicationType.valueOf(
- conf.get(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
- OzoneConfigKeys.OZONE_REPLICATION_TYPE_DEFAULT));
- boolean autoCreateFactorOne = conf.getBoolean(
- ScmConfigKeys.OZONE_SCM_PIPELINE_AUTO_CREATE_FACTOR_ONE,
+ boolean autoCreateFactorOne =
conf.getBoolean(ScmConfigKeys.OZONE_SCM_PIPELINE_AUTO_CREATE_FACTOR_ONE,
ScmConfigKeys.OZONE_SCM_PIPELINE_AUTO_CREATE_FACTOR_ONE_DEFAULT);
Review Comment:
This line exceeds the project's 120 character Checkstyle limit (and similar
long key names are wrapped elsewhere in this file). Wrapping the
conf.getBoolean call avoids Checkstyle failures.
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/ECMinDataNodeSafeModeRule.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.hadoop.hdds.client.ECReplicationConfig;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.protocol.DatanodeID;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.events.SCMEvents;
+import org.apache.hadoop.hdds.scm.node.NodeManager;
+import org.apache.hadoop.hdds.scm.node.NodeStatus;
+import
org.apache.hadoop.hdds.scm.server.SCMDatanodeProtocolServer.NodeRegistrationContainerReport;
+import org.apache.hadoop.hdds.server.events.EventQueue;
+import org.apache.hadoop.hdds.server.events.TypedEvent;
+
+/**
+ * Safe mode exit rule for EC-default clusters.
+ *
+ * <p>EC pipelines are ephemeral and created on demand. This rule ensures that
+ * at least {@code data + parity} healthy DataNodes are available before SCM
+ * exits safe mode for EC-default clusters.
+ *
+ * <p>For non-EC defaults this rule is a no-op.
+ */
+public class ECMinDataNodeSafeModeRule
+ extends SafeModeExitRule<NodeRegistrationContainerReport> {
+
+ private final boolean enabled;
+ private final int requiredDns;
+ private final String ecConfigLabel;
+ private final NodeManager nodeManager;
+ private final Set<DatanodeID> registeredDnSet;
+
+ public ECMinDataNodeSafeModeRule(EventQueue eventQueue,
+ ConfigurationSource conf,
+ NodeManager nodeManager,
+ SCMSafeModeManager safeModeManager) {
+ super(safeModeManager, eventQueue);
+ this.nodeManager = nodeManager;
+
+ ReplicationConfig defaultConfig = getDefaultReplicationConfig(conf);
+ if (defaultConfig != null
+ && defaultConfig.getReplicationType() ==
HddsProtos.ReplicationType.EC) {
+ ECReplicationConfig ecConfig = (ECReplicationConfig) defaultConfig;
+ this.requiredDns = ecConfig.getRequiredNodes();
+ this.ecConfigLabel = ecConfig.configFormat();
+ this.enabled = true;
+ this.registeredDnSet = new HashSet<>(Math.max(requiredDns * 2, 1));
+ SCMSafeModeManager.getLogger().info(
+ "ECMinDataNodeSafeModeRule enabled for default EC config {}. "
+ + "Required healthy DataNodes for safemode exit: {}.",
+ ecConfigLabel, requiredDns);
+ } else {
+ this.requiredDns = 0;
+ this.ecConfigLabel = "";
+ this.enabled = false;
+ this.registeredDnSet = new HashSet<>(0);
+ SCMSafeModeManager.getLogger().debug(
+ "ECMinDataNodeSafeModeRule disabled: default replication is not
EC.");
+ }
+ }
+
+ @Override
+ protected TypedEvent<NodeRegistrationContainerReport> getEventType() {
+ return SCMEvents.NODE_REGISTRATION_CONT_REPORT;
+ }
+
+ @Override
+ protected synchronized boolean validate() {
+ if (!enabled) {
+ return true;
+ }
+ if (validateBasedOnReportProcessing()) {
+ return getRegisteredDns() >= requiredDns;
+ }
+ return nodeManager.getNodes(NodeStatus.inServiceHealthy()).size() >=
requiredDns;
+ }
Review Comment:
ECMinDataNodeSafeModeRule claims to ensure enough *healthy* DataNodes, but
when validateBasedOnReportProcessing() is true (the default), validate() only
checks how many DNs registered and does not consult NodeManager health at all.
This can allow safemode exit even if some registered nodes are not
in-service/healthy.
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestBackgroundPipelineCreator.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.pipeline;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.time.Clock;
+import java.util.List;
+import org.apache.hadoop.hdds.client.RatisReplicationConfig;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.ScmConfigKeys;
+import org.apache.hadoop.hdds.scm.ha.SCMContext;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for BackgroundPipelineCreator replication config selection.
+ */
+public class TestBackgroundPipelineCreator {
+
+ @Test
+ public void testEcDefaultReplicationWithoutRatisThreeFlagCreatesNoPipelines()
+ throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ 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);
+
+ BackgroundPipelineCreator creator = new BackgroundPipelineCreator(
+ mock(PipelineManager.class), conf, mock(SCMContext.class),
+ Clock.systemUTC());
+
+ List<ReplicationConfig> configs = creator.getReplicationConfigs(false);
+
+ assertTrue(configs.isEmpty());
+ }
+
+ @Test
+ public void testEcDefaultReplicationWithRatisThreeFlag() throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ 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);
+
+ BackgroundPipelineCreator creator = new BackgroundPipelineCreator(
+ mock(PipelineManager.class), conf, mock(SCMContext.class),
+ Clock.systemUTC());
+
+ List<ReplicationConfig> configs = creator.getReplicationConfigs(false);
+
+ assertEquals(1, configs.size());
+ assertTrue(configs.stream()
+ .anyMatch(c -> RatisReplicationConfig.hasFactor(c,
+ HddsProtos.ReplicationFactor.THREE)));
+ assertFalse(configs.stream().anyMatch(c ->
+ c.getReplicationType() == HddsProtos.ReplicationType.EC));
+ }
+
+ @Test
+ public void testRatisDefaultReplicationBehaviorUnchanged() throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
+ HddsProtos.ReplicationType.RATIS.name());
+
+ BackgroundPipelineCreator creator = new BackgroundPipelineCreator(
+ mock(PipelineManager.class), conf, mock(SCMContext.class),
+ Clock.systemUTC());
+
+ List<ReplicationConfig> configs = creator.getReplicationConfigs(false);
+
+ assertEquals(1, configs.size());
+ assertTrue(RatisReplicationConfig.hasFactor(configs.get(0),
+ HddsProtos.ReplicationFactor.THREE));
+ }
+
+ @Test
+ public void testInvalidDefaultReplicationConfigCreatesNoPipelines() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
HddsProtos.ReplicationType.RATIS.name());
+ conf.set(OzoneConfigKeys.OZONE_REPLICATION, "invalid-replication-value");
+
+ BackgroundPipelineCreator creator =
+ new BackgroundPipelineCreator(mock(PipelineManager.class), conf,
mock(SCMContext.class), Clock.systemUTC());
Review Comment:
The BackgroundPipelineCreator constructor invocation is on a single very
long line which is likely to violate Checkstyle's 120 character limit.
Splitting the arguments across lines keeps the test consistent with the rest of
the file and avoids Checkstyle failures.
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestBackgroundPipelineCreator.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.pipeline;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.time.Clock;
+import java.util.List;
+import org.apache.hadoop.hdds.client.RatisReplicationConfig;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.ScmConfigKeys;
+import org.apache.hadoop.hdds.scm.ha.SCMContext;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for BackgroundPipelineCreator replication config selection.
+ */
+public class TestBackgroundPipelineCreator {
+
+ @Test
+ public void testEcDefaultReplicationWithoutRatisThreeFlagCreatesNoPipelines()
+ throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ 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);
+
+ BackgroundPipelineCreator creator = new BackgroundPipelineCreator(
+ mock(PipelineManager.class), conf, mock(SCMContext.class),
+ Clock.systemUTC());
+
+ List<ReplicationConfig> configs = creator.getReplicationConfigs(false);
+
+ assertTrue(configs.isEmpty());
+ }
+
+ @Test
+ public void testEcDefaultReplicationWithRatisThreeFlag() throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ 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);
+
+ BackgroundPipelineCreator creator = new BackgroundPipelineCreator(
+ mock(PipelineManager.class), conf, mock(SCMContext.class),
+ Clock.systemUTC());
+
+ List<ReplicationConfig> configs = creator.getReplicationConfigs(false);
+
+ assertEquals(1, configs.size());
+ assertTrue(configs.stream()
+ .anyMatch(c -> RatisReplicationConfig.hasFactor(c,
+ HddsProtos.ReplicationFactor.THREE)));
+ assertFalse(configs.stream().anyMatch(c ->
+ c.getReplicationType() == HddsProtos.ReplicationType.EC));
+ }
+
+ @Test
+ public void testRatisDefaultReplicationBehaviorUnchanged() throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
+ HddsProtos.ReplicationType.RATIS.name());
+
+ BackgroundPipelineCreator creator = new BackgroundPipelineCreator(
+ mock(PipelineManager.class), conf, mock(SCMContext.class),
+ Clock.systemUTC());
+
+ List<ReplicationConfig> configs = creator.getReplicationConfigs(false);
+
+ assertEquals(1, configs.size());
+ assertTrue(RatisReplicationConfig.hasFactor(configs.get(0),
+ HddsProtos.ReplicationFactor.THREE));
+ }
+
+ @Test
+ public void testInvalidDefaultReplicationConfigCreatesNoPipelines() {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
HddsProtos.ReplicationType.RATIS.name());
+ conf.set(OzoneConfigKeys.OZONE_REPLICATION, "invalid-replication-value");
Review Comment:
This assignment line is over the 120 character Checkstyle limit. Please wrap
it like the other conf.set calls in this test to avoid Checkstyle failures.
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/ECMinDataNodeSafeModeRule.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.hadoop.hdds.client.ECReplicationConfig;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.protocol.DatanodeID;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.events.SCMEvents;
+import org.apache.hadoop.hdds.scm.node.NodeManager;
+import org.apache.hadoop.hdds.scm.node.NodeStatus;
+import
org.apache.hadoop.hdds.scm.server.SCMDatanodeProtocolServer.NodeRegistrationContainerReport;
+import org.apache.hadoop.hdds.server.events.EventQueue;
+import org.apache.hadoop.hdds.server.events.TypedEvent;
+
+/**
+ * Safe mode exit rule for EC-default clusters.
+ *
+ * <p>EC pipelines are ephemeral and created on demand. This rule ensures that
+ * at least {@code data + parity} healthy DataNodes are available before SCM
+ * exits safe mode for EC-default clusters.
+ *
+ * <p>For non-EC defaults this rule is a no-op.
+ */
+public class ECMinDataNodeSafeModeRule
+ extends SafeModeExitRule<NodeRegistrationContainerReport> {
+
+ private final boolean enabled;
+ private final int requiredDns;
+ private final String ecConfigLabel;
+ private final NodeManager nodeManager;
+ private final Set<DatanodeID> registeredDnSet;
+
+ public ECMinDataNodeSafeModeRule(EventQueue eventQueue,
+ ConfigurationSource conf,
+ NodeManager nodeManager,
+ SCMSafeModeManager safeModeManager) {
+ super(safeModeManager, eventQueue);
+ this.nodeManager = nodeManager;
+
+ ReplicationConfig defaultConfig = getDefaultReplicationConfig(conf);
+ if (defaultConfig != null
+ && defaultConfig.getReplicationType() ==
HddsProtos.ReplicationType.EC) {
+ ECReplicationConfig ecConfig = (ECReplicationConfig) defaultConfig;
+ this.requiredDns = ecConfig.getRequiredNodes();
+ this.ecConfigLabel = ecConfig.configFormat();
+ this.enabled = true;
+ this.registeredDnSet = new HashSet<>(Math.max(requiredDns * 2, 1));
+ SCMSafeModeManager.getLogger().info(
+ "ECMinDataNodeSafeModeRule enabled for default EC config {}. "
+ + "Required healthy DataNodes for safemode exit: {}.",
+ ecConfigLabel, requiredDns);
Review Comment:
SafeModeMetrics.numRequiredDatanodesThreshold is currently set by
DataNodeSafeModeRule (min DN config), but for EC-default clusters the actual
safemode DN requirement is data+parity (requiredDns) enforced by this rule.
Without updating the metric here, the safemode metrics can report a lower
threshold than what is actually required to exit safemode.
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/safemode/TestOneReplicaPipelineSafeModeRule.java:
##########
@@ -217,7 +216,7 @@ public void
testOneReplicaPipelineRuleWithReportProcessingFalse() {
java.util.Collections.singletonList(mock(DatanodeDetails.class))));
when(mockedPipelineManager.getPipelines(
- Mockito.any(ReplicationConfig.class),
+ Mockito.any(),
Mockito.eq(Pipeline.PipelineState.OPEN)))
Review Comment:
Using Mockito.any() without a type here makes the matcher less precise and
can mask signature/overload mismatches if PipelineManager#getPipelines changes.
Use a typed matcher to keep the test robust (without needing to re-add the
ReplicationConfig import).
--
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]