You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by la...@apache.org on 2022/08/03 11:08:02 UTC

[incubator-pegasus] branch master updated: chore(script): Use fqdn instead of ip to generate the meta_server conf (#1085)

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

laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new f6acfceb0 chore(script): Use fqdn instead of ip to generate the meta_server conf  (#1085)
f6acfceb0 is described below

commit f6acfceb0158dd5bdf75abfd47a562bef0d12346
Author: WHBANG <38...@users.noreply.github.com>
AuthorDate: Wed Aug 3 19:07:57 2022 +0800

    chore(script): Use fqdn instead of ip to generate the meta_server conf  (#1085)
---
 docker/pegasus-docker-compose/cluster_args.sh |  2 ++
 docker/pegasus-docker-compose/prepare.sh      | 12 +++++++-----
 run.sh                                        | 16 +++++++--------
 scripts/get_local_ip.py                       | 28 ---------------------------
 src/server/config.min.ini                     |  8 ++++----
 src/test/kill_test/config.ini                 |  4 ++--
 src/test/upgrade_test/config.ini              |  2 +-
 7 files changed, 24 insertions(+), 48 deletions(-)

diff --git a/docker/pegasus-docker-compose/cluster_args.sh b/docker/pegasus-docker-compose/cluster_args.sh
index 6570138aa..65651f1f7 100755
--- a/docker/pegasus-docker-compose/cluster_args.sh
+++ b/docker/pegasus-docker-compose/cluster_args.sh
@@ -25,6 +25,8 @@
 # For exmaple, Meta1's address is 172.21.0.11:34601.
 export META_IP_PREFIX=172.21.0
 
+export META_HOSTNAME_PREFIX=onebox.pegasus.apache.test
+
 # The exported port of pegasus meta-server.
 # Please ensure this port is not occupied by other programs.
 export META_PORT=34601
diff --git a/docker/pegasus-docker-compose/prepare.sh b/docker/pegasus-docker-compose/prepare.sh
index 8aa64b059..1bc756b96 100755
--- a/docker/pegasus-docker-compose/prepare.sh
+++ b/docker/pegasus-docker-compose/prepare.sh
@@ -39,11 +39,11 @@ cp -f "${ROOT}"/config.min.ini "${DOCKER_DIR}/config.ini"
 sed -i "s/%{cluster.name}/${CLUSTER_NAME}/g" "${DOCKER_DIR}/config.ini"
 sed -i "s/allow_non_idempotent_write = false/allow_non_idempotent_write = ${IDEMPOTENT}/" "${DOCKER_DIR}/config.ini"
 for i in $(seq "${META_COUNT}"); do
-    meta_ip=${META_IP_PREFIX}.1$((i))
+    meta_fqdn=${META_HOSTNAME_PREFIX}.$((i))
     if [ "${i}" -eq 1 ]; then
-        meta_list="${meta_ip}:$META_PORT"
+        meta_list="${meta_fqdn}:$META_PORT"
     else
-        meta_list="$meta_list,${meta_ip}:$META_PORT"
+        meta_list="$meta_list,${meta_fqdn}:$META_PORT"
     fi
 done
 sed -i "s/%{meta.server.list}/$meta_list/g" "${DOCKER_DIR}/config.ini"
@@ -63,12 +63,13 @@ for i in $(seq "${META_COUNT}"); do
     command:
       - meta
     privileged: true
+    hostname: @META_HOSTNAME_PREFIX@.$((i))
     networks:
       frontend:
         ipv4_address: @META_IP_PREFIX@.1$((i))
     restart: on-failure" >> "${DOCKER_DIR}"/docker-compose.yml
-    meta_ip=$(hostname -I | cut -d' ' -f1)
-    echo "META$((i))_ADDRESS=$meta_ip:$meta_port"
+    meta_hostname=$(hostname -f | cut -d' ' -f1)
+    echo "META$((i))_ADDRESS=$meta_hostname:$meta_port"
 done
 for i in $(seq "${REPLICA_COUNT}"); do
     echo "  replica$((i)):
@@ -87,6 +88,7 @@ for i in $(seq "${REPLICA_COUNT}"); do
       frontend:" >> "${DOCKER_DIR}"/docker-compose.yml
 done
 sed -i "s/@META_IP_PREFIX@/${META_IP_PREFIX}/g" "${DOCKER_DIR}"/docker-compose.yml
+sed -i "s/@META_HOSTNAME_PREFIX@/${META_HOSTNAME_PREFIX}/g" "${DOCKER_DIR}"/docker-compose.yml
 sed -i "s/@IMAGE_NAME@/${IMAGE_NAME}/g" "${DOCKER_DIR}"/docker-compose.yml
 sed -i "s/@META_PORT@/${META_PORT}/g" "${DOCKER_DIR}"/docker-compose.yml
 
diff --git a/run.sh b/run.sh
index b482973f6..f2dce0005 100755
--- a/run.sh
+++ b/run.sh
@@ -20,7 +20,7 @@ set -e
 
 PID=$$
 ROOT=`pwd`
-LOCAL_IP=`python3 scripts/get_local_ip.py`
+LOCAL_HOSTNAME=`hostname -f`
 export REPORT_DIR="$ROOT/test_report"
 export DSN_ROOT=$ROOT/DSN_ROOT
 export THIRDPARTY_ROOT=$ROOT/thirdparty
@@ -434,7 +434,7 @@ function run_pegasus_test()
         exit 1
     fi
 
-    sed -i "s/@LOCAL_IP@/${LOCAL_IP}/g"  $ROOT/src/builder/src/server/test/config.ini
+    sed -i "s/@LOCAL_HOSTNAME@/${LOCAL_HOSTNAME}/g"  $ROOT/src/builder/src/server/test/config.ini
 
     for module in `echo $test_modules | sed 's/,/ /g'`; do
         echo "====================== run $module =========================="
@@ -723,19 +723,19 @@ function run_start_onebox()
         do
             meta_port=$((34600+i))
             if [ $i -eq 1 ]; then
-                meta_list="${LOCAL_IP}:$meta_port"
+                meta_list="${LOCAL_HOSTNAME}:$meta_port"
             else
-                meta_list="$meta_list,${LOCAL_IP}:$meta_port"
+                meta_list="$meta_list,${LOCAL_HOSTNAME}:$meta_port"
             fi
         done
         sed -i 's/%{meta.server.list}/'"$meta_list"'/g' ${ROOT}/config-server.ini
-        sed -i 's/%{zk.server.list}/'"${LOCAL_IP}"':22181/g' ${ROOT}/config-server.ini
+        sed -i 's/%{zk.server.list}/'"${LOCAL_HOSTNAME}"':22181/g' ${ROOT}/config-server.ini
         sed -i 's/app_name = .*$/app_name = '"$APP_NAME"'/' ${ROOT}/config-server.ini
         sed -i 's/partition_count = .*$/partition_count = '"$PARTITION_COUNT"'/' ${ROOT}/config-server.ini
     else
         [ -z "${CONFIG_FILE}" ] && CONFIG_FILE=${ROOT}/src/server/config.min.ini
         [ ! -f "${CONFIG_FILE}" ] && { echo "${CONFIG_FILE} is not exist"; exit 1; }
-        sed "s/@LOCAL_IP@/${LOCAL_IP}/g;s/@APP_NAME@/${APP_NAME}/g;s/@PARTITION_COUNT@/${PARTITION_COUNT}/g" \
+        sed "s/@LOCAL_HOSTNAME@/${LOCAL_HOSTNAME}/g;s/@APP_NAME@/${APP_NAME}/g;s/@PARTITION_COUNT@/${PARTITION_COUNT}/g" \
             ${CONFIG_FILE} >${ROOT}/config-server.ini
     fi
 
@@ -1234,7 +1234,7 @@ function run_start_kill_test()
     cd $ROOT
     CONFIG=config-kill-test.ini
 
-    sed "s/@LOCAL_IP@/${LOCAL_IP}/g;\
+    sed "s/@LOCAL_HOSTNAME@/${LOCAL_HOSTNAME}/g;\
 s/@META_COUNT@/${META_COUNT}/g;\
 s/@REPLICA_COUNT@/${REPLICA_COUNT}/g;\
 s/@ZK_COUNT@/1/g;s/@APP_NAME@/${APP_NAME}/g;\
@@ -1463,7 +1463,7 @@ function run_start_upgrade_test()
     cd $ROOT
     CONFIG=config-upgrade-test.ini
 
-    sed "s/@LOCAL_IP@/${LOCAL_IP}/g;\
+    sed "s/@LOCAL_HOSTNAME@/${LOCAL_HOSTNAME}/g;\
 s/@META_COUNT@/${META_COUNT}/g;\
 s/@REPLICA_COUNT@/${REPLICA_COUNT}/g;\
 s/@ZK_COUNT@/1/g;s/@APP_NAME@/${APP_NAME}/g;\
diff --git a/scripts/get_local_ip.py b/scripts/get_local_ip.py
deleted file mode 100755
index 09c034f34..000000000
--- a/scripts/get_local_ip.py
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/env python
-# 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.
-
-import socket
-
-
-def get_host_ip():
-    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
-        s.connect(('8.8.8.8', 80))
-        return s.getsockname()[0]
-
-
-print(get_host_ip())
diff --git a/src/server/config.min.ini b/src/server/config.min.ini
index 4d56d7ee9..0a5fcd6df 100644
--- a/src/server/config.min.ini
+++ b/src/server/config.min.ini
@@ -119,10 +119,10 @@
   worker_count = 4
 
 [meta_server]
-  server_list = @LOCAL_IP@:34601,@LOCAL_IP@:34602,@LOCAL_IP@:34603
-  cluster_root = /pegasus/onebox/@LOCAL_IP@
+  server_list = @LOCAL_HOSTNAME@:34601,@LOCAL_HOSTNAME@:34602,@LOCAL_HOSTNAME@:34603
+  cluster_root = /pegasus/onebox/@LOCAL_HOSTNAME@
   distributed_lock_service_type = distributed_lock_service_zookeeper
-  distributed_lock_service_parameters = /pegasus/onebox/@LOCAL_IP@
+  distributed_lock_service_parameters = /pegasus/onebox/@LOCAL_HOSTNAME@
   meta_state_service_type = meta_state_service_zookeeper
   stable_rs_min_running_seconds = 0
   server_load_balancer_type = greedy_load_balancer
@@ -162,7 +162,7 @@
   enable_detect_hotkey = false
 
 [pegasus.clusters]
-  onebox = @LOCAL_IP@:34601,@LOCAL_IP@:34602,@LOCAL_IP@:34603
+  onebox = @LOCAL_HOSTNAME@:34601,@LOCAL_HOSTNAME@:34602,@LOCAL_HOSTNAME@:34603
   onebox2 = 0.0.0.0:35601
 
 # The group of clusters participating in duplication.
diff --git a/src/test/kill_test/config.ini b/src/test/kill_test/config.ini
index 228d9bba7..765b000f9 100644
--- a/src/test/kill_test/config.ini
+++ b/src/test/kill_test/config.ini
@@ -113,6 +113,6 @@ get_thread_count = @GET_THREAD_COUNT@
 onebox_run_path = @ONEBOX_RUN_PATH@
 
 [pegasus.clusters]
-onebox = @LOCAL_IP@:34601,@LOCAL_IP@:34602,@LOCAL_IP@:34603
-mycluster = @LOCAL_IP@:34601,@LOCAL_IP@:34602,@LOCAL_IP@:34603
+onebox = @LOCAL_HOSTNAME@:34601,@LOCAL_HOSTNAME@:34602,@LOCAL_HOSTNAME@:34603
+mycluster = @LOCAL_HOSTNAME@:34601,@LOCALOCAL_HOSTNAMEL_IP@:34602,@LOCAL_HOSTNAME@:34603
 
diff --git a/src/test/upgrade_test/config.ini b/src/test/upgrade_test/config.ini
index a2d102322..ff5b99ee9 100644
--- a/src/test/upgrade_test/config.ini
+++ b/src/test/upgrade_test/config.ini
@@ -115,4 +115,4 @@ old_version_path = @OLD_VERSION_PATH@
 new_version_path = @NEW_VERSION_PATH@
 
 [pegasus.clusters]
-onebox = @LOCAL_IP@:30601,@LOCAL_IP@:30602,@LOCAL_IP@:30603
+onebox = @LOCAL_HOSTNAME@:30601,@LOCAL_HOSTNAME@:30602,@LOCAL_HOSTNAME@:30603


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org