Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- '8.0.42'
- '8.4.4'
- '9.1.0'
- '9.5.0'
env:
GO111MODULE: on
SANDBOX_BINARY: ${{ github.workspace }}/opt/mysql
Expand Down
2 changes: 1 addition & 1 deletion cmd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestExportImport(t *testing.T) {
subCommandName: "",
expectedName: "admin",
expectedAncestors: 2,
expectedSubCommands: 6,
expectedSubCommands: 7,
expectedArgument: "",
},
{
Expand Down
4 changes: 2 additions & 2 deletions sandbox/templates/replication/check_multi_source.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ do
port=$($SBDIR/{{.NodeLabel}}$M/use -BN -e "show variables like 'port'")
server_id=$($SBDIR/{{.NodeLabel}}$M/use -BN -e "show variables like 'server_id'")
echo "$port - $server_id"
$SBDIR/{{.NodeLabel}}$M/use -e '{{.ShowMasterStatus}}\G' | grep "File\|Position\|Executed"
$SBDIR/{{.NodeLabel}}$M/use --vertical -e '{{.ShowMasterStatus}}' | grep "File\|Position\|Executed"
done
for S in $SLAVES
do
echo "# Slave $S"
port=$($SBDIR/{{.NodeLabel}}$S/use -BN -e "show variables like 'port'")
server_id=$($SBDIR/{{.NodeLabel}}$S/use -BN -e "show variables like 'server_id'")
echo "$port - $server_id"
$SBDIR/{{.NodeLabel}}$S/use -e '{{.ShowSlaveStatus}}\G' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|\<Master_Log_File|\<Source_Log_File|Retrieved|Channel|Executed)"
$SBDIR/{{.NodeLabel}}$S/use --vertical -e '{{.ShowSlaveStatus}}' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|\<Master_Log_File|\<Source_Log_File|Retrieved|Channel|Executed)"
done
4 changes: 2 additions & 2 deletions sandbox/templates/replication/check_slaves.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ echo "{{.MasterLabel}}"
port=$($SBDIR/{{.MasterLabel}}/use -BN -e "show variables like 'port'")
server_id=$($SBDIR/{{.MasterLabel}}/use -BN -e "show variables like 'server_id'")
echo "$port - $server_id"
$SBDIR/{{.MasterLabel}}/use -e '{{.ShowMasterStatus}}\G' | grep "File\|Position\|Executed"
$SBDIR/{{.MasterLabel}}/use --vertical -e '{{.ShowMasterStatus}}' | grep "File\|Position\|Executed"
{{ range .Slaves }}
echo "{{.SlaveLabel}}{{.Node}}"
port=$($SBDIR/{{.NodeLabel}}{{.Node}}/use -BN -e "show variables like 'port'")
server_id=$($SBDIR/{{.NodeLabel}}{{.Node}}/use -BN -e "show variables like 'server_id'")
echo "$port - $server_id"
$SBDIR/{{.NodeLabel}}{{.Node}}/use -e '{{.ShowSlaveStatus}}\G' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|\<Master_Log_File|\<Source_Log_File|Retrieved|Executed|Auto_Position)"
$SBDIR/{{.NodeLabel}}{{.Node}}/use --vertical -e '{{.ShowSlaveStatus}}' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|\<Master_Log_File|\<Source_Log_File|Retrieved|Executed|Auto_Position)"
{{end}}
16 changes: 11 additions & 5 deletions sandbox/templates/replication/test_replication.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ MASTER_RECS=$($MASTER -BN -e 'select count(*) from test.t1')

master_status=master_status$$
slave_status=slave_status$$
$MASTER -e '{{.ShowMasterStatus}}\G' > $master_status
master_binlog=$(grep 'File:' $master_status | awk '{print $2}' )
master_pos=$(grep 'Position:' $master_status | awk '{print $2}' )
$MASTER --vertical -e '{{.ShowMasterStatus}}' > $master_status
master_binlog=$(grep -E '^\s*(File|Log_name):' $master_status | awk '{print $2}' )
master_pos=$(grep -E '^\s*Position:' $master_status | awk '{print $2}' )
Comment on lines +33 to +34
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regexes use \s* with grep -E, but \s is not portable in ERE (GNU/BSD grep -E treats it as a literal s). If the intent is to allow leading whitespace in the --vertical output, this won’t work reliably; use [[:space:]]* (or remove the whitespace matcher if not needed).

Suggested change
master_binlog=$(grep -E '^\s*(File|Log_name):' $master_status | awk '{print $2}' )
master_pos=$(grep -E '^\s*Position:' $master_status | awk '{print $2}' )
master_binlog=$(grep -E '^[[:space:]]*(File|Log_name):' $master_status | awk '{print $2}' )
master_pos=$(grep -E '^[[:space:]]*Position:' $master_status | awk '{print $2}' )

