chihsuan commented on code in PR #11218:
URL: https://github.com/apache/ozone/pull/11218#discussion_r4082760498


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -6092,6 +6098,98 @@ 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.
+   *
+   * 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 new list references an SCM whose address is not set
+   * yet, the reload fails: the previous node list is restored and the 
exception
+   * is rethrown so the reconfiguration is reported FAILED and can be retried.
+   * This keeps the live configuration from holding an SCM node without a
+   * resolvable address (which would break {@code getServiceList()}). To add an
+   * SCM in a single {@code reconfig start}, set its address key together with
+   * the node list; the reconfiguration-complete callback
+   * ({@link #reloadScmProxiesOnReconfig}) applies the final membership once 
both

Review Comment:
   Could we reword this? When the node list is applied before the address, it 
is rolled back, so the callback reloads the old list. Adding a node then needs 
a second `reconfig start`. Same for the `reloadScmProxiesOnReconfig` javadoc.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -6092,6 +6098,98 @@ 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.
+   *
+   * 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 new list references an SCM whose address is not set
+   * yet, the reload fails: the previous node list is restored and the 
exception
+   * is rethrown so the reconfiguration is reported FAILED and can be retried.
+   * This keeps the live configuration from holding an SCM node without a
+   * resolvable address (which would break {@code getServiceList()}). To add an
+   * SCM in a single {@code reconfig start}, set its address key together with
+   * the node list; the reconfiguration-complete callback
+   * ({@link #reloadScmProxiesOnReconfig}) applies the final membership once 
both
+   * are stored.
+   *
+   * 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));
+    String previous = configuration.get(scmNodesKey);
+    configuration.set(scmNodesKey, value);
+    try {
+      scmClient.reloadScmNodes();
+      LOG.info("Reloaded SCM proxy configuration for {} : {}", scmNodesKey, 
value);
+    } catch (RuntimeException e) {
+      // A referenced SCM address is missing or malformed (an unset address 
throws
+      // ConfigurationException, a bad host:port throws 
IllegalArgumentException from
+      // NetUtils.createSocketAddr), so the new membership cannot be resolved. 
Restore
+      // the previous node list so the live configuration never keeps a node 
without a
+      // resolvable address, and rethrow so the reconfiguration is reported 
FAILED and
+      // can be retried once the address key is fixed.
+      if (previous == null) {
+        configuration.unset(scmNodesKey);
+      } else {
+        configuration.set(scmNodesKey, previous);
+      }
+      throw e;
+    }
+    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) {
+      try {
+        scmClient.reloadScmNodes();
+        LOG.info("Reloaded SCM failover proxies after reconfiguration of {} / 
{}*",
+            scmNodesKey, scmAddressPrefix);
+      } catch (RuntimeException e) {
+        // A complete callback must not break the chain: the remaining 
callbacks
+        // (tracing, logging) still need to run. A bad node list is already
+        // reported FAILED by reconfScmNodes; here we catch any reload failure
+        // (unset address -> ConfigurationException, malformed host:port ->
+        // IllegalArgumentException) and only log, so an address-only change 
that
+        // cannot be resolved leaves the previous proxies in place.
+        LOG.warn("Failed to reload SCM failover proxies after reconfiguration 
of {} / {}*; "
+            + "keeping the previous SCM proxy configuration", scmNodesKey, 
scmAddressPrefix, e);

Review Comment:
   Heads-up for the follow-up Jira rather than a change request. If an address 
key is unset, or set to `host:port`, the bad value stays in the live conf. 
`getServiceList()` then throws, so new clients can't reach this OM until fixed.



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestOmSCMNodesReconfiguration.java:
##########
@@ -0,0 +1,325 @@
+/*
+ * 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.SCMFailoverProxyProviderBase;
+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());

Review Comment:
   nit: Would it be worth calling `getScmInfo()` after the reload here? The 
tests only compare node ids, so a proxy that was stopped but still in use would 
not be caught.



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestOmSCMNodesReconfiguration.java:
##########
@@ -0,0 +1,283 @@
+/*
+ * 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.SCMFailoverProxyProviderBase;
+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:
   Thanks for the explanation, that makes sense. Could we still add two cases 
here? One with an unrelated key, to check no reload happens, and one with a 
malformed address, to check the failure is caught.



-- 
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]

Reply via email to