You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@amoro.apache.org by "wardlican (via GitHub)" <gi...@apache.org> on 2025/11/10 07:12:44 UTC

[PR] Add a registration function for table allocation in master-slave mode. [amoro]

wardlican opened a new pull request, #3920:
URL: https://github.com/apache/amoro/pull/3920

   ## Why are the changes needed?
   The HighAvailabilityContainer adds a node registration function. In master-slave mode, each AMS node, after startup, needs to elect a master through ZooKeeper and register its own node information in ZooKeeper. Registration is done using ephemeral nodes. If a node fails, its registration information needs to be automatically deleted. The system also provides the master node with the ability to view the list of currently active nodes.
   
   Close #3919 .
   
   ## Brief change log
   Core functionalities implemented:
   
   1. Node registration:
   - In master-slave mode, AMS nodes register their information with ZooKeeper (ZK) upon startup.
   - Ephemeral sequential nodes (EPHEMERAL_SEQUENTIAL) are used, automatically cleaned up when a node exits abnormally.
   
   2. Node deregistration:
   - Nodes actively deregister from their ZK registration information when shutting down.
   
   3. Live node query:
   - The master node can query a list of all currently live nodes. In non-master or non-master-slave modes, an empty list is returned.
   
   -
   
   ## How was this patch tested?
   
   - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
   
   - [ ] Add screenshots for manual tests if appropriate
   
   - [ ] Run test locally before making a pull request
   
   ## Documentation
   
   - Does this pull request introduce a new feature? (yes / no)
   - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3920:
