Skip to content

[do-not-merge] mysql ci debug #14468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ binlog_do_db = mysql
gtid_mode = ON
enforce_gtid_consistency = ON
log_slave_updates = ON
tls_version = TLSv1.2,TLSv1.3
tls_version = TLSv1.2,TLSv1.3
68 changes: 51 additions & 17 deletions packages/mysql/_dev/deploy/docker/replica/entrypoint-replica.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,27 @@ echo "MySQL slave is ready."

# Configure the slave to start replication
echo "Configuring slave to start replication..."

# Wait for the master to be ready and for its logs to be available
MASTER_LOGS_AVAILABLE=false
for i in {1..30}; do
MS_STATUS=$(mysql -h "$MYSQL_MASTER_HOST" -P 3306 -u root -p"$MYSQL_ROOT_PASSWORD" -e "SHOW MASTER STATUS;")
echo "Attempt $i: Checking master status..."
MS_STATUS=$(mysql -h "$MYSQL_MASTER_HOST" -P 3306 -u root -p"$MYSQL_ROOT_PASSWORD" -e "SHOW MASTER STATUS;" 2>/dev/null || echo "FAILED")

if [ "$MS_STATUS" = "FAILED" ]; then
echo "Failed to connect to master, retrying..."
sleep 2
continue
fi

echo "Master status response: $MS_STATUS"

Comment on lines +23 to +33
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again better handling but with 2s delay before retrying.

CURRENT_LOG=$(echo "$MS_STATUS" | awk 'NR==2 {print $1}')
CURRENT_POS=$(echo "$MS_STATUS" | awk 'NR==2 {print $2}')

echo "Debug: CURRENT_LOG = '$CURRENT_LOG'"
echo "Debug: CURRENT_POS = '$CURRENT_POS'"

if [ -n "$CURRENT_LOG" ] && [ -n "$CURRENT_POS" ]; then
MASTER_LOGS_AVAILABLE=true
break
Expand All @@ -30,34 +45,53 @@ for i in {1..30}; do
sleep 2
fi
done

if [ "$MASTER_LOGS_AVAILABLE" = false ]; then
echo "Failed to obtain master log file and position."
exit 1
echo "Failed to obtain master log file and position."
exit 1
fi

echo "Master status obtained. Current log: $CURRENT_LOG, Current position: $CURRENT_POS."
echo "Master status obtained. Current log: '$CURRENT_LOG', Current position: '$CURRENT_POS'."

# Validate the values
if [ -z "$CURRENT_LOG" ] || [ -z "$CURRENT_POS" ]; then
echo "Error: Empty log file or position values"
exit 1
fi

# Reset the slave to ensure a clean replication setup
echo "Resetting the slave..."
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "STOP SLAVE; RESET SLAVE ALL;"
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "STOP SLAVE; RESET SLAVE ALL;" 2>/dev/null || echo "Slave was not running"

# Prepare the CHANGE MASTER TO command
start_slave_stmt="CHANGE MASTER TO MASTER_HOST='$MYSQL_MASTER_HOST', MASTER_USER='mydb_replica_user', MASTER_PASSWORD='mydb_replica_pwd', MASTER_LOG_FILE='$CURRENT_LOG', MASTER_LOG_POS=$CURRENT_POS; START SLAVE;"

# Display the command that will be executed
echo "Running the following command to start replication: $start_slave_stmt"
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" <<EOF
CHANGE MASTER TO
MASTER_HOST='$MYSQL_MASTER_HOST',
MASTER_USER='mydb_replica_user',
MASTER_PASSWORD='mydb_replica_pwd',
MASTER_LOG_FILE='$CURRENT_LOG',
MASTER_LOG_POS=$CURRENT_POS;
EOF

# Run the CHANGE MASTER TO command
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "$start_slave_stmt" || {
echo "Failed to start replication. Entering sleep mode for debugging."
tail -f /dev/null # This will keep the container running indefinitely
}
if [ $? -eq 0 ]; then
echo "CHANGE MASTER command executed successfully"

# Start the slave
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "START SLAVE;"

if [ $? -eq 0 ]; then
echo "Slave started successfully"
else
echo "Failed to start slave"
exit 1
fi
else
echo "Failed to execute CHANGE MASTER command"
exit 1
fi

# Verify slave status
echo "Verifying slave status..."
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "GRANT REPLICATION CLIENT ON *.* TO 'mydb_replica_user'@'%'; FLUSH PRIVILEGES;"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant as it is already there in grant-permissions.sql. Also the placement is wrong as GRANTs should be done before starting the slave.

mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "SHOW SLAVE STATUS \G"

# Now, keep the script running to prevent the container from exiting
wait
tail -f /dev/null
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
CREATE USER IF NOT EXISTS 'mydb_replica_user'@'%' IDENTIFIED BY 'mydb_replica_pwd';
GRANT REPLICATION SLAVE ON *.* TO 'mydb_replica_user'@'%';
GRANT REPLICATION CLIENT ON *.* TO 'mydb_replica_user'@'%';
Comment on lines +2 to 3
Copy link
Member Author

@shmsr shmsr Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REPLICATION CLIENT - This allows the user to execute SHOW MASTER STATUS and SHOW SLAVE STATUS commands

GRANT REPLICATION SLAVE - This allows the user to connect as a replica (START SLAVE)

FLUSH PRIVILEGES;
FLUSH PRIVILEGES;
5 changes: 5 additions & 0 deletions packages/mysql/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# newer versions go on top
- version: "1.27.1"
changes:
- description: Fix healthcheck.
type: enhancement
link: https://github.com/elastic/integrations/pull/99999
- version: "1.27.0"
changes:
- description: Add a flag `fips_compatible` to control whether the package is allowed in the ECH FedRAMP High environment.
Expand Down
2 changes: 1 addition & 1 deletion packages/mysql/manifest.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
format_version: "3.0.2"
name: mysql
title: MySQL
version: "1.27.0"
version: "1.27.1"
description: Collect logs and metrics from MySQL servers with Elastic Agent.
type: integration
categories:
Expand Down