Skip to content

Commit

Permalink
refactor: pass master_id to validate_master_info and compare to NODE_ID
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Dec 18, 2024
1 parent d6cf3df commit c01e9e2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/mysql-role.sh
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ watch_role_changes() {
if master_id=$(get_master_id); then
local master_info
if master_info=$(get_node_info "$master_id"); then
if validate_master_info "$master_info"; then
if validate_master_info "$master_id" "$master_info"; then
# Only reconfigure if we're not already replicating or in standalone mode
if [ $REPLICATION_CONFIGURED -eq 0 ] && [ $STANDALONE_CONFIGURED -eq 1 ]; then
log_info "Valid master detected, reconfiguring replication"
Expand Down Expand Up @@ -797,7 +797,8 @@ configure_standalone_slave() {

# Validate master info
validate_master_info() {
local master_info=$1
local master_id=$1
local master_info=$2
local master_host master_port master_role

# Use raw functions to parse JSON directly
Expand All @@ -816,7 +817,7 @@ validate_master_info() {
fi

# Check if master is ourselves
if [ "$master_host" = "$(hostname)" ]; then
if [ "$master_id" = "$NODE_ID" ]; then
log_error "Cannot replicate from ourselves"
return 1
fi
Expand Down

0 comments on commit c01e9e2

Please sign in to comment.