Skip to content

Commit

Permalink
chore: fix ob restore standby failed (#333)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1d7f8c7)
  • Loading branch information
wangyelei committed Feb 28, 2024
1 parent 0f2e589 commit d2c3c7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
19 changes: 11 additions & 8 deletions addons/oceanbase/dataprotection/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ function executeSQLFile() {

function waitForPrimaryClusterRestore() {
local primaryHost=${1}
local primaryCmd="mysql -u root -P${sql_port} -h ${primaryHost} -N -e"
local primaryPort=${2}
local primaryCmd="mysql -u root -P${primaryPort} -h ${primaryHost} -N -e"
while true; do
echo "INFO: wait primary cluster to restore data completed..."
historyRes=$(${primaryCmd} "SELECT count(*) FROM oceanbase.CDB_OB_RESTORE_HISTORY;" | awk -F '\t' '{print}')
if [[ ${historyRes} -lt 1 ]];then
if [[ ${historyRes} -lt 1 ]] && [[ "${REBUILD_STANDBY}" == "false" ]];then
sleep 10
continue
fi
Expand All @@ -138,8 +139,9 @@ function waitForPrimaryClusterRestore() {

function waitToPromotePrimary() {
local primaryHost=${1}
local tenant_name=${2}
local primaryCmd="mysql -u root -P2881 -h ${primaryHost} -N -e"
local primaryPort=${2}
local tenant_name=${3}
local primaryCmd="mysql -u root -P${primaryPort} -h ${primaryHost} -N -e"
local time=0
while true; do
echo "INFO: wait to promote ${tenant_name} to PRIMARY."
Expand Down Expand Up @@ -311,19 +313,20 @@ if [[ ${isPrimaryCluster} == "false" ]]; then
primaryComponentName="${KB_CLUSTER_COMP_NAME%-*}-1"
fi
primaryHost="${primaryComponentName}-0.${primaryComponentName}-headless"
echo "primary cluster host: ${primaryHost}"
waitForPrimaryClusterRestore "${primaryHost}"
primaryPort=$(cat /home/admin/workdir/component_ports.ob | jq -r ".\"${primaryComponentName}\"")
echo "primary cluster host/port: ${primaryHost}:${primaryPort}"
waitForPrimaryClusterRestore "${primaryHost}" "${primaryPort}"
echo "INFO: establish replication relationship"
# set -e
for tenant_name in `${mysql_cmd} "SELECT tenant_name FROM oceanbase.DBA_OB_TENANTS where tenant_type='user' and status='NORMAL';" | awk -F '\t' '{print}'`; do
primary_tenant_cmd="mysql -u root@${tenant_name} -h ${primaryHost} -P${sql_port} -N -e"
primary_tenant_cmd="mysql -u root@${tenant_name} -h ${primaryHost} -P${primaryPort} -N -e"
# get primary tenant svr_list
arr=$(${primary_tenant_cmd} "select concat(SVR_IP,':',SQL_PORT) from oceanbase.DBA_OB_ACCESS_POINT dp, oceanbase.DBA_OB_TENANTS dt where dp.tenant_id = dt.tenant_id and dt.tenant_name='${tenant_name}';" | awk -F '\t' '{print}')
IFS=,
svrList="${arr[*]}"
IFS=$OlD_IFS
# wait to promote primary cluster to Primary
waitToPromotePrimary "${primaryHost}" "${tenant_name}"
waitToPromotePrimary "${primaryHost}" "${primaryPort}" "${tenant_name}"
res=`${primary_tenant_cmd} "SELECT count(*) FROM mysql.user where user='${repUser}'" | awk -F '\t' '{print}'`
if [[ $res -eq 0 ]]; then
echo "INFO: create user ${repUser} for primary tenant ${tenant_name}"
Expand Down
11 changes: 11 additions & 0 deletions addons/oceanbase/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ echo "COMP_RPC_PORT: $COMP_RPC_PORT"
function init_port_list {
MYSQL_PORTS=()
RPC_PORTS=()
COMP_NAMES=()
components_prefix=$(echo "${KB_CLUSTER_COMP_NAME}" | awk -F'-' '{NF--; print}' OFS='-')
for i in $(seq 0 $(($OB_CLUSTERS_COUNT-1))); do
MYSQL_PORTS+=(2881)
RPC_PORTS+=(2882)
COMP_NAMES+=(${components_prefix}-${i})
done

{{- range $i, $e := $.dynamicCompInfos }}
Expand All @@ -56,8 +59,16 @@ function init_port_list {
{{- end }}
MYSQL_PORTS[{{ $i }}]={{$mysql_port}}
RPC_PORTS[{{ $i }}]={{$rpc_port}}
COMP_NAMES[{{ $i }}]={{$e.name}}
{{- end }}

comp_ports_json="{}"
for ((i=0; i<${#COMP_NAMES[@]}; i++))
do
comp_ports_json=$(echo ${comp_ports_json} | jq ".+{\"${COMP_NAMES[$i]}\":\"${MYSQL_PORTS[$i]}\"}")
done
echo $comp_ports_json > /home/admin/workdir/component_ports.ob

COMP_MYSQL_PORT=${MYSQL_PORTS[$COMPONENT_INDEX]}
COMP_RPC_PORT=${RPC_PORTS[$COMPONENT_INDEX]}
# persisting the sql port for backup and restore
Expand Down

0 comments on commit d2c3c7b

Please sign in to comment.