@@ -270,28 +270,23 @@ function wait_for_primary() {
270270 cluster_size=${# members_id[@]}
271271
272272 local is_primary_found=0
273- for member_id in ${members_id[*]} ; do
274- for i in {60..0}; do
275- primary_member_id=$( ${mysql} -N -e " SHOW STATUS WHERE Variable_name = 'group_replication_primary_member';" | awk ' {print $2}' )
276- log " INFO" " Attempt $i : Trying to find primary member........................"
277- if [[ -n " $primary_member_id " ]]; then
278- is_primary_found=1
279- primary_host=$( ${mysql} -N -e " SELECT MEMBER_HOST FROM performance_schema.replication_group_members WHERE MEMBER_ID = '${primary_member_id} ';" | awk ' {print $1}' )
280- # calculate data size of the primary node.
281- # https://forums.mysql.com/read.php?108,201578,201578
282- primary_db_size=$( ${mysql_header} --host=$primary_host -N -e ' select round(sum( data_length + index_length) / 1024 / 1024) "size in mb" from information_schema.tables;' )
283- log " INFO" " Primary found. Primary host: $primary_host , database size: $primary_db_size "
284- break
285- fi
286-
287- echo -n .
288- sleep 1
289- done
290273
291- if [[ " $is_primary_found " == " 1" ]]; then
274+ for i in {20..0}; do
275+ primary_member_id=$( ${mysql} -N -e " SELECT MEMBER_ID FROM performance_schema.replication_group_members WHERE MEMBER_STATE = 'ONLINE' and MEMBER_ROLE = 'PRIMARY';" | awk ' {print $2}' )
276+ log " INFO" " Attempt $i : Trying to find primary member........................"
277+ if [[ -n " $primary_member_id " ]]; then
278+ log " INFO" " Found the primary"
279+ is_primary_found=1
280+ primary_host=$( ${mysql} -N -e " SELECT MEMBER_HOST FROM performance_schema.replication_group_members WHERE MEMBER_ID = '${primary_member_id} ';" | awk ' {print $1}' )
281+ # calculate data size of the primary node.
282+ # https://forums.mysql.com/read.php?108,201578,201578
283+ primary_db_size=$( ${mysql_header} --host=$primary_host -N -e ' select round(sum( data_length + index_length) / 1024 / 1024) "size in mb" from information_schema.tables;' )
284+ log " INFO" " Primary found. Primary host: $primary_host , database size: $primary_db_size "
292285 break
293286 fi
294287
288+ echo -n .
289+ sleep 1
295290 done
296291
297292 if [[ " $is_primary_found " == " 1" ]]; then
@@ -542,7 +537,7 @@ while true; do
542537
543538 if [[ $desired_func == " join_in_cluster" ]]; then
544539 check_member_list_updated " ${member_hosts[*]} "
545- wait_for_primary " ${member_hosts[*]} "
540+ # wait_for_primary "${member_hosts[*]}"
546541 set_valid_donors
547542 join_into_cluster
548543 fi
0 commit comments