URL: https://github.com/apache/amoro/pull/3920#issuecomment-3510620286

   ## [Codecov](https://app.codecov.io/gh/apache/amoro/pull/3920?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `58.97436%` with `32 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 28.89%. Comparing base ([`4382d55`](https://app.codecov.io/gh/apache/amoro/commit/4382d55c542066c6a5091da8ea2eee1a90714688?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`b635c0d`](https://app.codecov.io/gh/apache/amoro/commit/b635c0dd87dc4952b05909269f728bdb79c455b7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 23 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/amoro/pull/3920?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...apache/amoro/server/HighAvailabilityContainer.java](https://app.codecov.io/gh/apache/amoro/pull/3920?src=pr&el=tree&filepath=amoro-ams%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Famoro%2Fserver%2FHighAvailabilityContainer.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-YW1vcm8tYW1zL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9hbW9yby9zZXJ2ZXIvSGlnaEF2YWlsYWJpbGl0eUNvbnRhaW5lci5qYXZh) | 67.24% | [15 Missing and 4 partials :warning: ](https://app.codecov.io/gh/apache/amoro/pull/3920?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...org/apache/amoro/server/AmoroServiceContainer.java](https://app.codecov.io/gh/apache/amoro/pull/3920?src=pr&el=tree&filepath=amoro-ams%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Famoro%2Fserver%2FAmoroServiceContainer.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-YW1vcm8tYW1zL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9hbW9yby9zZXJ2ZXIvQW1vcm9TZXJ2aWNlQ29udGFpbmVyLmphdmE=) | 14.28% | [12 Missing :warning: ](https://app.codecov.io/gh/apache/amoro/pull/3920?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...a/org/apache/amoro/properties/AmsHAProperties.java](https://app.codecov.io/gh/apache/amoro/pull/3920?src=pr&el=tree&filepath=amoro-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Famoro%2Fproperties%2FAmsHAProperties.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-YW1vcm8tY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9hbW9yby9wcm9wZXJ0aWVzL0Ftc0hBUHJvcGVydGllcy5qYXZh) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/amoro/pull/3920?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #3920      +/-   ##
   ============================================
   - Coverage     29.00%   28.89%   -0.11%     
   - Complexity     3850     3854       +4     
   ============================================
     Files           631      628       -3     
     Lines         50770    50623     -147     
     Branches       6543     6464      -79     
   ============================================
   - Hits          14724    14628      -96     
   + Misses        34989    34965      -24     
   + Partials       1057     1030      -27     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/amoro/pull/3920/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [core](https://app.codecov.io/gh/apache/amoro/pull/3920/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `28.89% <58.97%> (-0.11%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/amoro/pull/3920?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "czy006 (via GitHub)" <gi...@apache.org>.
czy006 merged PR #3920:
URL: https://github.com/apache/amoro/pull/3920


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "wardlican (via GitHub)" <gi...@apache.org>.
wardlican commented on PR #3920:
URL: https://github.com/apache/amoro/pull/3920#issuecomment-3640408337

   Please check the changes here.


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3920:
URL: https://github.com/apache/amoro/pull/3920#issuecomment-3733709906

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@amoro.apache.org list. Thank you for your contributions.


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "xxubai (via GitHub)" <gi...@apache.org>.
xxubai commented on code in PR #3920:
URL: https://github.com/apache/amoro/pull/3920#discussion_r2887969126


##########
amoro-ams/src/test/java/org/apache/amoro/server/ha/TestZkHighAvailabilityContainer.java:
##########
@@ -0,0 +1,566 @@
+/*
+ * 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.ha;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.amoro.client.AmsServerInfo;
+import org.apache.amoro.config.Configurations;
+import org.apache.amoro.properties.AmsHAProperties;
+import org.apache.amoro.server.AmoroManagementConf;
+import org.apache.amoro.shade.zookeeper3.org.apache.curator.framework.CuratorFramework;
+import org.apache.amoro.shade.zookeeper3.org.apache.curator.framework.recipes.leader.LeaderLatch;
+import org.apache.amoro.shade.zookeeper3.org.apache.zookeeper.CreateMode;
+import org.apache.amoro.shade.zookeeper3.org.apache.zookeeper.KeeperException;
+import org.apache.amoro.shade.zookeeper3.org.apache.zookeeper.data.Stat;
+import org.apache.amoro.utils.JacksonUtil;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/** Test for HighAvailabilityContainer using mocked ZK to avoid connection issues. */
+public class TestZkHighAvailabilityContainer {
+
+  private Configurations serviceConfig;
+  private HighAvailabilityContainer haContainer;
+  private MockZkState mockZkState;
+  private CuratorFramework mockZkClient;
+  private LeaderLatch mockLeaderLatch;
+
+  @Before
+  public void setUp() throws Exception {
+    mockZkState = new MockZkState();
+    mockZkClient = createMockZkClient();
+    mockLeaderLatch = createMockLeaderLatch();
+
+    // Create test configuration
+    serviceConfig = new Configurations();
+    serviceConfig.setString(AmoroManagementConf.SERVER_EXPOSE_HOST, "127.0.0.1");
+    serviceConfig.setInteger(AmoroManagementConf.TABLE_SERVICE_THRIFT_BIND_PORT, 1260);
+    serviceConfig.setInteger(AmoroManagementConf.OPTIMIZING_SERVICE_THRIFT_BIND_PORT, 1261);
+    serviceConfig.setInteger(AmoroManagementConf.HTTP_SERVER_PORT, 1630);
+    serviceConfig.setBoolean(AmoroManagementConf.HA_ENABLE, true);
+    serviceConfig.setString(AmoroManagementConf.HA_ZOOKEEPER_ADDRESS, "127.0.0.1:2181");
+    serviceConfig.setString(AmoroManagementConf.HA_CLUSTER_NAME, "test-cluster");
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    if (haContainer != null) {
+      haContainer.close();
+    }
+    mockZkState.clear();
+  }
+
+  @Test
+  public void testRegisterAndElectWithoutMasterSlaveMode() throws Exception {
+    // Test that node registration is skipped when master-slave mode is disabled
+    serviceConfig.setBoolean(AmoroManagementConf.USE_MASTER_SLAVE_MODE, false);
+    haContainer = createContainerWithMockZk();
+
+    // Should not throw exception and should not register node
+    haContainer.registerAndElect();
+
+    // Verify no node was registered
+    String nodesPath = AmsHAProperties.getNodesPath("test-cluster");
+    List<String> children = mockZkState.getChildren(nodesPath);
+    Assert.assertEquals(
+        "No nodes should be registered when master-slave mode is disabled", 0, children.size());
+  }
+
+  @Test
+  public void testRegisterAndElectWithMasterSlaveMode() throws Exception {
+    // Test that node registration works when master-slave mode is enabled
+    serviceConfig.setBoolean(AmoroManagementConf.USE_MASTER_SLAVE_MODE, true);
+    haContainer = createContainerWithMockZk();
+
+    // Register node
+    haContainer.registerAndElect();
+
+    // Verify node was registered
+    String nodesPath = AmsHAProperties.getNodesPath("test-cluster");
+    List<String> children = mockZkState.getChildren(nodesPath);
+    Assert.assertEquals("One node should be registered", 1, children.size());
+
+    // Verify node data
+    String nodePath = nodesPath + "/" + children.get(0);
+    byte[] data = mockZkState.getData(nodePath);
+    Assert.assertNotNull("Node data should not be null", data);
+    Assert.assertTrue("Node data should not be empty", data.length > 0);
+
+    // Verify node info
+    String nodeInfoJson = new String(data, StandardCharsets.UTF_8);
+    AmsServerInfo nodeInfo = JacksonUtil.parseObject(nodeInfoJson, AmsServerInfo.class);
+    Assert.assertEquals("Host should match", "127.0.0.1", nodeInfo.getHost());
+    Assert.assertEquals(
+        "Thrift port should match", Integer.valueOf(1260), nodeInfo.getThriftBindPort());

Review Comment:
   ```suggestion
           "Thrift port should match", Integer.valueOf(1261), nodeInfo.getThriftBindPort());
   ```



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3920:
URL: https://github.com/apache/amoro/pull/3920#issuecomment-3639439238

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@amoro.apache.org list. Thank you for your contributions.


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "wardlican (via GitHub)" <gi...@apache.org>.
wardlican commented on PR #3920:
URL: https://github.com/apache/amoro/pull/3920#issuecomment-3753063190

   @zhoujinsong Please help with the CR .


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "xxubai (via GitHub)" <gi...@apache.org>.
xxubai commented on code in PR #3920:
URL: https://github.com/apache/amoro/pull/3920#discussion_r2881874019


##########
amoro-ams/src/main/java/org/apache/amoro/server/ha/DataBaseHighAvailabilityContainer.java:
##########
@@ -135,6 +137,44 @@ public void waitFollowerShip() throws InterruptedException {
     LOG.info("Became the follower of AMS (Database lease)");
   }
 
+  @Override
+  public void registerAndElect() throws Exception {
+    boolean isMasterSlaveMode = serviceConfig.getBoolean(AmoroManagementConf.USE_MASTER_SLAVE_MODE);
+    if (!isMasterSlaveMode) {
+      LOG.debug("Master-slave mode is not enabled, skip node registration");
+      return;
+    }
+    // In master-slave mode, register node to database by writing OPTIMIZING_SERVICE info
+    // This is similar to ZK mode registering ephemeral nodes
+    long now = System.currentTimeMillis();
+    String optimizingInfoJson = JacksonUtil.toJSONString(optimizingServiceServerInfo);

Review Comment:
   The two implementations register **different** service info. Given that `AmoroServiceContainer.main()` calls `registerAndElect()` followed by `startOptimizingService()` in master-slave mode, the ZK implementation should also register `optimizingServiceServerInfo` (or both) to be consistent.
   



##########
amoro-ams/src/main/java/org/apache/amoro/server/ha/HighAvailabilityContainer.java:
##########
@@ -49,5 +53,19 @@ public interface HighAvailabilityContainer {
    *
    * @throws Exception If registration fails or participation in the primary election fails.
    */
-  void registAndElect() throws Exception;
+  void registerAndElect() throws Exception;
+
+  /**
+   * Used in master-slave mode to obtain information about all currently registered AMS nodes.
+   *
+   * @return List<AmsServerInfo>
+   */
+  List<AmsServerInfo> getAliveNodes();
+
+  /**
+   * Used to determine whether the current AMS node is the primary node.
+   *
+   * @return

Review Comment:
   nit: lack return param



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "wardlican (via GitHub)" <gi...@apache.org>.
wardlican commented on code in PR #3920:
URL: https://github.com/apache/amoro/pull/3920#discussion_r2791986596


##########
amoro-ams/src/main/java/org/apache/amoro/server/ha/DataBaseHighAvailabilityContainer.java:
##########
@@ -135,6 +137,44 @@ public void waitFollowerShip() throws InterruptedException {
     LOG.info("Became the follower of AMS (Database lease)");
   }
 
+  @Override
+  public void registAndElect() throws Exception {
+    boolean isMasterSlaveMode = serviceConfig.getBoolean(AmoroManagementConf.USE_MASTER_SLAVE_MODE);
+    if (!isMasterSlaveMode) {
+      LOG.debug("Master-slave mode is not enabled, skip node registration");
+      return;
+    }
+    // In master-slave mode, register node to database by writing OPTIMIZING_SERVICE info
+    // This is similar to ZK mode registering ephemeral nodes
+    long now = System.currentTimeMillis();
+    String optimizingInfoJson = JacksonUtil.toJSONString(optimizingServiceServerInfo);
+    try {
+      doAsIgnoreError(
+          HaLeaseMapper.class,
+          mapper -> {
+            int updated =
+                mapper.updateServerInfo(
+                    clusterName, OPTIMIZING_SERVICE, nodeId, nodeIp, optimizingInfoJson, now);
+            if (updated == 0) {
+              mapper.insertServerInfoIfAbsent(

Review Comment:
   Reasons for not requiring lease expiration times during the registration phase:
   
   1. Separation of Duties Principle: The registration phase focuses solely on establishing node identity; lease management is handled by a dedicated heartbeat mechanism.
   2. Avoid Race Conditions: Setting expiration times during registration could lead to multiple nodes simultaneously believing they have a lease.
   3. Simplified Registration Logic: The registration operation should be lightweight, avoiding complex lease status checks.
   4. Alignment with ZK Model: This design aligns with ZooKeeper's ephemeral node registration model.



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "czy006 (via GitHub)" <gi...@apache.org>.
czy006 commented on code in PR #3920:
URL: https://github.com/apache/amoro/pull/3920#discussion_r2767730101


##########
amoro-ams/src/main/java/org/apache/amoro/server/ha/DataBaseHighAvailabilityContainer.java:
##########
@@ -135,6 +137,44 @@ public void waitFollowerShip() throws InterruptedException {
     LOG.info("Became the follower of AMS (Database lease)");
   }
 
+  @Override
+  public void registAndElect() throws Exception {

Review Comment:
   method name charge to **registerAndElect**



##########
amoro-ams/src/main/java/org/apache/amoro/server/ha/DataBaseHighAvailabilityContainer.java:
##########
@@ -135,6 +137,44 @@ public void waitFollowerShip() throws InterruptedException {
     LOG.info("Became the follower of AMS (Database lease)");
   }
 
+  @Override
+  public void registAndElect() throws Exception {
+    boolean isMasterSlaveMode = serviceConfig.getBoolean(AmoroManagementConf.USE_MASTER_SLAVE_MODE);
+    if (!isMasterSlaveMode) {
+      LOG.debug("Master-slave mode is not enabled, skip node registration");
+      return;
+    }
+    // In master-slave mode, register node to database by writing OPTIMIZING_SERVICE info
+    // This is similar to ZK mode registering ephemeral nodes
+    long now = System.currentTimeMillis();
+    String optimizingInfoJson = JacksonUtil.toJSONString(optimizingServiceServerInfo);
+    try {
+      doAsIgnoreError(
+          HaLeaseMapper.class,
+          mapper -> {
+            int updated =
+                mapper.updateServerInfo(
+                    clusterName, OPTIMIZING_SERVICE, nodeId, nodeIp, optimizingInfoJson, now);
+            if (updated == 0) {
+              mapper.insertServerInfoIfAbsent(

Review Comment:
   why not need to lease_expire_ts to first register time?



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "wardlican (via GitHub)" <gi...@apache.org>.
wardlican commented on code in PR #3920:
URL: https://github.com/apache/amoro/pull/3920#discussion_r2887862123


##########
amoro-ams/src/main/java/org/apache/amoro/server/ha/DataBaseHighAvailabilityContainer.java:
##########
@@ -135,6 +137,44 @@ public void waitFollowerShip() throws InterruptedException {
     LOG.info("Became the follower of AMS (Database lease)");
   }
 
+  @Override
+  public void registerAndElect() throws Exception {
+    boolean isMasterSlaveMode = serviceConfig.getBoolean(AmoroManagementConf.USE_MASTER_SLAVE_MODE);
+    if (!isMasterSlaveMode) {
+      LOG.debug("Master-slave mode is not enabled, skip node registration");
+      return;
+    }
+    // In master-slave mode, register node to database by writing OPTIMIZING_SERVICE info
+    // This is similar to ZK mode registering ephemeral nodes
+    long now = System.currentTimeMillis();
+    String optimizingInfoJson = JacksonUtil.toJSONString(optimizingServiceServerInfo);

Review Comment:
   Okay, I'll change it so that `optimizingServiceServerInfo` is used for registration here.



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "wardlican (via GitHub)" <gi...@apache.org>.
wardlican commented on code in PR #3920:
URL: https://github.com/apache/amoro/pull/3920#discussion_r2887863970


##########
amoro-ams/src/main/java/org/apache/amoro/server/ha/HighAvailabilityContainer.java:
##########
@@ -49,5 +53,19 @@ public interface HighAvailabilityContainer {
    *
    * @throws Exception If registration fails or participation in the primary election fails.
    */
-  void registAndElect() throws Exception;
+  void registerAndElect() throws Exception;
+
+  /**
+   * Used in master-slave mode to obtain information about all currently registered AMS nodes.
+   *
+   * @return List<AmsServerInfo>
+   */
+  List<AmsServerInfo> getAliveNodes();
+
+  /**
+   * Used to determine whether the current AMS node is the primary node.
+   *
+   * @return

Review Comment:
   I will add some information about the return value description.
   
   > nit: lack return param
   
   



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "wardlican (via GitHub)" <gi...@apache.org>.
wardlican commented on code in PR #3920:
URL: https://github.com/apache/amoro/pull/3920#discussion_r2791973204


##########
amoro-ams/src/main/java/org/apache/amoro/server/ha/DataBaseHighAvailabilityContainer.java:
##########
@@ -135,6 +137,44 @@ public void waitFollowerShip() throws InterruptedException {
     LOG.info("Became the follower of AMS (Database lease)");
   }
 
+  @Override
+  public void registAndElect() throws Exception {

Review Comment:
   okay,I will change it to registerAndElect.



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a registration function for table allocation in master-slave mode. [amoro]

Posted by "wardlican (via GitHub)" <gi...@apache.org>.
wardlican closed pull request #3920: Add a registration function for table allocation in master-slave mode. 
URL: https://github.com/apache/amoro/pull/3920


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org