Skip to content
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bf903d4
fix doc
FreeOnePlus Oct 8, 2022
479be86
Merge branch 'master' of https://github.com/apache/doris
FreeOnePlus Oct 8, 2022
49a7f4e
Merge branch 'master' of https://github.com/apache/doris
FreeOnePlus Oct 14, 2022
e6c848d
Merge branch 'apache:master' into master
FreeOnePlus Oct 27, 2022
9f21035
Merge branch 'apache:master' into master
FreeOnePlus Nov 11, 2022
c3d4e46
Merge branch 'apache:master' into master
FreeOnePlus Nov 17, 2022
714c6aa
Merge branch 'apache:master' into master
FreeOnePlus Nov 18, 2022
75bfec0
Merge branch 'apache:master' into master
FreeOnePlus Nov 21, 2022
393c3c3
Merge branch 'apache:master' into master
FreeOnePlus Nov 21, 2022
291e354
Merge branch 'apache:master' into master
FreeOnePlus Nov 27, 2022
5277262
change docs
FreeOnePlus Nov 21, 2022
34d88d2
change docs
FreeOnePlus Nov 21, 2022
2345b20
change docs
FreeOnePlus Nov 21, 2022
0967a61
change docs
FreeOnePlus Nov 21, 2022
b24fcaf
change sh_checker_exclude
FreeOnePlus Nov 22, 2022
efa085b
add shell
FreeOnePlus Nov 27, 2022
44aab66
add broker Dockerfile and init_broker.sh
FreeOnePlus Nov 27, 2022
1b4b90e
add docker docs
FreeOnePlus Nov 27, 2022
c8feddc
Merge branch 'master' of https://github.com/apache/doris
FreeOnePlus Nov 29, 2022
6e5856b
Adjust the field naming rules when creating tables
FreeOnePlus Nov 29, 2022
d7ccd50
Merge branch 'apache:master' into master
FreeOnePlus Dec 6, 2022
7cbae26
Merge branch 'apache:master' into master
FreeOnePlus Dec 9, 2022
edf57c3
Merge branch 'apache:master' into master
FreeOnePlus Dec 21, 2022
c876212
Merge branch 'apache:master' into master
FreeOnePlus Dec 22, 2022
0a1e391
Merge branch 'apache:master' into master
FreeOnePlus Jan 25, 2023
cab2b92
Merge branch 'apache:master' into master
FreeOnePlus Feb 7, 2023
5a9f1e7
Merge branch 'apache:master' into master
FreeOnePlus Feb 8, 2023
62cf3ed
Merge branch 'apache:master' into master
FreeOnePlus Feb 9, 2023
64b2b88
Merge branch 'apache:master' into master
FreeOnePlus Feb 10, 2023
8c2dba9
Merge branch 'apache:master' into master
FreeOnePlus Feb 11, 2023
4b1f7e4
Merge branch 'apache:master' into master
FreeOnePlus Feb 12, 2023
0cc891f
Merge branch 'apache:master' into master
FreeOnePlus Feb 14, 2023
fb475f6
add broker dockerfile
FreeOnePlus Feb 14, 2023
5ab7d60
add computer node interface
FreeOnePlus Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
229 changes: 156 additions & 73 deletions docker/runtime/broker/resource/init_broker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,95 +16,178 @@
# specific language governing permissions and limitations
# under the License.

FE_SERVERS=""
BROKER_ADDR=""
set -eo pipefail
shopt -s nullglob

ARGS=$(getopt -o -h: --long fe_servers:,broker_addr: -n "$0" -- "$@")
DORIS_HOME="/opt/apache-doris"

eval set -- "${ARGS}"
# Obtain necessary and basic information to complete initialization

while [[ -n "$1" ]]; do
case "$1" in
--fe_servers)
FE_SERVERS=$2
shift
;;
--broker_addr)
BROKER_ADDR=$2
shift
;;
--) ;;
# logging functions
# usage: doris_[note|warn|error] $log_meg
# ie: doris_warn "task may BROKER risky!"
# out: 2023-01-08T19:08:16+08:00 [Warn] [Entrypoint]: task may BROKER risky!
doris_log() {
local type="$1"
shift
# accept argument string or stdin
local text="$*"
if [ "$#" -eq 0 ]; then text="$(cat)"; fi
local dt="$(date -Iseconds)"
printf '%s [%s] [Entrypoint]: %s\n' "$dt" "$type" "$text"
}
doris_note() {
doris_log Note "$@"
}
doris_warn() {
doris_log Warn "$@" >&2
}
doris_error() {
doris_log ERROR "$@" >&2
exit 1
}

*)
echo "Error option $1"
break
;;
esac
shift
done

#echo FE_SERVERS = $FE_SERVERS
echo "DEBUG >>>>>> FE_SERVERS=[${FE_SERVERS}]"
echo "DEBUG >>>>>> BROKER_ADDR=[${BROKER_ADDR}]"
# check to see if this file is BROKERing run or sourced from another script
_is_sourced() {
[ "${#FUNCNAME[@]}" -ge 2 ] &&
[ "${FUNCNAME[0]}" = '_is_sourced' ] &&
[ "${FUNCNAME[1]}" = 'source' ]
}

