diff --git a/cookbook/templates/replication-operations.gotxt b/cookbook/templates/replication-operations.gotxt index 18f51b8e..d08daea5 100644 --- a/cookbook/templates/replication-operations.gotxt +++ b/cookbook/templates/replication-operations.gotxt @@ -17,11 +17,21 @@ 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 -$sandbox_dir/m -e 'SHOW MASTER STATUS' +$sandbox_dir/m -e "$show_master_cmd" ) header "Creating a table in the master" @@ -54,7 +64,12 @@ header "Checking the status of all slaves" run $sandbox_dir/check_slaves header "Running a multiple query in all slaves" -(set -x -$sandbox_dir/use_all_slaves "STOP SLAVE; SET GLOBAL slave_parallel_workers=3; START SLAVE;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 + (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 ee28b295..c3f00467 100644 --- a/sandbox/sandbox.go +++ b/sandbox/sandbox.go @@ -712,6 +712,14 @@ func createSingleSandbox(sandboxDef SandboxDef) (execList []concurrent.Execution "HistoryDir": sandboxDef.HistoryDir, } + // Use version-appropriate replication syntax for connection info + 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 == "" { return emptyExecutionList, fmt.Errorf("task user defined but task role is empty") 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..5409bfdc 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" ]] || [[ "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,35 @@ then exit 1 fi +# MySQL 8.0.23+ renamed CHANGE MASTER TO parameters +minimum_version_change_source="008000023" +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" ]] || [[ "v$slave_sortable_version" == "v$minimum_version_change_source" ]] +then + 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 +258,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" ]] || [[ "v$slave_sortable_version" == "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