-
Notifications
You must be signed in to change notification settings - Fork 1
Fix remaining templates for MySQL 8.4+ replication syntax #23
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
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 " | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
+74
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. 🧩 Analysis chain🏁 Script executed: fd -t f "replication-operations.gotxt" --exec cat -n {} \; | head -100Repository: ProxySQL/dbdeployer Length of output: 2815 🌐 Web query:
💡 Result: In MySQL 8.0.22 release notes, the statements START SLAVE, STOP SLAVE, SHOW SLAVE STATUS, SHOW SLAVE HOSTS, and RESET SLAVE are deprecated. New aliases START REPLICA, STOP REPLICA, SHOW REPLICA STATUS, SHOW REPLICAS, and RESET REPLICA are introduced as replacements. These new statements function identically to the old ones, with only terminology changes to use "replica" instead of "slave". The old statements still work but emit deprecation warnings. Corresponding status variables like Com_slave_start are aliased to Com_replica_start. Citations:
🌐 Web query:
💡 Result: Yes, the replica_parallel_workers system variable is available in MySQL 8.0.26. It was introduced in this version as the replacement for the deprecated slave_parallel_workers variable. In MySQL 8.0.26, the default value is 0 (single-threaded replication by default). The variable enables multithreaded replication on replicas, setting the number of parallel applier worker threads (plus a coordinator thread). Values range from 0 to 1024, and it is dynamic (can be changed at runtime). For multi-channel replication, the setting applies per channel. From MySQL 8.0.27 onward, the default changed to 4. Citations:
Gate
Suggested fix minimum_version_binary_log="008002000"
minimum_version_replica="008000022"
+minimum_version_replica_parallel_workers="008000026"
@@
if [[ "v$sortable_version" > "v$minimum_version_replica" ]] || [[ "v$sortable_version" == "v$minimum_version_replica" ]]; then
+ parallel_workers_var="slave_parallel_workers"
+ if [[ "v$sortable_version" > "v$minimum_version_replica_parallel_workers" ]] || [[ "v$sortable_version" == "v$minimum_version_replica_parallel_workers" ]]; then
+ parallel_workers_var="replica_parallel_workers"
+ fi
(set -x
- $sandbox_dir/use_all_slaves "STOP REPLICA; SET GLOBAL replica_parallel_workers=3; START REPLICA;show processlist "
+ $sandbox_dir/use_all_slaves "STOP REPLICA; SET GLOBAL ${parallel_workers_var}=3; START REPLICA;show processlist "
)
else📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}}" | ||
|
Comment on lines
+2
to
+5
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ] | ||
|
Comment on lines
+237
to
240
|
||
| then | ||
| connection_string=$(cat $master_connection ; echo -n ", " ; cat clone_replication.sql) | ||
| fi | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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\|\<Master_Log_File\|Retrieved\|Executed\|Auto_Position\)" | ||
| # MySQL 8.0.22+ renamed START/STOP/SHOW SLAVE to REPLICA | ||
| 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" ]] || [[ "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\|\<Master_Log_File\|\<Source_Log_File\|Retrieved\|Executed\|Auto_Position\)" | ||
| date > $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 | ||
|
|
||
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.
sortable_versionis computed inside the first( ... )subshell, so it won’t be available in the later subshell at lines 61-65. That makes theif [[ "v$sortable_version" ... ]]check effectively compare an empty value and will pick the wrong branch on newer MySQL versions. Move thesortable_version=...computation outside the subshells (once, near the top) so it can be reused reliably.