You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "DanielLeens (via GitHub)" <gi...@apache.org> on 2026/04/20 06:55:11 UTC
Re: [PR] [Improve][MySQL-CDC] Enhance diagnostics for missing binlog and GTID during restore [seatunnel]
DanielLeens commented on PR #10566:
URL: https://github.com/apache/seatunnel/pull/10566#issuecomment-4278475960
Hi @zhangshenghang, I pulled this PR locally and reviewed it against the current `dev` baseline. Thanks for improving this area; missing binlog / purged GTID restore failures are painful in production because the original exception tells users that the offset is gone, but not whether the root cause is retention, a different MySQL instance, replica lag, or GTID purge.
Local branch: `seatunnel-review-10566`
Head reviewed: `cf3a7d15acea0aa4ed7635598c01c04a6d48ecf8`
Base checked: `upstream/dev`, merge-base `34a57c70bc06e13e0d2e07cdcda7f3d67ba2e559`
Diff checked: 2 files, `+563/-3`
Local merge check: no current `dev` conflicts reproduced with `git merge-tree`
What this PR fixes:
- User pain: when a MySQL-CDC job restores from checkpoint/savepoint and the required binlog or GTID set is no longer available, users only see a generic restore/startup failure and have to manually inspect MySQL state.
- Fix approach: the PR keeps the existing failure behavior, but adds diagnostic logging around the failing offset: restored source info, Debezium target host/port, MySQL identity, binlog retention variables, master status, replica/slave status, and binlog range analysis.
- In one sentence: this PR does not make missing binlogs recoverable, but it makes the failure much easier to diagnose correctly.
A simple example:
```text
Saved offset: mysql-bin.000123:4567
Current server has: mysql-bin.000200 ... mysql-bin.000205
Before:
"The connector is trying to read binlog starting at ..., but this is no longer available"
After:
The same failure is still thrown, but logs also explain that mysql-bin.000123
is older than the earliest available file, which strongly points to binlog purge/expiration.
```
Runtime path checked:
```text
Zeta restore / MySQL-CDC reader startup
-> Source task restore/open path
-> MySqlSourceFetchTaskContext.configure(sourceSplitBase) [MySqlSourceFetchTaskContext.java:L123-L193]
-> loadStartingOffsetState(new MySqlOffsetContext.Loader(...), sourceSplitBase) [L282-L300]
-> getInitOffset(mySqlSplit) for incremental split [L302-L314]
-> loader.load(offset.getOffset()) [L290]
-> isBinlogAvailable(mySqlOffsetContext) [L292, L317-L324]
Binlog-file offset path
-> checkBinlogFilename(offset) [L326-L350]
-> binlog filename is null/empty
-> keep legacy behavior and return true [L327-L333]
-> connection.availableBinlogFiles() [L336]
-> if required file is missing
-> warn with summarized available binlogs [L340-L345]
-> logBinlogNotAvailableDiagnostics(...) [L410-L427]
-> log restored sourceInfo and configured target host/port
-> SELECT @@hostname/@@port/@@server_id/@@server_uuid/read_only/super_read_only/version/gtid_mode [L444-L472]
-> SHOW VARIABLES for log_bin/binlog_format/binlog_expire_logs_seconds/expire_logs_days [L475-L503]
-> SHOW MASTER STATUS [L505-L527]
-> SHOW REPLICA STATUS, fallback to SHOW SLAVE STATUS on SQL error [L530-L591]
-> parse available binlog sequence range and classify older/newer/missing-in-range [L593-L643]
-> return false
-> loadStartingOffsetState throws IllegalStateException with existing restore guidance [L292-L298]
GTID offset path
-> checkGtidSet(offset) [L352-L408]
-> connection.knownGtidSet()
-> if server has no GTID set, or restored GTID is not available/non-purged
-> logGtidNotAvailableDiagnostics(offset) [L429-L442]
-> return false
-> loadStartingOffsetState throws the same restore failure
```
## Core code change snippets
Before this PR, a missing binlog only logged the raw available file list:
```java
boolean found = logNames.stream().anyMatch(binlogFilename::equals);
if (!found) {
LOG.info(
"Connector requires binlog file '{}', but MySQL only has {}",
binlogFilename,
String.join(", ", logNames));
} else {
LOG.info("MySQL has the binlog file '{}' required by the connector", binlogFilename);
}
return found;
```
After this PR, the same failure path summarizes the file list and emits targeted diagnostics:
```java
boolean found = logNames.stream().anyMatch(binlogFilename::equals);
if (!found) {
LOG.warn(
"Connector requires binlog file '{}', but it is not available on the connected MySQL server. {}",
binlogFilename,
summarizeBinlogFiles(logNames));
logBinlogNotAvailableDiagnostics(binlogFilename, logNames, offset);
} else {
LOG.info("MySQL has the binlog file '{}' required by the connector", binlogFilename);
}
return found;
```
The GTID path also now logs diagnostics before returning false:
```java
if (availableGtidStr == null || availableGtidStr.trim().isEmpty()) {
LOG.warn(
"Connector used GTIDs previously, but MySQL does not know of any GTIDs or they are not enabled");
logGtidNotAvailableDiagnostics(offset);
return false;
}
...
if (!gtidSetToReplicate.equals(nonPurgedGtidSetToReplicate)) {
LOG.warn("Some of the GTIDs needed to replicate have been already purged");
logGtidNotAvailableDiagnostics(offset);
return false;
}
```
## Findings
I did not find a blocking code issue in this PR.
Important observations:
- The normal healthy path does not run the extra diagnostic SQL. The new methods only run after `checkBinlogFilename()` or `checkGtidSet()` has already determined that the restored offset cannot be served.
- The PR preserves the existing failure contract: `loadStartingOffsetState()` still throws `IllegalStateException` when the required binlog/GTID is unavailable. It only improves the evidence emitted before the failure.
- The added SQL calls are best-effort and individually protected with `SQLException` handling, so missing permissions or unsupported statements should not hide the original restore failure.
- The binlog summary avoids logging an unbounded list of binlog files by sampling head/tail entries, which is a good production-safety choice.
One non-blocking suggestion: the new helper logic (`parseBinlogFileNumber`, `summarizeBinlogFiles`, and the older/newer/in-range classification) is only covered indirectly through the E2E test. A small unit test around these helpers would make future refactors safer, but I would not block this PR on that because the behavior is diagnostic-only and the main restore failure path has E2E coverage.
## CI status
The visible PR checks are green on the reviewed head:
```text
Build: SUCCESS
Notify test workflow: SUCCESS
labeler: SUCCESS
```
Note that these checks are from March 2026. I also checked the current base locally with `git merge-tree` and did not reproduce a merge conflict.
## Compatibility / side effects
- API: no public API or connector SPI contract is changed.
- Config: no new config option is introduced.
- Defaults: unchanged.
- Protocol / serialization: unchanged.
- Historical behavior: restore still fails when the offset is no longer available; the user-visible change is richer logging.
- CPU / memory / GC: no impact on the normal path. On failure, the extra diagnostics run a small number of SQL queries and allocate short log strings/lists.
- Network: only failure-path diagnostic SQL round trips are added.
- Locks / concurrency: no shared mutable state is introduced; helper variables are local to the failing restore check.
- Retry / idempotency: diagnostics are read-only SQL, except for the E2E test setup itself. Runtime diagnostics do not mutate MySQL state.
- Resource release: unchanged; connection and binary log client closure remain in the existing `close()` path.
## Error handling and logging
The error handling is appropriate for a diagnostic path: individual diagnostic query failures are logged and do not replace the original restore failure. The log content avoids passwords and tokens; it reports host, port, server identity, binlog variables, master status, and GTID/binlog state, which are useful for operations.
The WARN level is acceptable here because these diagnostics are emitted only after restore has already detected an unavailable offset, not during the healthy path.
## Tests and docs
- The new E2E test starts a MySQL container, runs a CDC job, savepoints it, purges the required binlog, restores the job, expects restore failure, and asserts that diagnostic logs include MySQL identity plus a missing-binlog/GTID indicator.
- The test is Zeta-only, consistent with the restore capability currently being disabled for Spark/Flink in the test annotation.
- No docs update is required for this PR because it does not add a user-facing config or command. The improvement is operational logging for an existing failure path.
## Merge conclusion
### Conclusion: can merge
Blocking items:
- None.
Recommended fixes:
- Add focused unit tests for the helper parsing/range-summary methods when convenient. This is a maintainability improvement, not a merge blocker.
Overall evaluation:
This is a precise, low-risk diagnostic improvement. It keeps the restore lifecycle and failure semantics unchanged, adds useful MySQL-side evidence only on the failing path, and includes an E2E regression test for the missing-binlog restore scenario. I think this PR can be merged once the community is comfortable with the CI status.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org