Skip to content

fix: replace \G with --vertical in replication templates (MySQL 9.5 macOS compat)#76

Merged
renecannao merged 1 commit intomasterfrom
fix/replication-9.5-test-scripts
Apr 4, 2026
Merged

fix: replace \G with --vertical in replication templates (MySQL 9.5 macOS compat)#76
renecannao merged 1 commit intomasterfrom
fix/replication-9.5-test-scripts

Conversation

@renecannao
Copy link
Copy Markdown

@renecannao renecannao commented Apr 4, 2026

Problem

MySQL 9.5 client on macOS rejects \G in -e mode:

ERROR at line 1: Unknown command '\G'.

This breaks test_replication, check_slaves, check_multi_source, and replicate_from scripts.

Fix

Replace \G with --vertical flag in all 4 templates. --vertical produces identical output and works on all platforms/versions.

Also:

  • Made binlog name grep more robust (handles File or Log_name)
  • Added guard for empty binlog variables in source_pos_wait call
  • Added MySQL 9.5.0 to CI sandbox test matrix
  • Fixed export test count for admin ui subcommand

Test Plan

  • Build succeeds
  • Unit tests pass
  • CI: test_replication passes for 8.0.42, 8.4.4, 9.1.0, 9.5.0
  • Manual: macOS + MySQL 9.5.0

Summary by CodeRabbit

  • Tests

    • Extended integration test coverage to include MySQL version 9.5.0 for sandbox and InnoDB Cluster deployments.
    • Updated command structure expectations.
  • Improvements

    • Enhanced replication status query output formatting for improved consistency and reliability across deployment scenarios.

….5 compat)

MySQL 9.5 client rejects \G in -e mode with "Unknown command '\G'".
Replace all instances across templates with --vertical flag which
produces the same vertical output format.

Templates fixed:
- test_replication.gotxt — \G on show master/slave status
- check_slaves.gotxt — \G on show master/slave status
- check_multi_source.gotxt — \G on show master/slave status
- replicate_from.gotxt — \G on show master/replica status

Also:
- Made master binlog/position grep more robust (handles File/Log_name)
- Added guard for empty binlog name in source_pos_wait call
- Updated export test for admin ui subcommand count
Copilot AI review requested due to automatic review settings April 4, 2026 11:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR adds MySQL 9.5.0 to GitHub Actions CI test matrices, updates sandbox replication templates to use MySQL's --vertical output formatting flag instead of \G terminators, and adds conditional logic to handle missing binlog position data. It also updates a test expectation value.

Changes

Cohort / File(s) Summary
CI Workflow Configuration
.github/workflows/integration_tests.yml
Extended sandbox-test and innodb-cluster-test job matrices to include MySQL version 9.5.0, adding test coverage for this release.
Test Expectations
cmd/export_test.go
Updated expected subcommand count for admin command from 6 to 7 in TestExportImport.
Replication Template Output Formatting
sandbox/templates/replication/check_multi_source.gotxt, check_slaves.gotxt, sandbox/templates/single/replicate_from.gotxt
Replaced \G vertical formatting terminators with --vertical flag on MySQL use command invocations for both master and slave status queries.
Replication Status Collection and Control Flow
sandbox/templates/replication/test_replication.gotxt
Added --vertical flag for status output, updated binlog/position field parsing to match both File/Log_name columns with whitespace trimming, and introduced conditional logic that emits warning and skips wait query if binlog or position is empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 With vertical flags now standing tall,
The output formats answer the call,
Where \G once reigned, the flag takes its place,
And binlog positions find their new space,
MySQL 9.5.0 hops in to play,
Templates renewed for the modern day!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: replace \G with --vertical in replication templates (MySQL 9.5 macOS compat)' clearly and specifically describes the main change: replacing \G with --vertical for MySQL 9.5 macOS compatibility in replication templates.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/replication-9.5-test-scripts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@renecannao renecannao merged commit 7f7864f into master Apr 4, 2026
20 of 29 checks passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates several MySQL replication templates to use the --vertical flag instead of the \G terminator and increments the expected subcommand count in the export tests. It also enhances test_replication.gotxt with more robust parsing for master status and a safety check for missing binlog coordinates. Review feedback suggests applying these robust parsing improvements to replicate_from.gotxt and using grep -E for better consistency and readability across the templates.

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.

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)"

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates dbdeployer’s replication-related shell templates to avoid MySQL client \G usage in -e mode (notably failing on MySQL 9.5 on macOS), while also adjusting a few related parsing/CI/test expectations.

Changes:

  • Replaced \G query terminator usage with mysql --vertical across replication templates to restore cross-platform compatibility.
  • Improved binlog filename parsing in test_replication and added a guard against empty binlog/position values before calling master_pos_wait/source_pos_wait.
  • Added MySQL 9.5.0 to the GitHub Actions integration test matrix and updated an export structure test expectation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sandbox/templates/single/replicate_from.gotxt Switches master/replica status output to --vertical for compatibility.
sandbox/templates/replication/test_replication.gotxt Uses --vertical, tweaks binlog parsing, and guards pos-wait invocation.
sandbox/templates/replication/check_slaves.gotxt Uses --vertical for master/slave status output.
sandbox/templates/replication/check_multi_source.gotxt Uses --vertical for multi-source status output.
cmd/export_test.go Updates expected admin subcommand count.
.github/workflows/integration_tests.yml Extends CI matrix to include MySQL 9.5.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 168 to 169
binlog_file=$(grep File < $master_status | awk '{print $2}')
binlog_pos=$(grep Position < $master_status | awk '{print $2}')
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.
Comment on lines +33 to +34
master_binlog=$(grep -E '^\s*(File|Log_name):' $master_status | awk '{print $2}' )
master_pos=$(grep -E '^\s*Position:' $master_status | awk '{print $2}' )
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.
Comment on lines +102 to +104
echo "# WARNING: could not determine master binlog/position, using GTID wait"
sleep 3
S_READY=0
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants