Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Dec 18, 2024
1 parent 4612f6e commit 5fa5da5
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions lib/mysql-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,34 @@ check_mysql_health() {

# Only check write capability if we're master
if [ "$CURRENT_ROLE" = "master" ]; then
# Get read_only status for debugging
local read_only_status
read_only_status=$(mysql_retry -e 'SHOW VARIABLES LIKE "read_only"' 2>/dev/null)
# Get detailed MySQL variables for debugging
local mysql_vars
mysql_vars=$(mysql_retry -e "SHOW VARIABLES LIKE '%read_only%'\G")
local super_read_only
super_read_only=$(mysql_retry -e "SELECT @@global.super_read_only")
local current_user
current_user=$(mysql_retry -e "SELECT CURRENT_USER()")
local grants
grants=$(mysql_retry -e "SHOW GRANTS")

if ! mysql_retry -e 'CREATE TABLE IF NOT EXISTS mysql.role_check (id INT); DROP TABLE mysql.role_check;' >/dev/null 2>&1; then
log_info "MySQL variables before write test:"
log_info "Read only settings: ${mysql_vars}"
log_info "Super read only: ${super_read_only}"
log_info "Current user: ${current_user}"
log_info "Grants: ${grants}"

# Try to create test table with error capture
if ! error_output=$(mysql_retry -e 'CREATE TABLE IF NOT EXISTS mysql.role_check (id INT); DROP TABLE mysql.role_check;' 2>&1); then
status_details+=("write:failed")
log_error "MySQL cannot execute DDL (read_only status: ${read_only_status})"
log_error "MySQL cannot execute DDL"
log_error "Error output: ${error_output}"
log_error "Variables: ${mysql_vars}"
log_error "Super read only: ${super_read_only}"
log_error "Current user: ${current_user}"
errors=$((errors + 1))
else
status_details+=("write:ok")
log_info "Write test successful"
fi
else
status_details+=("write:skipped")
Expand Down

0 comments on commit 5fa5da5

Please sign in to comment.