hani-fouladgar commented on code in PR #11218:
URL: https://github.com/apache/ozone/pull/11218#discussion_r4048390954


##########
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:
   Done!



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