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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to