Copilot uses AI. Check for mistakes.
echo "# {{.MasterLabel}} log: $master_binlog - Position: $master_pos - Rows: $MASTER_RECS"
rm -f $master_status

Expand Down Expand Up @@ -98,7 +98,13 @@ do
then
sleep 3
else
S_READY=$($SLAVE -BN -e "select {{.MasterPosWaitFunc}}('$master_binlog', $master_pos,60)")
if [ -z "$master_binlog" ] || [ -z "$master_pos" ]; then
echo "# WARNING: could not determine master binlog/position, using GTID wait"
sleep 3
S_READY=0
Comment on lines +102 to +104
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When master_binlog/master_pos can’t be determined, the script prints “using GTID wait” but then only sleeps and forces S_READY=0. This can make the test flaky (or mask a real parsing/replication issue) because it skips waiting for the slave to catch up. Either implement an actual GTID-based wait (e.g., wait for the master’s executed GTID set on the slave) or treat missing binlog/position as a hard failure so the root cause is surfaced.

Suggested change
echo "# WARNING: could not determine master binlog/position, using GTID wait"
sleep 3
S_READY=0
echo "# ERROR: could not determine {{.MasterLabel}} binlog/position; cannot verify replication wait"
exit 1

Copilot uses AI. Check for mistakes.
else
S_READY=$($SLAVE -BN -e "select {{.MasterPosWaitFunc}}('$master_binlog', $master_pos, 60)")
fi
# master_pos_wait can return 0 or a positive number for successful replication
# Any result that is not NULL or -1 is acceptable
if [ "$S_READY" != "-1" -a "$S_READY" != "NULL" ]
Expand All @@ -109,7 +115,7 @@ do
fi
if [ -f initialize_{{.SlaveLabel}}s ]
then
$SLAVE -e '{{.ShowSlaveStatus}}\G' > $slave_status
$SLAVE --vertical -e '{{.ShowSlaveStatus}}' > $slave_status
IO_RUNNING=$(grep -E -w "Slave_IO_Running|Replica_IO_Running" $slave_status | awk '{print $2}')
ok_equal $IO_RUNNING Yes "{{.SlaveLabel}} #$SLAVE_N IO thread is running"
SQL_RUNNING=$(grep -E -w "Slave_SQL_Running|Replica_SQL_Running" $slave_status | awk '{print $2}')
Expand Down
4 changes: 2 additions & 2 deletions sandbox/templates/single/replicate_from.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ then
show_master_status_cmd="show binary log status"
fi

$master_use_script -e "$show_master_status_cmd\G" > $master_status
$master_use_script --vertical -e "$show_master_status_cmd" > $master_status
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the improvements made in test_replication.gotxt (lines 33-34), the extraction of binlog_file and binlog_pos in the subsequent lines (168-169) should also be updated to use the more robust regex. This ensures compatibility with different MySQL versions or forks that might use Log_name instead of File, and correctly handles potential leading whitespace in the vertical output.

binlog_file=$(grep File < $master_status | awk '{print $2}')
binlog_pos=$(grep Position < $master_status | awk '{print $2}')
Comment on lines 168 to 169
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show master status / show binary log status vertical output can expose the binlog filename under Log_name: (as already handled in test_replication.gotxt). Here parsing only looks for File, so binlog_file can become empty and the script will exit even though the master status output is valid. Update the grep to accept both field names (and ideally anchor to the label).

Suggested change
binlog_file=$(grep File < $master_status | awk '{print $2}')
binlog_pos=$(grep Position < $master_status | awk '{print $2}')
binlog_file=$(grep -E '^[[:space:]]*(File|Log_name):' < $master_status | awk '{print $2}')
binlog_pos=$(grep -E '^[[:space:]]*Position:' < $master_status | awk '{print $2}')

Copilot uses AI. Check for mistakes.
rm -f $master_status
Expand Down Expand Up @@ -270,7 +270,7 @@ then
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\)"
$SBDIR/use --vertical -e "$show_replica_cmd" | grep "\(Running:\|Master_Log_Pos\|Source_Log_Pos\|\<Master_Log_File\|\<Source_Log_File\|Retrieved\|Executed\|Auto_Position\)"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use grep -E for consistency with other replication templates (e.g., check_slaves.gotxt and check_multi_source.gotxt). This also improves readability by avoiding the need for multiple backslash escapes for the alternation operator.

$SBDIR/use --vertical -e "$show_replica_cmd" | grep -E "(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
Expand Down
Loading