From 0950a08efd87e8993bb9d3af901b6207ca3fabda Mon Sep 17 00:00:00 2001 From: Adonis Ling Date: Tue, 21 Feb 2023 10:55:36 +0800 Subject: [PATCH] [chore](tools) Support starting multiple FEs on single node (#16787) Introduce a tool to start multiple FEs on single node. Use case: ``` $ ./multi-fe ./multi-fe start|stop|clean [OPTIONS ...] start -n -l -p Start the FE cluster. -n The number of FEs. -l The FE library path (default: doris/output/fe/lib) -p The base port to generate all needed ports (default: 9030). stop Stop the FE cluster. clean Stop the data (rm -rf "$(pwd)"/fe*). ``` --- .gitignore | 1 + tools/single-node-cluster/multi-fe | 268 +++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100755 tools/single-node-cluster/multi-fe diff --git a/.gitignore b/.gitignore index 5ba2f22e45..c6229863aa 100644 --- a/.gitignore +++ b/.gitignore @@ -92,6 +92,7 @@ tools/**/TPC-H_Tools_v*/ tools/**/tpc-h_v*.docx tools/**/tpc-h_v*.pdf tools/**/tpch-data/ +tools/single-node-cluster/fe* # be-ut data_test diff --git a/tools/single-node-cluster/multi-fe b/tools/single-node-cluster/multi-fe new file mode 100755 index 0000000000..762fab14fa --- /dev/null +++ b/tools/single-node-cluster/multi-fe @@ -0,0 +1,268 @@ +#!/bin/bash + +# 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. + +set -e + +CURRENT_PATH="$( + cd "$(dirname "${BASH_SOURCE[0]}")" + pwd +)" +OUTPUT_PATH="$(readlink -f "${CURRENT_PATH}/../../output")" + +readonly CURRENT_PATH +readonly OUTPUT_PATH + +function log() { + local level="${1}" + local message="${2}" + local date + date="$(date +'%Y-%m-%d %H:%M:%S')" + if [[ "${level}" == 'INFO' ]]; then + level="[\033[32;1m ${level} \033[0m]" + elif [[ "${level}" == 'WARNING' ]]; then + level="[\033[33;1m${level}\033[0m]" + elif [[ "${level}" == 'ERROR' ]]; then + level="[\033[31;1m ${level} \033[0m]" + fi + echo -e "${level} ${date} - ${message}" +} + +function log_info() { + local message="${1}" + log 'INFO' "${message}" +} + +function log_warning() { + local message="${1}" + log 'WARNING' "${message}" +} + +function log_error() { + local message="${1}" + log 'ERROR' "${message}" + exit 1 +} + +function help() { + cat >&2 < -l -p + + Start the FE cluster. + -n The number of FEs. + -l The FE library path (default: doris/output/fe/lib) + -p The base port to generate all needed ports (default: 9030). + + stop Stop the FE cluster. + + clean Stop the data (rm -rf "\$(pwd)"/fe*). +EOF + exit 1 +} + +function parse_options() { + NUMBER_INSTANCES=1 + PORT=9010 + LIBS_PATH="${OUTPUT_PATH}/fe/lib" + + ACTION="${1}" + if ! shift 1; then + help + fi + + local option + while getopts "+n:p:l:" option; do + case "${option}" in + n) + NUMBER_INSTANCES="${OPTARG}" + ;; + p) + PORT="${OPTARG}" + ;; + l) + LIBS_PATH="$(readlink -f "${OPTARG}")" + ;; + *) + help + ;; + esac + done + + readonly NUMBER_INSTANCES + readonly PORT + readonly LIBS_PATH +} + +function prepare() { + local port="${1}" + local doris_home="${2}" + local log_dir="${3}" + local conf_dir="${doris_home}/conf" + local meta_dir="${doris_home}/doris-meta" + local http_port=8030 + + mkdir -p "${doris_home}" + mkdir -p "${log_dir}" + mkdir -p "${conf_dir}" + mkdir -p "${meta_dir}" + + cat >"${conf_dir}/fe.conf" <"${meta_dir}/image/VERSION" + + mysql_command "ALTER SYSTEM ADD FOLLOWER \"127.0.0.1:$((PORT + id))\"" >/dev/null 2>&1 || true + cat >"${meta_dir}/image/ROLE" </dev/null + DORIS_HOME="${doris_home}" \ + PID_DIR="${doris_home}" \ + nohup java -cp "$( + IFS=: + echo "${classpath[*]}" + )" org.apache.doris.PaloFe ${helper:+${helper}} >>"${log_dir}/fe.out" 2>&1 & + if kill -0 $!; then + log_info "Start FE(${id}) successfully" + else + log_warning "Failed to start FE(${id})" + fi + popd >/dev/null +} + +function start() { + if [[ -z "${LIBS_PATH}" ]]; then + help + fi + + log_info "NUMBER: ${NUMBER_INSTANCES}" + log_info "BASE PORT: ${PORT}" + log_info "LIBRARY_PATH: ${LIBS_PATH}" + + for i in $(seq "${NUMBER_INSTANCES}"); do + start_fe "${i}" "${PORT}" "${LIBS_PATH}" + done +} + +function stop() { + local pid + while read -r file; do + pid="$(<"${file}")" + if kill "${pid}"; then + log_info "Stopped FE (${pid}) successfully" + else + log_warning "Failed to stop FE (${pid})" + fi + done < <(find "$(pwd)"/fe* -name 'fe.pid') +} + +function clean() { + rm -rf "$(pwd)"/fe* + log_info "Clean all data successfully" +} + +function main() { + parse_options "${@}" + + case "${ACTION}" in + start) start ;; + stop) stop ;; + clean) clean ;; + *) + help + ;; + esac +} + +main "${@}"