feIpArray=()
feEditLogPortArray=()
# Check the variables required for startup
docker_required_variables_env() {
if [[ $FE_SERVERS =~ ^.+:[1-2]{0,1}[0-9]{0,1}[0-9]{1}(\.[1-2]{0,1}[0-9]{0,1}[0-9]{1}){3}:[1-6]{0,1}[0-9]{1,4}(,.+:[1-2]{0,1}[0-9]{0,1}[0-9]{1}(\.[1-2]{0,1}[0-9]{0,1}[0-9]{1}){3}:[1-6]{0,1}[0-9]{1,4})*$ ]]; then
doris_warn "FE_SERVERS" $FE_SERVERS
else
doris_error "FE_SERVERS rule error!example: \$FE_NAME:\$FE_HOST_IP:\$FE_EDIT_LOG_PORT[,\$FE_NAME:\$FE_HOST_IP:\$FE_EDIT_LOG_PORT]..."
fi
if [[ $BROKER_ADDR =~ ^[a-zA-Z0-9]+:[1-2]{0,1}[0-9]{0,1}[0-9]{1}(\.[1-2]{0,1}[0-9]{0,1}[0-9]{1}){3}:[1-6]{0,1}[0-9]{1,4}$ ]]; then
doris_warn "BROKER_ADDR" $BROKER_ADDR
else
doris_error "BROKER_ADDR rule error!example: \$BROKER_NAME:\$BROKER_HOST_IP:\$BROKER_IPC_PORT"
fi
}

IFS=","
# shellcheck disable=SC2206
feServerArray=(${FE_SERVERS})

