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

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


The following commit(s) were added to refs/heads/master by this push:
     new 82ea622e168 [fix](doris compose) fix wait master fe ip 10s for ls 
command (#46387)
82ea622e168 is described below

commit 82ea622e168dbee262e6df6853eaa96ffe6ac88f
Author: yujun <[email protected]>
AuthorDate: Mon Jan 6 12:02:07 2025 +0800

    [fix](doris compose) fix wait master fe ip 10s for ls command (#46387)
    
    ### What problem does this PR solve?
    
    For ls command without a cluster name arg, it will list all clusters'
    information. For each cluster, it will need to get the master fe ip. And
    if the cluster path had been deleted or this cluster is not located in
    LOCAL_DORIS_PATH, then it can't found the master_fe_ip file, then it
    will wait this cluster for 10s.
---
 docker/runtime/doris-compose/cluster.py  | 23 +++++++++++++++--------
 docker/runtime/doris-compose/command.py  |  5 +++--
 docker/runtime/doris-compose/database.py |  8 ++++++--
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/docker/runtime/doris-compose/cluster.py 
b/docker/runtime/doris-compose/cluster.py
index f4522181d4b..d3b08d71226 100644
--- a/docker/runtime/doris-compose/cluster.py
+++ b/docker/runtime/doris-compose/cluster.py
@@ -138,14 +138,21 @@ def gen_subnet_prefix16():
     raise Exception("Failed to gen subnet")
 
 
-def get_master_fe_endpoint(cluster_name):
-    master_fe_ip_file = get_cluster_path(cluster_name) + "/status/master_fe_ip"
-    max_retries = 10
-    for attempt in range(max_retries):
-        if os.path.exists(master_fe_ip_file):
-            with open(master_fe_ip_file, "r") as f:
-                return "{}:{}".format(f.read().strip(), FE_QUERY_PORT)
-        time.sleep(1)
+def get_master_fe_endpoint(cluster_name, wait_master_fe_ip_file=False):
+    cluster_path = get_cluster_path(cluster_name)
+    if os.path.exists(cluster_path):
+        master_fe_ip_file = "{}/status/master_fe_ip".format(cluster_path)
+        max_retries = 10 if wait_master_fe_ip_file else 0
+        i = 0
+        while True:
+            if os.path.exists(master_fe_ip_file):
+                with open(master_fe_ip_file, "r") as f:
+                    return "{}:{}".format(f.read().strip(), FE_QUERY_PORT)
+            i += 1
+            if i < max_retries:
+                time.sleep(1)
+            else:
+                break
     try:
         cluster = Cluster.load(cluster_name)
         LOG.info("master file not exist, master ip get from node 1")
diff --git a/docker/runtime/doris-compose/command.py 
b/docker/runtime/doris-compose/command.py
index df3d47cabd9..150162ff074 100644
--- a/docker/runtime/doris-compose/command.py
+++ b/docker/runtime/doris-compose/command.py
@@ -626,7 +626,7 @@ class UpCommand(Command):
             if cluster.is_cloud and args.sql_mode_node_mgr:
                 db_mgr = database.get_db_mgr(args.NAME, False)
                 master_fe_endpoint = CLUSTER.get_master_fe_endpoint(
-                    cluster.name)
+                    cluster.name, True)
                 # Add FEs except master_fe
                 for fe in cluster.get_all_nodes(CLUSTER.Node.TYPE_FE):
                     fe_endpoint = f"{fe.get_ip()}:{CLUSTER.FE_EDITLOG_PORT}"
@@ -1071,7 +1071,8 @@ class ListCommand(Command):
                 if services is None:
                     return COMPOSE_BAD, {}
                 return COMPOSE_GOOD, {
-                    service: ComposeService(
+                    service:
+                    ComposeService(
                         service,
                         list(service_conf["networks"].values())[0]
                         ["ipv4_address"], service_conf["image"])
diff --git a/docker/runtime/doris-compose/database.py 
b/docker/runtime/doris-compose/database.py
index 370f1d5ee2a..9c0b2f66f83 100644
--- a/docker/runtime/doris-compose/database.py
+++ b/docker/runtime/doris-compose/database.py
@@ -233,11 +233,15 @@ class DBManager(object):
                     cursor.execute(sql)
                     fields = [field_md[0] for field_md in cursor.description
                               ] if cursor.description else []
-                    return [dict(zip(fields, row)) for row in 
cursor.fetchall()]
+                    return [
+                        dict(zip(fields, row)) for row in cursor.fetchall()
+                    ]
             except Exception as e:
                 LOG.warn(f"Error occurred: {e}")
                 if "timed out" in str(e).lower() and attempt < retries - 1:
-                    LOG.warn(f"Query timed out. Retrying {attempt + 
1}/{retries}...")
+                    LOG.warn(
+                        f"Query timed out. Retrying {attempt + 1}/{retries}..."
+                    )
                     self._reset_conn()
                 else:
                     raise e


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to