chihsuan commented on code in PR #11218:
URL: https://github.com/apache/ozone/pull/11218#discussion_r4047742585
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -5764,6 +5769,48 @@ public ListSnapshotDiffJobResponse listSnapshotDiffJobs(
}
}
+ /**
+ * Reload the block and container SCM failover proxies after the SCM node
list
+ * ({@code ozone.scm.nodes.<serviceId>}) is reconfigured, so the OM can
reach a
+ * newly added SCM without a restart. The per-node address keys
+ * ({@code ozone.scm.address.<serviceId>.<nodeId>}) must already be present
for
+ * the involved nodes.
+ *
+ * Scope: only the block and container proxies are reloaded here. Changing an
+ * address key alone does not trigger a reload; touch the node list to apply
Review Comment:
Thanks for the fix! I tried the defer path. With the address key missing,
status still says SUCCESS but the providers keep the old list. The live conf
also keeps a node without an address, so `getServiceList()` starts throwing.
Could we throw here instead, like the datanode side, so it shows FAILED and can
be retried?
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -5764,6 +5770,75 @@ public ListSnapshotDiffJobResponse listSnapshotDiffJobs(
}
}
+ /**
+ * Validate and publish a reconfigured SCM node list
+ * ({@code ozone.scm.nodes.<serviceId>}) and reload the block and container
SCM
+ * failover proxies so the OM can reach a newly added SCM without a restart.
+ *
+ * <p>The reload reads the node list and the per-node address keys
+ * ({@code ozone.scm.address.<serviceId>.<nodeId>}) from the same live
+ * configuration. If the node list is reconfigured before a newly added SCM's
+ * address, the reload here cannot resolve that node and is deferred: the new
+ * list is kept and {@link #reloadScmProxiesOnReconfig} reloads once the
whole
+ * reconfiguration batch (including the address key) has been applied, so a
+ * single {@code reconfig start} adds the node regardless of key order.
+ *
+ * <p>Scope: only the block and container proxies are reloaded. The
secure-mode
+ * SCM security and secret-key proxy providers are not reloaded and continue
to
+ * use the node list captured at startup.
+ */
+ private String reconfScmNodes(String value) {
+ if (StringUtils.isBlank(value)) {
+ throw new IllegalArgumentException("Reconfiguration failed since setting
an empty SCM nodes "
+ + "configuration is not allowed");
+ }
+ // ReconfigurableBase stores the new value into the configuration only
after
+ // this callback returns, but reloadScmNodes() rebuilds the SCM proxies
from
+ // that same live configuration. Publish the new node list first so the
+ // reload sees the intended membership.
+ String scmNodesKey = ConfUtils.addKeySuffixes(OZONE_SCM_NODES_KEY,
+ HddsUtils.getScmServiceId(configuration));
+ configuration.set(scmNodesKey, value);
+ try {
+ scmClient.reloadScmNodes();
+ LOG.info("Reloaded SCM proxy configuration for {} : {}",
OZONE_SCM_NODES_KEY, value);
+ } catch (ConfigurationException e) {
+ // A newly added SCM's address key is not set yet. Keep the new node list
+ // and let reloadScmProxiesOnReconfig complete the reload once the
address
+ // key is also applied, rather than rolling back and forcing a second
pass.
+ LOG.info("Deferring SCM proxy reload for {} until the reconfiguration
batch completes "
+ + "(a referenced SCM address is not set yet): {}", scmNodesKey,
e.getMessage());
+ }
+ return value;
+ }
+
+ /**
+ * Reconfiguration-complete callback that reloads the block and container SCM
+ * failover proxies once a batch that touched the SCM node list or any
per-node
+ * SCM address has been fully applied. Because it runs after every property
in
+ * the batch is stored, an address-only change takes effect (the per-property
+ * path only fires for the node list), and a node added with its address key
+ * listed before or after the node list is picked up in a single
reconfiguration.
+ */
+ @VisibleForTesting
+ public void reloadScmProxiesOnReconfig(Map<String, Boolean>
changedProperties,
+ Configuration newConf) {
+ String scmServiceId = HddsUtils.getScmServiceId(configuration);
+ if (scmServiceId == null || scmClient == null) {
+ return;
+ }
+ String scmNodesKey = ConfUtils.addKeySuffixes(OZONE_SCM_NODES_KEY,
scmServiceId);
+ String scmAddressPrefix =
+ ConfUtils.addKeySuffixes(OZONE_SCM_ADDRESS_KEY, scmServiceId) + ".";
+ boolean scmProxyKeyChanged = changedProperties.keySet().stream()
+ .anyMatch(key -> key.equals(scmNodesKey) ||
key.startsWith(scmAddressPrefix));
+ if (scmProxyKeyChanged) {
+ scmClient.reloadScmNodes();
Review Comment:
Should we catch and log here? If the reload throws, the remaining complete
callbacks (tracing, logging) are skipped.
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestOmSCMNodesReconfiguration.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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;
+
+import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_ADDRESS_KEY;
+import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_NODES_KEY;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.hadoop.conf.ReconfigurationException;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.conf.ReconfigurationHandler;
+import org.apache.hadoop.hdds.scm.proxy.SCMProxyInfo;
+import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
+import org.apache.hadoop.ozone.ha.ConfUtils;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.ScmClient;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+/**
+ * Test the OM's SCM nodes reconfiguration wiring: the SCM node list and the
+ * per-node SCM addresses must be reconfigurable on a running OM so that the OM
+ * can reload its SCM failover proxies without a restart. The proxy-level
+ * add/remove behavior is covered by
+ * {@link org.apache.hadoop.hdds.scm.proxy.SCMFailoverProxyProviderBase}'s unit
+ * tests; this verifies the OM-side registration and callback end to end.
+ */
+@Timeout(300)
+public class TestOmSCMNodesReconfiguration {
+
+ private MiniOzoneHAClusterImpl cluster = null;
+ private String scmServiceId;
+
+ @BeforeEach
+ public void init() throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ scmServiceId = "scm-service-test1";
+ cluster = MiniOzoneCluster.newHABuilder(conf)
+ .setOMServiceId("om-service-test1")
+ .setSCMServiceId(scmServiceId)
+ .setNumOfStorageContainerManagers(3)
+ .setNumOfOzoneManagers(1)
+ .build();
+ cluster.waitForClusterToBeReady();
+ }
+
+ @AfterEach
+ public void shutdown() {
+ if (cluster != null) {
+ cluster.shutdown();
+ }
+ }
+
+ /**
+ * The SCM node list and each SCM's address (registered as a prefix) must be
+ * reconfigurable on the OM.
+ */
+ @Test
+ void testScmNodesAndAddressReconfigurableOnOm() throws Exception {
+ ReconfigurationHandler handler =
+ cluster.getOzoneManager().getReconfigurationHandler();
+ String scmNodesKey =
+ ConfUtils.addKeySuffixes(OZONE_SCM_NODES_KEY, scmServiceId);
+
+ assertTrue(handler.isPropertyReconfigurable(scmNodesKey));
+ assertTrue(handler.listReconfigureProperties().contains(scmNodesKey));
+
+ // The per-node SCM address keys are registered as a prefix, so any node's
+ // address key is reconfigurable even though it was not registered by name.
+ for (StorageContainerManager scm : cluster.getStorageContainerManagers()) {
+ String scmAddrKey = ConfUtils.addKeySuffixes(
+ OZONE_SCM_ADDRESS_KEY, scmServiceId, scm.getSCMNodeId());
+ assertTrue(handler.isPropertyReconfigurable(scmAddrKey));
+ }
+ }
+
+ /**
+ * Setting an empty SCM node list must be rejected, leaving the OM's SCM
+ * proxies untouched.
+ */
+ @Test
+ void testReconfigureScmNodesToBlankThrows() {
+ ReconfigurationHandler handler =
+ cluster.getOzoneManager().getReconfigurationHandler();
+ String scmNodesKey =
+ ConfUtils.addKeySuffixes(OZONE_SCM_NODES_KEY, scmServiceId);
+
+ assertThrows(ReconfigurationException.class,
+ () -> handler.reconfigureProperty(scmNodesKey, ""));
+ }
+
+ /**
+ * Reconfiguring the SCM node list on a running OM must reload the SCM
failover
+ * proxies to the new membership. Dropping one SCM from the list has to
shrink
+ * the proxy node set for both the block and container providers; the reload
+ * reads the list from the (freshly written) configuration, so reconfiguring
to
+ * a genuinely different value is what exercises the wiring.
+ */
+ @Test
+ void testReconfigureScmNodesReloadsProxies() throws Exception {
+ OzoneManager om = cluster.getOzoneManager();
+ ReconfigurationHandler handler = om.getReconfigurationHandler();
+ ScmClient scmClient = om.getScmClient();
+ String scmNodesKey =
+ ConfUtils.addKeySuffixes(OZONE_SCM_NODES_KEY, scmServiceId);
+
+ List<String> before =
+ new ArrayList<>(scmClient.getContainerProxyProvider().getSCMNodeIds());
+ assertEquals(3, before.size());
+
+ // Drop one SCM from the OM's view. Its address stays in the configuration,
+ // so the reload of the remaining nodes succeeds.
+ String dropped = before.get(before.size() - 1);
+ List<String> remaining = new ArrayList<>(before.subList(0, before.size() -
1));
+ Set<String> expected = new HashSet<>(remaining);
+
+ handler.reconfigureProperty(scmNodesKey, String.join(",", remaining));
+
+ Set<String> afterContainer =
+ new HashSet<>(scmClient.getContainerProxyProvider().getSCMNodeIds());
+ Set<String> afterBlock =
+ new HashSet<>(scmClient.getBlockProxyProvider().getSCMNodeIds());
+ assertEquals(expected, afterContainer);
+ assertEquals(expected, afterBlock);
+ assertFalse(afterContainer.contains(dropped));
+ }
+
+ /**
+ * Changing only a per-node SCM address (no node-list change) must reload the
+ * OM's SCM failover proxies against the new endpoint. The address keys are
+ * registered as a prefix with no per-key reload function, so an address-only
+ * change is applied by the reconfiguration-complete callback, not the
+ * per-property path. Drive that callback directly: the async {@code reconfig
+ * start} path reads ozone-site.xml from disk, which a mini-cluster does not
+ * rewrite, so it cannot be exercised end to end here.
+ */
+ @Test
+ void testReconfigureScmAddressReloadsProxies() throws Exception {
+ OzoneManager om = cluster.getOzoneManager();
+ ScmClient scmClient = om.getScmClient();
+ String nodeId =
+ cluster.getStorageContainerManagers().get(0).getSCMNodeId();
+ String scmAddrKey = ConfUtils.addKeySuffixes(
+ OZONE_SCM_ADDRESS_KEY, scmServiceId, nodeId);
+
+ // Point one SCM at a different resolvable address on the OM's live
+ // configuration -- the same instance the proxy providers read.
+ OzoneConfiguration conf = om.getConfiguration();
+ conf.set(scmAddrKey, "127.0.0.2");
+
+ Map<String, Boolean> changed = new HashMap<>();
+ changed.put(scmAddrKey, true);
+ om.reloadScmProxiesOnReconfig(changed, conf);
Review Comment:
Could we also cover the nodes-before-address case? `reconfigureProperty`
never fires the complete callback, so its wiring is not exercised by these
tests.
--
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]