for i in "${!feServerArray[@]}"; do
val=${feServerArray[i]}
get_doris_broker_args() {
local feServerArray=($(echo "${FE_SERVERS}" | awk '{gsub (/,/," "); print $0}'))
for i in "${feServerArray[@]}"; do
val=${i}
val=${val// /}
tmpFeId=$(echo "${val}" | awk -F ':' '{ sub(/fe/, ""); sub(/ /, ""); print$1}')
tmpFeIp=$(echo "${val}" | awk -F ':' '{ sub(/ /, ""); print$2}')
tmpFeEditLogPort=$(echo "${val}" | awk -F ':' '{ sub(/ /, ""); print$3}')
feIpArray[tmpFeId]=${tmpFeIp}
feEditLogPortArray[tmpFeId]=${tmpFeEditLogPort}
done
check_arg "tmpFeIp" $tmpFeIp
feIpArray[$tmpFeId]=${tmpFeIp}
check_arg "tmpFeEditLogPort" $tmpFeEditLogPort
feEditLogPortArray[$tmpFeId]=${tmpFeEditLogPort}
done

broker_name=$(echo "${BROKER_ADDR}" | awk -F ':' '{ sub(/ /, ""); print$1}')
broker_ip=$(echo "${BROKER_ADDR}" | awk -F ':' '{ sub(/ /, ""); print$2}')
broker_ipc_port=$(echo "${BROKER_ADDR}" | awk -F ':' '{ sub(/ /, ""); print$3}')
declare -g MASTER_FE_IP BROKER_HOST_IP BROKER_IPC_PORT BROKER_NAME
MASTER_FE_IP=${feIpArray[1]}
check_arg "MASTER_FE_IP" $MASTER_FE_IP
BROKER_NAME=$(echo "${BROKER_ADDR}" | awk -F ':' '{ sub(/ /, ""); print$1}')
check_arg "BROKER_NAME" $BROKER_NAME
BROKER_HOST_IP=$(echo "${BROKER_ADDR}" | awk -F ':' '{ sub(/ /, ""); print$2}')
check_arg "BROKER_HOST_IP" $BROKER_HOST_IP
BROKER_IPC_PORT=$(echo "${BROKER_ADDR}" | awk -F ':' '{ sub(/ /, ""); print$3}')
check_arg "BROKER_IPC_PORT" $BROKER_IPC_PORT

echo "DEBUG >>>>>> feIpArray = ${feIpArray[*]}"
echo "DEBUG >>>>>> feEditLogPortArray = ${feEditLogPortArray[*]}"
echo "DEBUG >>>>>> masterFe = ${feIpArray[1]}:${feEditLogPortArray[1]}"
echo "DEBUG >>>>>> broker_addr = ${broker_ip}:${broker_ipc_port}"
doris_note "feIpArray = ${feIpArray[*]}"
doris_note "feEditLogPortArray = ${feEditLogPortArray[*]}"
doris_note "masterFe = ${feIpArray[1]}:${feEditLogPortArray[1]}"
doris_note "brokerAddr = ${BROKER_NAME}:${BROKER_HOST_IP}:${BROKER_IPC_PORT}"
# wait fe start
check_broker_status true
}

dropMySQL="/usr/bin/mysql -uroot -P9030 -h${feIpArray[1]} -e \"alter system drop broker ${broker_name} '${broker_ip}:${broker_ipc_port}'\""
echo "DEBUG >>>>>> dropMySQL = ${dropMySQL}"
eval "${dropMySQL}" && echo "DEBUG >>>>>> drop history registe SUCCESS!" || echo "DEBUG >>>>>> drop history registe FAILED!"
# Execute sql script, passed via stdin
# usage: docker_process_sql sql_script
docker_process_sql() {
set +e
mysql -uroot -P9030 -h${MASTER_FE_IP} --comments "$@" 2>/dev/null
}

# register broker to FE through mysql
registerMySQL="/usr/bin/mysql -uroot -P9030 -h${feIpArray[1]} -e \"alter system add broker ${broker_name} '${broker_ip}:${broker_ipc_port}'\""
echo "DEBUG >>>>>> registerMySQL = ${registerMySQL}"
eval "${registerMySQL}" && echo "DEBUG >>>>>> mysql register is SUCCESS!" || echo "DEBUG >>>>>> mysql register is FAILED!"
# register broker
register_broker_to_fe() {
set +e
# check fe status
local is_fe_start=false
for i in {1..300}; do
if [[ $(( $i % 20 )) == 1 ]]; then
doris_note "Register BROKER to FE is failed. retry."
fi
docker_process_sql <<<"alter system add broker ${BROKER_NAME} '${BROKER_HOST_IP}:${BROKER_IPC_PORT}'"
register_broker_status=$?
if [[ $register_broker_status == 0 ]]; then
doris_note "BROKER successfully registered to FE!"
is_fe_start=true
break
else
check_broker_status
if [ -n "$BROKER_ALREADY_EXISTS" ]; then
doris_warn "Same backend already exists! No need to register again!"
break
fi
if [[ $(( $i % 20 )) == 1 ]]; then
doris_warn "BROKER failed registered to FE!"
fi
fi
sleep 1
done
if ! [[ $is_fe_start ]]; then
doris_error "Failed to register BROKER to FE!Tried 30 times!MayBe FE Start Failed!"
fi
}

# start broker
registerShell="/opt/apache-doris/broker/bin/start_broker.sh &"
echo "DEBUG >>>>>> registerShell = ${registerShell}"
eval "${registerShell}" && echo "DEBUG >>>>>> start_broker SUCCESS!" || echo "DEBUG >>>>>> start_broker FAILED!"
# Check whether the passed parameters are empty to avoid subsequent task execution failures. At the same time,
# enumeration checks can BROKER added, such as checking whether a certain parameter appears repeatedly, etc.
check_arg() {
if [ -z $2 ]; then
doris_error "$1 is null!"
fi
}

for ((i = 0; i <= 20; i++)); do
sleep 10
## check broker register status
echo "DEBUG >>>>>> run commnad mysql -uroot -P9030 -h${feIpArray[1]} -e \"show proc '/brokers'\" | grep \" ${broker_ip} \" | grep \" ${broker_ipc_port} \" | grep \" true \""
mysql -uroot -P9030 -h"${feIpArray[1]}" -e "show proc '/brokers'" | grep "[[:space:]]${broker_ip}[[:space:]]" | grep "[[:space:]]${broker_ipc_port}[[:space:]]" | grep "[[:space:]]true[[:space:]]"
# 这里可用 docker_process_sql() 函数封装,为了方便调试,暂未封装
Copy link
Contributor

Choose a reason for hiding this comment

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

use english

check_broker_status() {
set +e
for i in {1..300}; do
if [[ $1 == true ]]; then
docker_process_sql <<<"show frontends" | grep "[[:space:]]${MASTER_FE_IP}[[:space:]]"
else
docker_process_sql <<<"show proc '/brokers'" | grep "[[:space:]]${BROKER_HOST_IP}[[:space:]]" | grep "[[:space:]]${BROKER_IPC_PORT}[[:space:]]"
fi
broker_join_status=$?
echo "DEBUG >>>>>> The " "${i}" "time to register Broker node, broker_join_status=${broker_join_status}"
doris_warn "broker_join_status: " $broker_join_status
if [[ "${broker_join_status}" == 0 ]]; then
## broker registe successfully
echo "BROKER START SUCCESS!!!"
break
else
## broker doesn't registe
echo "DEBUG >>>>>> run commnad ${registerMySQL}"
eval "${registerMySQL}"
if [[ "${i}" == 20 ]]; then
echo "DEBUG >>>>>> Broker Start Or Register FAILED!"
fi
sleep 3
if [[ $1 == true ]]; then
doris_note "MASTER FE is started!"
else
doris_note "Init Check - Verify that BROKER is registered to FE successfully"
BROKER_ALREADY_EXISTS=true
fi
break
fi
done
if [[ $(( $i % 20 )) == 1 ]]; then
if [[ $1 == true ]]; then
doris_note "MASTER FE is not started. retry."
else
doris_note "BROKER is not register. retry."
fi
fi
sleep 1
done
}

_main() {
docker_required_variables_env
get_doris_broker_args
register_broker_to_fe
check_broker_status
doris_note "Ready to start BROKER!"
start_broker.sh
exec "$@"
}

if ! _is_sourced; then
_main "$@"
fi