From 1cf6994f20a24d7319c6312fc6d77101c5c94dcd Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Mon, 23 Mar 2026 23:16:05 +0000 Subject: [PATCH 1/2] fix: update remaining templates for MySQL 8.4+ replication syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - replicate_from.gotxt: shell-based version detection for SHOW BINARY LOG STATUS, CHANGE REPLICATION SOURCE TO, START/STOP REPLICA - connection_info_sql.gotxt: use version-aware template variables - sandbox.go: add replication command fields to single sandbox data map - replication-operations.gotxt: version-aware SHOW MASTER STATUS and STOP/START SLAVE commands Tested with MySQL 8.4.4 and 9.1.0 — single and replication sandboxes both fully functional. --- .../templates/replication-operations.gotxt | 9 ++- sandbox/sandbox.go | 15 +++++ .../single/connection_info_sql.gotxt | 8 +-- sandbox/templates/single/replicate_from.gotxt | 55 +++++++++++++++---- 4 files changed, 72 insertions(+), 15 deletions(-) diff --git a/cookbook/templates/replication-operations.gotxt b/cookbook/templates/replication-operations.gotxt index 18f51b8e..eb6ad082 100644 --- a/cookbook/templates/replication-operations.gotxt +++ b/cookbook/templates/replication-operations.gotxt @@ -21,7 +21,10 @@ header "Running a simple command with the master in the sandbox." \ "Notice the usage of the '-e', as if we were using the 'mysql' client" (set -x -$sandbox_dir/m -e 'SHOW MASTER STATUS' +sortable_version=$(echo $version | awk -F. '{printf "%03d%03d%03d", $1, $2, $3}') +show_master_cmd="SHOW MASTER STATUS" +if [[ "v$sortable_version" > "v008002000" ]]; then show_master_cmd="SHOW BINARY LOG STATUS"; fi +$sandbox_dir/m -e "$show_master_cmd" ) header "Creating a table in the master" @@ -55,6 +58,10 @@ run $sandbox_dir/check_slaves header "Running a multiple query in all slaves" (set -x +if [[ "v$sortable_version" > "v008000022" ]]; then +$sandbox_dir/use_all_slaves "STOP REPLICA; SET GLOBAL replica_parallel_workers=3; START REPLICA;show processlist " +else $sandbox_dir/use_all_slaves "STOP SLAVE; SET GLOBAL slave_parallel_workers=3; START SLAVE;show processlist " +fi ) diff --git a/sandbox/sandbox.go b/sandbox/sandbox.go index ee28b295..3ff3a0fa 100644 --- a/sandbox/sandbox.go +++ b/sandbox/sandbox.go @@ -710,6 +710,21 @@ func createSingleSandbox(sandboxDef SandboxDef) (execList []concurrent.Execution "ReportHost": fmt.Sprintf("report-host=single-%d", sandboxDef.Port), "ReportPort": fmt.Sprintf("report-port=%d", sandboxDef.Port), "HistoryDir": sandboxDef.HistoryDir, + "ChangeMasterTo": "CHANGE MASTER TO", + "MasterHostParam": "master_host", + "MasterPortParam": "master_port", + "MasterUserParam": "master_user", + "MasterPasswordParam": "master_password", + } + + // Use version-appropriate replication syntax for connection info + useChangeSource, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion) + if useChangeSource { + data["ChangeMasterTo"] = "CHANGE REPLICATION SOURCE TO" + data["MasterHostParam"] = "source_host" + data["MasterPortParam"] = "source_port" + data["MasterUserParam"] = "source_user" + data["MasterPasswordParam"] = "source_password" } if sandboxDef.TaskUser != "" { diff --git a/sandbox/templates/single/connection_info_sql.gotxt b/sandbox/templates/single/connection_info_sql.gotxt index e0ebc73d..139aee67 100644 --- a/sandbox/templates/single/connection_info_sql.gotxt +++ b/sandbox/templates/single/connection_info_sql.gotxt @@ -1,5 +1,5 @@ -CHANGE MASTER TO master_host="{{.SbHost}}", -master_port={{.Port}}, -master_user="{{.RplUser}}", -master_password="{{.RplPassword}}" +{{.ChangeMasterTo}} {{.MasterHostParam}}="{{.SbHost}}", +{{.MasterPortParam}}={{.Port}}, +{{.MasterUserParam}}="{{.RplUser}}", +{{.MasterPasswordParam}}="{{.RplPassword}}" diff --git a/sandbox/templates/single/replicate_from.gotxt b/sandbox/templates/single/replicate_from.gotxt index c99e8d4c..a7b86a35 100644 --- a/sandbox/templates/single/replicate_from.gotxt +++ b/sandbox/templates/single/replicate_from.gotxt @@ -156,7 +156,15 @@ fi master_status=/tmp/mstatus$$ -$master_use_script -e 'show master status\G' > $master_status +# MySQL 8.2+ renamed SHOW MASTER STATUS to SHOW BINARY LOG STATUS +show_master_status_cmd="show master status" +minimum_version_binary_log="008002000" +if [[ "v$master_sortable_version" > "v$minimum_version_binary_log" ]] +then + show_master_status_cmd="show binary log status" +fi + +$master_use_script -e "$show_master_status_cmd\G" > $master_status binlog_file=$(grep File < $master_status | awk '{print $2}') binlog_pos=$(grep Position < $master_status | awk '{print $2}') rm -f $master_status @@ -210,21 +218,37 @@ then exit 1 fi +# MySQL 8.0.23+ renamed CHANGE MASTER TO parameters +minimum_version_change_source="008000023" +change_master_cmd="CHANGE MASTER TO" +auto_position_param="master_auto_position" +log_file_param="master_log_file" +log_pos_param="master_log_pos" +public_key_param="GET_MASTER_PUBLIC_KEY" +if [[ "v$slave_sortable_version" > "v$minimum_version_change_source" ]] +then + change_master_cmd="CHANGE REPLICATION SOURCE TO" + auto_position_param="source_auto_position" + log_file_param="source_log_file" + log_pos_param="source_log_pos" + public_key_param="GET_SOURCE_PUBLIC_KEY" +fi + if [ -n "$using_gtid" ] then - connection_string=$(cat $master_connection ; echo -n ", master_auto_position=1") -else - connection_string=$(cat $master_connection ; echo -n ', master_log_file="'$binlog_file'", master_log_pos='$binlog_pos ) + connection_string=$(cat $master_connection ; echo -n ", $auto_position_param=1") +else + connection_string=$(cat $master_connection ; echo -n ", $log_file_param=\"$binlog_file\", $log_pos_param=$binlog_pos" ) if [ -f clone_replication.sql ] then connection_string=$(cat $master_connection ; echo -n ", " ; cat clone_replication.sql) fi fi -# If master is 8.0, the slave must be at least 8.0 -if [ "$master_short_version" == "8.0" ] +# If master is 8.0+, need public key for caching_sha2_password +if [[ $master_major -ge 8 ]] then - connection_string="$connection_string, GET_MASTER_PUBLIC_KEY=1" + connection_string="$connection_string, $public_key_param=1" fi echo "Connecting to $master_path" @@ -236,12 +260,23 @@ if [ -f clone_replication.sql ] then rm -f clone_replication.sql fi -$SBDIR/use -v -e 'start slave' -$SBDIR/use -v -e 'SHOW SLAVE STATUS\G' | grep "\(Running:\|Master_Log_Pos\|\ "v$minimum_version_replica" ]] +then + start_replica_cmd="start replica" + show_replica_cmd="SHOW REPLICA STATUS" + stop_reset_cmd="stop replica; reset replica" +fi +$SBDIR/use -v -e "$start_replica_cmd" +$SBDIR/use -v -e "$show_replica_cmd\G" | grep "\(Running:\|Master_Log_Pos\|Source_Log_Pos\|\ $active_replication echo "Connected to $master_path" >> $active_replication echo "#!{{.ShellPath}}" > $remove_replication -echo "$SBDIR/use -v -e 'stop slave; reset slave'" >> $remove_replication +echo "$SBDIR/use -v -e '$stop_reset_cmd'" >> $remove_replication echo "rm -f $active_replication" >> $remove_replication chmod +x $remove_replication From 671aaa8506e3a8d1528ea36ad3963423e0d22e40 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Mon, 23 Mar 2026 23:27:57 +0000 Subject: [PATCH 2/2] fix: address code review feedback - Fix single-quote bug preventing $stop_reset_cmd expansion in remove_replication script (Gemini) - Fix boundary version comparisons to include exact version match using >= semantics (Copilot) - Remove unused change_master_cmd variable (Copilot) - Move sortable_version outside subshell in cookbook template (Copilot) - Use replicationCommands() in sandbox.go instead of duplicating version logic (Gemini) - Use named variables for magic version strings (Gemini) --- .../templates/replication-operations.gotxt | 28 ++++++++++++------- sandbox/sandbox.go | 19 ++++--------- sandbox/templates/single/replicate_from.gotxt | 10 +++---- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/cookbook/templates/replication-operations.gotxt b/cookbook/templates/replication-operations.gotxt index eb6ad082..d08daea5 100644 --- a/cookbook/templates/replication-operations.gotxt +++ b/cookbook/templates/replication-operations.gotxt @@ -17,13 +17,20 @@ fi sandbox_dir=$SANDBOX_HOME/rsandbox_$(echo $version | tr '.' '_' ) +# Version-aware SQL commands +sortable_version=$(echo "$version" | awk -F. '{printf "%03d%03d%03d", $1, $2, $3}') +minimum_version_binary_log="008002000" +minimum_version_replica="008000022" + +show_master_cmd="SHOW MASTER STATUS" +if [[ "v$sortable_version" > "v$minimum_version_binary_log" ]] || [[ "v$sortable_version" == "v$minimum_version_binary_log" ]]; then + show_master_cmd="SHOW BINARY LOG STATUS" +fi + header "Running a simple command with the master in the sandbox." \ - "Notice the usage of the '-e', as if we were using the 'mysql' client" + "Notice the usage of the '-e', as if we were using the 'mysql' client" (set -x -sortable_version=$(echo $version | awk -F. '{printf "%03d%03d%03d", $1, $2, $3}') -show_master_cmd="SHOW MASTER STATUS" -if [[ "v$sortable_version" > "v008002000" ]]; then show_master_cmd="SHOW BINARY LOG STATUS"; fi $sandbox_dir/m -e "$show_master_cmd" ) @@ -57,11 +64,12 @@ header "Checking the status of all slaves" run $sandbox_dir/check_slaves header "Running a multiple query in all slaves" -(set -x -if [[ "v$sortable_version" > "v008000022" ]]; then -$sandbox_dir/use_all_slaves "STOP REPLICA; SET GLOBAL replica_parallel_workers=3; START REPLICA;show processlist " +if [[ "v$sortable_version" > "v$minimum_version_replica" ]] || [[ "v$sortable_version" == "v$minimum_version_replica" ]]; then + (set -x + $sandbox_dir/use_all_slaves "STOP REPLICA; SET GLOBAL replica_parallel_workers=3; START REPLICA;show processlist " + ) else -$sandbox_dir/use_all_slaves "STOP SLAVE; SET GLOBAL slave_parallel_workers=3; START SLAVE;show processlist " + (set -x + $sandbox_dir/use_all_slaves "STOP SLAVE; SET GLOBAL slave_parallel_workers=3; START SLAVE;show processlist " + ) fi -) - diff --git a/sandbox/sandbox.go b/sandbox/sandbox.go index 3ff3a0fa..c3f00467 100644 --- a/sandbox/sandbox.go +++ b/sandbox/sandbox.go @@ -710,22 +710,15 @@ func createSingleSandbox(sandboxDef SandboxDef) (execList []concurrent.Execution "ReportHost": fmt.Sprintf("report-host=single-%d", sandboxDef.Port), "ReportPort": fmt.Sprintf("report-port=%d", sandboxDef.Port), "HistoryDir": sandboxDef.HistoryDir, - "ChangeMasterTo": "CHANGE MASTER TO", - "MasterHostParam": "master_host", - "MasterPortParam": "master_port", - "MasterUserParam": "master_user", - "MasterPasswordParam": "master_password", } // Use version-appropriate replication syntax for connection info - useChangeSource, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion) - if useChangeSource { - data["ChangeMasterTo"] = "CHANGE REPLICATION SOURCE TO" - data["MasterHostParam"] = "source_host" - data["MasterPortParam"] = "source_port" - data["MasterUserParam"] = "source_user" - data["MasterPasswordParam"] = "source_password" - } + replCmds := replicationCommands(sandboxDef.Version) + data["ChangeMasterTo"] = replCmds["ChangeMasterTo"] + data["MasterHostParam"] = replCmds["MasterHostParam"] + data["MasterPortParam"] = replCmds["MasterPortParam"] + data["MasterUserParam"] = replCmds["MasterUserParam"] + data["MasterPasswordParam"] = replCmds["MasterPasswordParam"] if sandboxDef.TaskUser != "" { if sandboxDef.TaskUserRole == "" { diff --git a/sandbox/templates/single/replicate_from.gotxt b/sandbox/templates/single/replicate_from.gotxt index a7b86a35..5409bfdc 100644 --- a/sandbox/templates/single/replicate_from.gotxt +++ b/sandbox/templates/single/replicate_from.gotxt @@ -159,7 +159,7 @@ master_status=/tmp/mstatus$$ # MySQL 8.2+ renamed SHOW MASTER STATUS to SHOW BINARY LOG STATUS show_master_status_cmd="show master status" minimum_version_binary_log="008002000" -if [[ "v$master_sortable_version" > "v$minimum_version_binary_log" ]] +if [[ "v$master_sortable_version" > "v$minimum_version_binary_log" ]] || [[ "v$master_sortable_version" == "v$minimum_version_binary_log" ]] then show_master_status_cmd="show binary log status" fi @@ -220,14 +220,12 @@ fi # MySQL 8.0.23+ renamed CHANGE MASTER TO parameters minimum_version_change_source="008000023" -change_master_cmd="CHANGE MASTER TO" auto_position_param="master_auto_position" log_file_param="master_log_file" log_pos_param="master_log_pos" public_key_param="GET_MASTER_PUBLIC_KEY" -if [[ "v$slave_sortable_version" > "v$minimum_version_change_source" ]] +if [[ "v$slave_sortable_version" > "v$minimum_version_change_source" ]] || [[ "v$slave_sortable_version" == "v$minimum_version_change_source" ]] then - change_master_cmd="CHANGE REPLICATION SOURCE TO" auto_position_param="source_auto_position" log_file_param="source_log_file" log_pos_param="source_log_pos" @@ -265,7 +263,7 @@ start_replica_cmd="start slave" show_replica_cmd="SHOW SLAVE STATUS" stop_reset_cmd="stop slave; reset slave" minimum_version_replica="008000022" -if [[ "v$slave_sortable_version" > "v$minimum_version_replica" ]] +if [[ "v$slave_sortable_version" > "v$minimum_version_replica" ]] || [[ "v$slave_sortable_version" == "v$minimum_version_replica" ]] then start_replica_cmd="start replica" show_replica_cmd="SHOW REPLICA STATUS" @@ -276,7 +274,7 @@ $SBDIR/use -v -e "$show_replica_cmd\G" | grep "\(Running:\|Master_Log_Pos\|Sourc date > $active_replication echo "Connected to $master_path" >> $active_replication echo "#!{{.ShellPath}}" > $remove_replication -echo "$SBDIR/use -v -e '$stop_reset_cmd'" >> $remove_replication +echo "$SBDIR/use -v -e \"$stop_reset_cmd\"" >> $remove_replication echo "rm -f $active_replication" >> $remove_replication chmod +x $remove_replication