Skip to content

Commit b94a174

Browse files
committed
fix: update remaining templates for MySQL 8.4+ replication syntax
- 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.
1 parent 0a505d2 commit b94a174

4 files changed

Lines changed: 72 additions & 15 deletions

File tree

cookbook/templates/replication-operations.gotxt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ header "Running a simple command with the master in the sandbox." \
2121
"Notice the usage of the '-e', as if we were using the 'mysql' client"
2222

2323
(set -x
24-
$sandbox_dir/m -e 'SHOW MASTER STATUS'
24+
sortable_version=$(echo $version | awk -F. '{printf "%03d%03d%03d", $1, $2, $3}')
25+
show_master_cmd="SHOW MASTER STATUS"
26+
if [[ "v$sortable_version" > "v008002000" ]]; then show_master_cmd="SHOW BINARY LOG STATUS"; fi
27+
$sandbox_dir/m -e "$show_master_cmd"
2528
)
2629

2730
header "Creating a table in the master"
@@ -55,6 +58,10 @@ run $sandbox_dir/check_slaves
5558

5659
header "Running a multiple query in all slaves"
5760
(set -x
61+
if [[ "v$sortable_version" > "v008000022" ]]; then
62+
$sandbox_dir/use_all_slaves "STOP REPLICA; SET GLOBAL replica_parallel_workers=3; START REPLICA;show processlist "
63+
else
5864
$sandbox_dir/use_all_slaves "STOP SLAVE; SET GLOBAL slave_parallel_workers=3; START SLAVE;show processlist "
65+
fi
5966
)
6067

sandbox/sandbox.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,21 @@ func createSingleSandbox(sandboxDef SandboxDef) (execList []concurrent.Execution
710710
"ReportHost": fmt.Sprintf("report-host=single-%d", sandboxDef.Port),
711711
"ReportPort": fmt.Sprintf("report-port=%d", sandboxDef.Port),
712712
"HistoryDir": sandboxDef.HistoryDir,
713+
"ChangeMasterTo": "CHANGE MASTER TO",
714+
"MasterHostParam": "master_host",
715+
"MasterPortParam": "master_port",
716+
"MasterUserParam": "master_user",
717+
"MasterPasswordParam": "master_password",
718+
}
719+
720+
// Use version-appropriate replication syntax for connection info
721+
useChangeSource, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion)
722+
if useChangeSource {
723+
data["ChangeMasterTo"] = "CHANGE REPLICATION SOURCE TO"
724+
data["MasterHostParam"] = "source_host"
725+
data["MasterPortParam"] = "source_port"
726+
data["MasterUserParam"] = "source_user"
727+
data["MasterPasswordParam"] = "source_password"
713728
}
714729

