Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve](docker) add disable query for be restart #45208

Closed
42 changes: 41 additions & 1 deletion docker/runtime/be/resource/be_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ FE_QUERY_PORT=${FE_QUERY_PORT:-9030}
PROBE_TIMEOUT=60
# interval time to probe fe.
PROBE_INTERVAL=2
NEED_PRE_START=${NEED_PRE_STOP:-"false"}

# rpc port for fe communicate with be.
HEARTBEAT_PORT=9050
# fqdn or ip
Expand Down Expand Up @@ -107,6 +109,17 @@ show_backends(){
echo "$backends"
}

enable_query(){
local svc=$1
set_enable_query=`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\" = \"false\");" 2>&1`
log_stderr "[info] use root no password set enable query result $set_enable_query ."
if echo $set_enable_query | grep -w "1045" | grep -q -w "28000" &>/dev/null; then
log_stderr "[info] use username($DB_ADMIN_USER) and password that configured to enable query."
set_enable_query=`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\" = \"false\");"`
fi
log_stderr "[info] set enable query return $set_enable_query"
}

# get all registered fe in cluster, for check the fe have `MASTER`.
function show_frontends()
{
Expand Down Expand Up @@ -146,6 +159,17 @@ collect_env_info()
fi
}

check_enable(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_enable, check what enable.

local memlist=$1
if echo "$memlist" | grep "$MY_SELF" | grep -q -w "isQueryDisabled\":false" &>/dev/null ; then
log_stderr "[info] Check myself ($MY_SELF:$HEARTBEAT_PORT) enable_query success "
echo "true"
else
log_stderr "[error] Check myself ($MY_SELF:$HEARTBEAT_PORT) enble_query failed "
echo "false"
fi
}

add_self()
{
local svc=$1
Expand All @@ -157,7 +181,23 @@ add_self()
memlist=`show_backends $svc`
if echo "$memlist" | grep -q -w "$MY_SELF" &>/dev/null ; then
log_stderr "[info] Check myself ($MY_SELF:$HEARTBEAT_PORT) exist in FE, start be directly ..."
break;
if [[ "x$NEED_PRE_START" == "xfalse" ]] ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what the NEED_PRE_START variable meaning

break;
fi
enable_quer $svc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not have function name is "enable_quer" ,the function name is "enable_query"

res=`check_enable $memlist`
if [[ "x$res" == "xtrue" ]] ; then
break;
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if already break. not need else.

sleep $PROBE_INTERVAL
let "expire=start+timeout"
now=`date +%s`
if [[ $expire -le $now ]] ; then
log_stderr "[error] exit probe master for probing timeout."
return 0
fi
continue;
fi
fi

# check fe cluster have master, if fe have not master wait.
Expand Down
139 changes: 139 additions & 0 deletions docker/runtime/be/resource/be_prestop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_disable_query_is_true

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++))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so long, if time is spent in here, the graceful exit has enough time.

do
disable_query $ENV_FE_ADDR
disable_res=`check_disable $ENV_FE_ADDR`
if [[ "x$disable_res" == "xtrue" ]] ; then
break
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not need else.

log_stderr "[error] will retry to set be disable query "
sleep $PROBE_INTERVAL
fi
done
}


if [[ "x$NEED_PRE_STOP" == "xtrue" ]] ; then
resolve_password_from_secret
collect_env_info
prepare_stop $ENV_FE_ADDR
fi


$DORIS_HOME/bin/stop_be.sh --grace
Loading