-
Notifications
You must be signed in to change notification settings - Fork 469
[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
base: main
Are you sure you want to change the base?
Changes from all commits
38da392
de25429
cca98e9
0ffea20
dd47626
0dd0d70
c60fa3b
caecc78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
||
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 | ||
|
@@ -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;" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant as it is already there in |
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
There was a problem hiding this comment.
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.