715730
if sandboxDef.TaskUser != "" {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
CHANGE MASTER TO master_host="{{.SbHost}}",
3-
master_port={{.Port}},
4-
master_user="{{.RplUser}}",
5-
master_password="{{.RplPassword}}"
2+
{{.ChangeMasterTo}} {{.MasterHostParam}}="{{.SbHost}}",
3+
{{.MasterPortParam}}={{.Port}},
4+
{{.MasterUserParam}}="{{.RplUser}}",
5+
{{.MasterPasswordParam}}="{{.RplPassword}}"

sandbox/templates/single/replicate_from.gotxt

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,15 @@ fi
156156

157157
master_status=/tmp/mstatus$$
158158

159-
$master_use_script -e 'show master status\G' > $master_status
159+
# MySQL 8.2+ renamed SHOW MASTER STATUS to SHOW BINARY LOG STATUS
160+
show_master_status_cmd="show master status"
161+
minimum_version_binary_log="008002000"
162+
if [[ "v$master_sortable_version" > "v$minimum_version_binary_log" ]]
163+
then
164+
show_master_status_cmd="show binary log status"
165+
fi
166+
167+
$master_use_script -e "$show_master_status_cmd\G" > $master_status
160168
binlog_file=$(grep File < $master_status | awk '{print $2}')
161169
binlog_pos=$(grep Position < $master_status | awk '{print $2}')
162170
rm -f $master_status
@@ -210,21 +218,37 @@ then
210218
exit 1
211219
fi
212220

221+
# MySQL 8.0.23+ renamed CHANGE MASTER TO parameters
222+
minimum_version_change_source="008000023"
223+
change_master_cmd="CHANGE MASTER TO"
224+
auto_position_param="master_auto_position"
225+
log_file_param="master_log_file"
226+
log_pos_param="master_log_pos"
227+
public_key_param="GET_MASTER_PUBLIC_KEY"
228+
if [[ "v$slave_sortable_version" > "v$minimum_version_change_source" ]]
229+
then
230+
change_master_cmd="CHANGE REPLICATION SOURCE TO"
231+
auto_position_param="source_auto_position"
232+
log_file_param="source_log_file"
233+
log_pos_param="source_log_pos"
234+
public_key_param="GET_SOURCE_PUBLIC_KEY"
235+
fi
236+
213237
if [ -n "$using_gtid" ]
214238
then
215-
connection_string=$(cat $master_connection ; echo -n ", master_auto_position=1")
216-
else
217-
connection_string=$(cat $master_connection ; echo -n ', master_log_file="'$binlog_file'", master_log_pos='$binlog_pos )
239+
connection_string=$(cat $master_connection ; echo -n ", $auto_position_param=1")
240+
else
241+
connection_string=$(cat $master_connection ; echo -n ", $log_file_param=\"$binlog_file\", $log_pos_param=$binlog_pos" )
218242
if [ -f clone_replication.sql ]
219243
then
220244
connection_string=$(cat $master_connection ; echo -n ", " ; cat clone_replication.sql)
221245
fi
222246
fi
223247

224-
# If master is 8.0, the slave must be at least 8.0
225-
if [ "$master_short_version" == "8.0" ]
248+
# If master is 8.0+, need public key for caching_sha2_password
249+
if [[ $master_major -ge 8 ]]
226250
then
227-
connection_string="$connection_string, GET_MASTER_PUBLIC_KEY=1"
251+
connection_string="$connection_string, $public_key_param=1"
228252
fi
229253

230254
echo "Connecting to $master_path"
@@ -236,12 +260,23 @@ if [ -f clone_replication.sql ]
236260
then
237261
rm -f clone_replication.sql
238262
fi
239-
$SBDIR/use -v -e 'start slave'
240-
$SBDIR/use -v -e 'SHOW SLAVE STATUS\G' | grep "\(Running:\|Master_Log_Pos\|\<Master_Log_File\|Retrieved\|Executed\|Auto_Position\)"
263+
# MySQL 8.0.22+ renamed START/STOP/SHOW SLAVE to REPLICA
264+
start_replica_cmd="start slave"
265+
show_replica_cmd="SHOW SLAVE STATUS"
266+
stop_reset_cmd="stop slave; reset slave"
267+
minimum_version_replica="008000022"
268+
if [[ "v$slave_sortable_version" > "v$minimum_version_replica" ]]
269+
then
270+
start_replica_cmd="start replica"
271+
show_replica_cmd="SHOW REPLICA STATUS"
272+
stop_reset_cmd="stop replica; reset replica"
273+
fi
274+
$SBDIR/use -v -e "$start_replica_cmd"
275+
$SBDIR/use -v -e "$show_replica_cmd\G" | grep "\(Running:\|Master_Log_Pos\|Source_Log_Pos\|\<Master_Log_File\|\<Source_Log_File\|Retrieved\|Executed\|Auto_Position\)"
241276
date > $active_replication
242277
echo "Connected to $master_path" >> $active_replication
243278
echo "#!{{.ShellPath}}" > $remove_replication
244-
echo "$SBDIR/use -v -e 'stop slave; reset slave'" >> $remove_replication
279+
echo "$SBDIR/use -v -e '$stop_reset_cmd'" >> $remove_replication
245280
echo "rm -f $active_replication" >> $remove_replication
246281
chmod +x $remove_replication
247282

0 commit comments

Comments
 (0)