This is an automated email from the ASF dual-hosted git repository.

xxubai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/amoro.git


The following commit(s) were added to refs/heads/master by this push:
     new bbec598ae [Hotfix][AMS] Fix optimizer registration failure under 
database HA mode (#4352)
bbec598ae is described below

commit bbec598aeda42b051bbc2dce7299086cbf565f22
Author: wangxianghu <[email protected]>
AuthorDate: Fri Sep 4 12:24:20 2026 +0400

    [Hotfix][AMS] Fix optimizer registration failure under database HA mode 
(#4352)
---
 .../amoro/server/dashboard/utils/AmsUtil.java      |  6 +-
 .../amoro/server/dashboard/utils/TestAmsUtil.java  | 76 ++++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git 
a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/utils/AmsUtil.java 
b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/utils/AmsUtil.java
index fb749a66f..1388b6588 100644
--- 
a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/utils/AmsUtil.java
+++ 
b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/utils/AmsUtil.java
@@ -124,7 +124,11 @@ public class AmsUtil {
   }
 
   public static String getAMSThriftAddress(Configurations conf, String 
serviceName) {
-    if (conf.getBoolean(AmoroManagementConf.HA_ENABLE)) {
+    boolean zkHaEnabled =
+        conf.getBoolean(AmoroManagementConf.HA_ENABLE)
+            && AmoroManagementConf.HA_TYPE_ZK.equalsIgnoreCase(
+                conf.getString(AmoroManagementConf.HA_TYPE));
+    if (zkHaEnabled) {
       return String.format(
           ZOOKEEPER_ADDRESS_FORMAT,
           conf.getString(AmoroManagementConf.HA_ZOOKEEPER_ADDRESS),
diff --git 
a/amoro-ams/src/test/java/org/apache/amoro/server/dashboard/utils/TestAmsUtil.java
 
b/amoro-ams/src/test/java/org/apache/amoro/server/dashboard/utils/TestAmsUtil.java
new file mode 100644
index 000000000..0fe17e6be
--- /dev/null
+++ 
b/amoro-ams/src/test/java/org/apache/amoro/server/dashboard/utils/TestAmsUtil.java
@@ -0,0 +1,76 @@
+/*
+ * 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.amoro.server.dashboard.utils;
+
+import org.apache.amoro.Constants;
+import org.apache.amoro.config.Configurations;
+import org.apache.amoro.server.AmoroManagementConf;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestAmsUtil {
+
+  @Test
+  public void testGetAMSThriftAddressWithoutHa() {
+    Configurations conf = new Configurations();
+    conf.setBoolean(AmoroManagementConf.HA_ENABLE, false);
+    conf.setString(AmoroManagementConf.SERVER_EXPOSE_HOST, "127.0.0.1");
+    conf.set(AmoroManagementConf.TABLE_SERVICE_THRIFT_BIND_PORT, 1260);
+    conf.set(AmoroManagementConf.OPTIMIZING_SERVICE_THRIFT_BIND_PORT, 1261);
+
+    Assertions.assertEquals(
+        "thrift://127.0.0.1:1260",
+        AmsUtil.getAMSThriftAddress(conf, 
Constants.THRIFT_TABLE_SERVICE_NAME));
+    Assertions.assertEquals(
+        "thrift://127.0.0.1:1261",
+        AmsUtil.getAMSThriftAddress(conf, 
Constants.THRIFT_OPTIMIZING_SERVICE_NAME));
+  }
+
+  @Test
+  public void testGetAMSThriftAddressWithZkHa() {
+    Configurations conf = new Configurations();
+    conf.setBoolean(AmoroManagementConf.HA_ENABLE, true);
+    conf.setString(AmoroManagementConf.HA_TYPE, 
AmoroManagementConf.HA_TYPE_ZK);
+    conf.setString(AmoroManagementConf.HA_ZOOKEEPER_ADDRESS, "127.0.0.1:2181");
+    conf.setString(AmoroManagementConf.HA_CLUSTER_NAME, "test-cluster");
+
+    Assertions.assertEquals(
+        "zookeeper://127.0.0.1:2181/test-cluster",
+        AmsUtil.getAMSThriftAddress(conf, 
Constants.THRIFT_TABLE_SERVICE_NAME));
+  }
+
+  @Test
+  public void testGetAMSThriftAddressWithDatabaseHa() {
+    // HA enabled but backed by database: the thrift address must fall back to 
the direct
+    // host:port form instead of the ZooKeeper address.
+    Configurations conf = new Configurations();
+    conf.setBoolean(AmoroManagementConf.HA_ENABLE, true);
+    conf.setString(AmoroManagementConf.HA_TYPE, 
AmoroManagementConf.HA_TYPE_DATABASE);
+    conf.setString(AmoroManagementConf.SERVER_EXPOSE_HOST, "127.0.0.1");
+    conf.set(AmoroManagementConf.TABLE_SERVICE_THRIFT_BIND_PORT, 1260);
+    conf.set(AmoroManagementConf.OPTIMIZING_SERVICE_THRIFT_BIND_PORT, 1261);
+
+    Assertions.assertEquals(
+        "thrift://127.0.0.1:1260",
+        AmsUtil.getAMSThriftAddress(conf, 
Constants.THRIFT_TABLE_SERVICE_NAME));
+    Assertions.assertEquals(
+        "thrift://127.0.0.1:1261",
+        AmsUtil.getAMSThriftAddress(conf, 
Constants.THRIFT_OPTIMIZING_SERVICE_NAME));
+  }
+}

Reply via email to