Skip to content

Commit

Permalink
fix: Improve MySQL role handling and etcd synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Dec 18, 2024
1 parent 78bedfe commit f675478
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/mysql-role.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ save_role_state() {
verify_role_state() {
local expected_role=$1

# Validate input role
if [ -z "$expected_role" ] || [ "$expected_role" = "null" ]; then
expected_role="slave"
log_info "Invalid expected role, defaulting to: $expected_role"
fi

if [ "$CURRENT_ROLE" != "$expected_role" ]; then
log_warn "Role state mismatch - expected: $expected_role, current: $CURRENT_ROLE"
log_info "Role state update - expected: $expected_role, current: $CURRENT_ROLE"
CURRENT_ROLE="$expected_role"
save_role_state "$expected_role"

# Ensure etcd is updated with the new role
update_node_status "$NODE_ID" "online" "$expected_role"
fi
}

Expand Down Expand Up @@ -543,18 +552,22 @@ monitor_gtid() {
local current_info
current_info=$(get_node_info "$NODE_ID")

# Get role with proper fallback
# Get role with proper fallback and validation
local current_role
if [ -z "$current_info" ]; then
# If no node info, use current role from global state
current_role="${CURRENT_ROLE:-slave}"
log_warn "No node info found, using current role: $current_role"
log_info "No node info found, using current role: $current_role"
# Update etcd with our current role to prevent empty role issues
update_node_status "$NODE_ID" "online" "$current_role"
else
# Get role from node info with fallback to current role or slave
# Get role from node info with strict validation
current_role=$(get_node_role_raw "$current_info")
if [ -z "$current_role" ]; then
if [ -z "$current_role" ] || [ "$current_role" = "null" ]; then
current_role="${CURRENT_ROLE:-slave}"
log_warn "Empty role in node info, using current role: $current_role"
log_info "Invalid role in etcd, updating with current role: $current_role"
# Force update etcd with valid role
update_node_status "$NODE_ID" "online" "$current_role"
fi
fi

Expand Down

0 comments on commit f675478

Please sign in to comment.