Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Dec 17, 2024
1 parent da9ab82 commit 72a40d1
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions lib/mysql-role.sh
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,10 @@ watch_role_changes() {
if [ $((current_time - last_master_check)) -ge $master_check_interval ]; then
local master_id
if master_id=$(get_master_id); then
log_info "Found potential master with ID: $master_id"
local master_info
if master_info=$(get_node_info "$master_id"); then
if master_info=$(get_master_info "$master_id"); then
log_info "Retrieved master info from etcd"
if validate_master_info "$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
Expand All @@ -613,13 +615,17 @@ watch_role_changes() {
STANDALONE_CONFIGURED=1
fi
fi
else
log_info "Skipping replication setup - already configured (repl: $REPLICATION_CONFIGURED, standalone: $STANDALONE_CONFIGURED)"
fi
else
log_warn "Invalid master configuration detected"
log_warn "Invalid master configuration detected - will retry later"
fi
else
log_warn "Failed to get master info from etcd - will retry later"
fi
last_master_check=$current_time
fi
last_master_check=$current_time
fi

# Configure as slave if not properly configured at all
Expand Down Expand Up @@ -826,25 +832,58 @@ validate_master_info() {
local master_info=$1
local master_host master_port master_role

master_host=$(get_node_hostname "$master_info")
master_port=$(get_node_port "$master_info")
master_role=$(get_node_role "$master_info")
# Debug the input
log_info "Validating master info: $master_info"

master_host=$(echo "$master_info" | jq -r '.host // empty')
master_port=$(echo "$master_info" | jq -r '.port // empty')
master_role=$(echo "$master_info" | jq -r '.role // empty')

log_info "Extracted values - host: ${master_host:-none}, port: ${master_port:-none}, role: ${master_role:-none}"

if [ -z "$master_host" ] || [ -z "$master_port" ]; then
log_error "Invalid master info - missing host or port"
log_error "Invalid master info - missing host or port (host: ${master_host:-none}, port: ${master_port:-none})"
return 1
fi

if [ "$master_role" != "master" ]; then
log_error "Node $master_host:$master_port is not in master role"
log_error "Node $master_host:$master_port is not in master role (role: ${master_role:-none})"
return 1
fi

# Check if master is ourselves
if [ "$master_host" = "$(hostname)" ]; then
log_error "Cannot replicate from ourselves"
log_error "Cannot replicate from ourselves (master host: $master_host, our hostname: $(hostname))"
return 1
fi

log_info "Master info validation successful"
return 0
}

# Get master node info
get_master_info() {
local master_id=$1
local master_info

# Debug output
log_info "Getting master info for ID: $master_id"

# Get raw master info from etcd
master_info=$(etcdctl get "$ETCD_NODES/$master_id" --print-value-only 2>/dev/null)
if [ $? -ne 0 ]; then
log_error "Failed to get master info from etcd"
return 1
fi

# Debug the raw info
log_info "Raw master info: $master_info"

if [ -z "$master_info" ]; then
log_error "No master info found in etcd"
return 1
fi

echo "$master_info"
return 0
}

0 comments on commit 72a40d1

Please sign in to comment.