Skip to content

fix(mysql): make PITR disk-pressure binlog cleanup functional and prefix-safe#3088

Draft
weicao wants to merge 4 commits into
mainfrom
helios/mysql-pitr-binlog-cleanup
Draft

fix(mysql): make PITR disk-pressure binlog cleanup functional and prefix-safe#3088
weicao wants to merge 4 commits into
mainfrom
helios/mysql-pitr-binlog-cleanup

Conversation

@weicao

@weicao weicao commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #3087.

Three changes, all inside cleanup_mysql_binlogs:

  1. Replica discovery that works in a DP job pod: new get_replica_hosts queries the target primary (SHOW REPLICAS, falling back to SHOW SLAVE HOSTS for 5.7) — replicas register their report_host there. Replaces the dead KB_ITS_*_HOSTNAME env scan (both call sites).
  2. Prefix-safe master purge: PURGE BINARY LOGS TO deletes everything before the named file, so the scan stops at the first file that must be kept (not synced+uploaded, or within the newest 5 — the old code actually kept 4) and issues one PURGE TO for the safe prefix. The old per-file loop could delete an unarchived binlog and break PITR continuity.
  3. Exact-match membership tests (grep -Fxq over newline lists) instead of substring grep -q.

Conservative boundary kept: if no replica can be confirmed (query failure or zero registered replicas), master purge is still skipped, same as before.

Validation: bash -n pass. Runtime matrix for the mysql team via kubeblocks-tests before undraft: multi-replica cluster at >=80% disk — purge executes and keeps unarchived+newest files; replica lagging — purge stops before its sync point; orchestrator/replica down — cleanup skips; 5.7 path uses SHOW SLAVE HOSTS.

🤖 Generated with Claude Code

…fix-safe

Replica discovery relied on KB_ITS_*_HOSTNAME env that never existed in
DataProtection job pods on KB 1.x, so the >=80% disk cleanup (default
PURGE_BINLOG=on) silently never purged anything. Discover replicas from
the target primary via SHOW REPLICAS / SHOW SLAVE HOSTS instead.

Also make the master purge prefix-safe: PURGE BINARY LOGS TO is prefix
deletion, so scan stops at the first file that must be kept (not yet
synced+uploaded, or one of the newest 5) and a single PURGE TO that
file is issued - the old per-file loop could delete an unarchived
binlog sitting before a qualifying one and tear the archived sequence.
Membership tests are now exact-match instead of substring grep.

Fixes #3087

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (35e0ded) to head (0db099b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3088   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        144     144           
  Lines      23013   23013           
=====================================
  Misses     23013   23013           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

wei and others added 3 commits July 7, 2026 19:02
The disk-pressure binlog purge only triggers at >=80% usage, which cannot
be safely reached on a large shared host volume in tests (would need a
~177GB fill). Make the threshold overridable via PURGE_BINLOG_DISK_THRESHOLD
(default 80, production behaviour unchanged) so a test can set it below the
current usage and exercise the real purge path without filling the disk.

Refs #3087

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
get_synced_binlogs matched replica status against a reconstructed
${DP_TARGET_POD_NAME}-bin, which fails when the target env drifts from
the actual binlog-writing pod (e.g. after a switchover) - returning
'No synced binlog files found' even when replicas are synced. Match
against LOG_PREFIX (derived from the real log_bin_basename) instead.
Add DEBUG lines printing DP_TARGET_POD_NAME/LOG_PREFIX/replica hosts and
per-replica resolved current_file, so the cleanup-decision path is
observable in the archive-binlog log.

Refs #3087

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…stderr

get_replica_hosts assumed replicas register report_host, but the semisync
cmpd start command omits --report-host (only the MGR cmpd and
mysql-entrypoint.sh set it). With report_host empty, SHOW REPLICAS leaves the
Host column blank and `awk '{print $2}'` slides onto the Port, returning
"3306" as the replica host (observed: 'Processing replica host: 3306',
'Can't connect to MySQL server on 3306:3306'). Discover connected replicas
from the primary's own Binlog Dump threads instead
(information_schema.PROCESSLIST), which carry the replica ip:port regardless
of report_host; strip the ephemeral :port. Fall back to SHOW REPLICAS / SHOW
SLAVE HOSTS with TAB-split awk so an empty Host stays empty instead of
becoming the Port.

Also move the two DEBUG lines in get_synced_binlogs to stderr: that
function's stdout is captured by `synced_binlogs=$(get_synced_binlogs)`, so
echoing on stdout both hid the lines from the pod log and corrupted the
return value (making the empty result look non-empty and bypassing the
fail-closed 'No synced binlog files found' guard).

Split the `local synced_binlogs=$(...)` declaration from its assignment so
the `$? -ne 0` check reflects get_synced_binlogs' exit code rather than the
always-zero exit of `local`, keeping the fail-closed guard closed.

Refs #3087

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@weicao weicao added the nopick Not auto cherry-pick when PR merged label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nopick Not auto cherry-pick when PR merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mysql: PITR disk-pressure binlog cleanup is a silent no-op (dead KB_ITS env) with a latent purge-gap defect

2 participants