-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Changes from all commits
14ead91
2950cda
d311933
9d98569
9a62d68
65cccd4
6038e6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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() | ||
{ | ||
|
@@ -146,6 +159,17 @@ collect_env_info() | |
fi | ||
} | ||
|
||
check_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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what the |
||
break; | ||
fi | ||
enable_quer $svc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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++)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.