enable fast boot docker

Signed-off-by: 汪渺 <shanhaikang.shk@oceanbase.com>
This commit is contained in:
汪渺
2023-11-08 21:30:30 +08:00
parent ec404798ef
commit 51a520d5e9
9 changed files with 408 additions and 34 deletions

View File

@ -4,6 +4,37 @@ cd "${CWD}"
source _env
STAMP="$(date +%s)"
STEP=1
PHASE_START_TIME=0
function timediff() {
start_time=$1
end_time=$2
start_s=${start_time%.*}
start_nanos=${start_time#*.}
end_s=${end_time%.*}
end_nanos=${end_time#*.}
if [ "$end_nanos" -lt "$start_nanos" ];then
end_s=$(( 10#$end_s - 1 ))
end_nanos=$(( 10#$end_nanos + 10**9 ))
fi
time=$(( 10#$end_s - 10#$start_s )).`printf "%03d\n" $(( (10#$end_nanos - 10#$start_nanos)/10**6 ))`
echo $time
}
function print_start_phase() {
echo "/////////////////////// STEP ${STEP}: $@ ///////////////////////"
STEP=$[ ${STEP} + 1 ]
PHASE_START_TIME=$(date +%s.%N)
}
function print_end_phase() {
cur_time=$(date +%s.%N)
echo "/////////////////////// phase end: $(timediff ${PHASE_START_TIME} ${cur_time}) s ///////////////////////"
}
function is_true() {
value=$1
@ -19,7 +50,8 @@ function is_true() {
function get_mode() {
if test -z ${MODE}
then
MODE="MINI"
# default mode is "STANDALONE" now.
MODE="STANDALONE"
fi
MODE=${MODE^^}
}
@ -90,12 +122,14 @@ if [ -f "$HOME/.obd/cluster/${OB_CLUSTER_NAME}/config.yaml" ]; then
obd cluster start $OB_CLUSTER_NAME
else # nothing here, bootstrap
echo "generate boot.yaml ..."
print_start_phase "Config Generation"
TMPFILE="boot.${STAMP}.yaml"
get_mode
if [ "x${MODE}" == "xMINI" ]; then
if [ "x${MODE}" == "xSTANDALONE" ]; then
echo "oceanbase-ce docker in standalone mode"
cp -f boot-mini-tmp.yaml $TMPFILE
elif [ "x${MODE}" == "xMINI" ]; then
echo "oceanbase-ce docker in mini mode"
cp -f boot-mini-tmp.yaml $TMPFILE
elif [ "x${MODE}" == "xSLIM" ]; then
@ -118,43 +152,66 @@ else # nothing here, bootstrap
sed -i "s|@OB_DATAFILE_SIZE@|${OB_DATAFILE_SIZE}|g" $TMPFILE
sed -i "s|@OB_LOG_DISK_SIZE@|${OB_LOG_DISK_SIZE}|g" $TMPFILE
sed -i "s|@OB_ROOT_PASSWORD@|${OB_ROOT_PASSWORD}|g" $TMPFILE
[ "${OB_DATA_DIR}" ] && echo " data_dir: ${OB_DATA_DIR}" >> $TMPFILE
[ "${OB_REDO_DIR}" ] && echo " redo_dir: ${OB_REDO_DIR}" >> $TMPFILE
echo "create boot dirs and deploy ob cluster ..."
mkdir -p $OB_HOME_PATH
print_end_phase
print_start_phase "Ob-deploy mirror clone"
mkdir -p $OB_HOME_PATH
obd mirror clone /root/pkg/*.rpm \
&& obd mirror list local
print_end_phase
print_start_phase "Ob-deploy deploy"
remove_disk_check_logic_in_obd
obd devmode enable && obd cluster autodeploy "${OB_CLUSTER_NAME}" -c $TMPFILE;
if [ $? -ne 0 ]; then
deploy_failed
fi
if [ "x${MODE}" == "xSTANDALONE" ]; then
obd devmode enable && obd cluster deploy "${OB_CLUSTER_NAME}" -c $TMPFILE;
if [ $? -ne 0 ]; then
deploy_failed
fi
print_end_phase
print_start_phase "Ob-deploy restore store dir"
rm -rf ${OB_HOME_PATH}/store && tar -Sxzvf /root/boot/store.tar.gz -C ${OB_HOME_PATH}
print_end_phase
create_tenant_cmd="obd cluster tenant create ${OB_CLUSTER_NAME} -n ${OB_TENANT_NAME}"
if ! [ -z "${OB_TENANT_MINI_CPU}" ]; then
create_tenant_cmd="${create_tenant_cmd} --min-cpu=${OB_TENANT_MINI_CPU}"
fi;
if ! [ -z "${OB_TENANT_MEMORY_SIZE}" ]; then
create_tenant_cmd="${create_tenant_cmd} --memory-size=${OB_TENANT_MEMORY_SIZE}"
fi;
if ! [ -z "${OB_TENANT_LOG_DISK_SIZE}" ]; then
create_tenant_cmd="${create_tenant_cmd} --log-disk-size=${OB_TENANT_LOG_DISK_SIZE}"
fi;
eval ${create_tenant_cmd}
if [ $? -ne 0 ]; then
deploy_failed
fi
print_start_phase "Ob-deploy import etc"
cp -r /root/boot/etc/* ${OB_HOME_PATH}/etc
print_end_phase
if [ "x${MODE}" != "xSLIM" ]; then
obclient -h127.1 -uroot@${OB_TENANT_NAME} -A -P${OB_MYSQL_PORT} < init_tenant_user.sql
print_start_phase "Ob-deploy start"
obd cluster start ${OB_CLUSTER_NAME}
print_end_phase
else
run_custom_scripts /root/boot/init.d
fi
print_start_phase "Ob-deploy autodeploy"
obd devmode enable && obd cluster autodeploy "${OB_CLUSTER_NAME}" -c $TMPFILE;
print_end_phase
print_start_phase "Ob-deploy Create Tenant"
create_tenant_cmd="obd cluster tenant create ${OB_CLUSTER_NAME} -n ${OB_TENANT_NAME}"
if ! [ -z "${OB_TENANT_MINI_CPU}" ]; then
create_tenant_cmd="${create_tenant_cmd} --min-cpu=${OB_TENANT_MINI_CPU}"
fi;
if ! [ -z "${OB_TENANT_MEMORY_SIZE}" ]; then
create_tenant_cmd="${create_tenant_cmd} --memory-size=${OB_TENANT_MEMORY_SIZE}"
fi;
if ! [ -z "${OB_TENANT_LOG_DISK_SIZE}" ]; then
create_tenant_cmd="${create_tenant_cmd} --log-disk-size=${OB_TENANT_LOG_DISK_SIZE}"
fi;
eval ${create_tenant_cmd}
if [ $? -ne 0 ]; then
deploy_failed
fi
if [ "x${MODE}" != "xSLIM" ]; then
obclient -h127.1 -uroot@${OB_TENANT_NAME} -A -P${OB_MYSQL_PORT} < init_tenant_user.sql
else
run_custom_scripts /root/boot/init.d
fi
print_end_phase
fi
if [ $? -ne 0 ]; then
deploy_failed
fi