intelligentfu8 commented on code in PR #45208: URL: https://github.com/apache/doris/pull/45208#discussion_r1897061516
########## docker/runtime/be/resource/be_prestop.sh: ########## @@ -18,4 +18,143 @@ DORIS_ROOT=${DORIS_ROOT:-"/opt/apache-doris"} DORIS_HOME=${DORIS_ROOT}/be + +# interval time. +PROBE_INTERVAL=5 +RETRY_TIMES=10 +NEED_PRE_STOP=${NEED_PRE_STOP:-"false"} + +BE_CONFIG=$DORIS_HOME/conf/be.conf + +AUTH_PATH="/etc/basic_auth" + +DB_ADMIN_USER=${USER:-"root"} + +DB_ADMIN_PASSWD=$PASSWD + +ENV_FE_ADDR=$ENV_FE_ADDR +FE_QUERY_PORT=${FE_QUERY_PORT:-9030} + + +HEARTBEAT_PORT=9050 +MY_SELF= +MY_IP=`hostname -i` +MY_HOSTNAME=`hostname -f` + +log_stderr() +{ + echo "[`date`] $@" >&2 +} + +resolve_password_from_secret() +{ + if [[ -f "$AUTH_PATH/password" ]]; then + DB_ADMIN_PASSWD=`cat $AUTH_PATH/password` + fi + if [[ -f "$AUTH_PATH/username" ]]; then + DB_ADMIN_USER=`cat $AUTH_PATH/username` + fi +} + +parse_confval_from_conf() +{ + # a naive script to grep given confkey from fe conf file + # assume conf format: ^\s*<key>\s*=\s*<value>\s*$ + local confkey=$1 + local confvalue=`grep "\<$confkey\>" $BE_CONFIG | grep -v '^\s*#' | sed 's|^\s*'$confkey'\s*=\s*\(.*\)\s*$|\1|g'` + echo "$confvalue" +} + + +collect_env_info() +{ + # heartbeat_port from conf file + local heartbeat_port=`parse_confval_from_conf "heartbeat_service_port"` + if [[ "x$heartbeat_port" != "x" ]] ; then + HEARTBEAT_PORT=$heartbeat_port + fi + + if [[ "x$HOST_TYPE" == "xIP" ]] ; then + MY_SELF=$MY_IP + else + MY_SELF=$MY_HOSTNAME + fi +} + +function show_frontends() +{ + local addr=$1 + frontends=`timeout 15 mysql --connect-timeout 2 -h $addr -P $FE_QUERY_PORT -uroot --batch -e 'show frontends;' 2>&1` + log_stderr "[info] use root no password show frontends result $frontends ." + if echo $frontends | grep -w "1045" | grep -q -w "28000" &>/dev/null; then + log_stderr "[info] use username and passwore that configured to show frontends." + frontends=`timeout 15 mysql --connect-timeout 2 -h $addr -P $FE_QUERY_PORT -u$DB_ADMIN_USER -p$DB_ADMIN_PASSWD --batch -e 'show frontends;'` + fi + + echo "$frontends" +} + +show_backends(){ + local svc=$1 + backends=`timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -uroot --skip-column-names --batch -e 'SHOW BACKENDS;' 2>&1` + log_stderr "[info] use root no password show backends result $backends ." + if echo $backends | grep -w "1045" | grep -q -w "28000" &>/dev/null; then + log_stderr "[info] use username and password that configured to show backends." + backends=`timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -u$DB_ADMIN_USER -p$DB_ADMIN_PASSWD --skip-column-names --batch -e 'SHOW BACKENDS;'` + fi + + echo "$backends" +} + + +disable_query(){ + local svc=$1 + disable_result=`timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -uroot --skip-column-names --batch -e "ALTER SYSTEM MODIFY BACKEND \"$MY_SELF:$HEARTBEAT_PORT\" SET (\"disable_query\" = \"true\");" 2>&1` + if echo $disable_result | grep -w "1045" | grep -q -w "28000" &>/dev/null ; then + log_stderr "[info] disable_query use pwd to run 'ALTER SYSTEM MODIFY BACKEND' sql ." + disable_result=`timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -u$DB_ADMIN_USER -p$DB_ADMIN_PASSWD --skip-column-names --batch -e "ALTER SYSTEM MODIFY BACKEND \"$MY_SELF:$HEARTBEAT_PORT\" SET (\"disable_query\" = \"true\");" 2>&1` + fi + if [[ "x$disable_result" == "x" ]] ; then + log_stderr "[info] disable_query success ." + else + log_stderr "[error] disable_query failed: $disable_result ." + fi +} + +check_disable(){ + local svc=$1 + memlist=`show_backends $svc` + if echo "$memlist" | grep "$MY_SELF" | grep -q -w "isQueryDisabled\":true" &>/dev/null ; then + log_stderr "[info] Check myself ($MY_SELF:$HEARTBEAT_PORT) disable_query success " + echo "true" + else + log_stderr "[error] Check myself ($MY_SELF:$HEARTBEAT_PORT) disable_query failed " + echo "false" + fi +} + +# disable query and check for stop +prepare_stop(){ + local svc=$1 + for ((i=1; i<=RETRY_TIMES; i++)) Review Comment: It's so long, if time is spent in here, the graceful exit has enough 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-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org