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/21 04:16:03 UTC
Re: [PR] [Fix][Connector-V2] Fix JDBC sink reconnect for nested batch exceptions [seatunnel]
DanielLeens commented on PR #10793:
URL: https://github.com/apache/seatunnel/pull/10793#issuecomment-4285883924
Hi @davidzollo, thanks for the careful JDBC retry fix. I reviewed the latest PR head locally from the full diff and the actual JDBC sink flush path.
# What This PR Fixes
- User pain point: when JDBC `executeBatch()` throws a `BatchUpdateException`, the real connection or statement failure can be hidden in `nextException` or the cause chain. The old code only checked `connectionProvider.isConnectionValid()`, so a still-valid connection with a closed/invalid prepared statement could keep retrying with the wrong executor state.
- Fix approach: after a flush `SQLException`, the PR collects SQLExceptions from both the cause chain and `nextException` chain. It refreshes the executor when it sees SQLState `08xxx`, statement-closed signals, or an invalid connection.
- One-line summary: JDBC sink retry can now recognize nested batch failure signals and rebuild the statement before retrying.
# 1. Code Change Review
## 1.1 Core Logic Analysis
Local review info:
- Local review ref: `refs/pr-review-batch/seatunnel-pr-review-2/10793`
- Local branch name: `seatunnel-review-10793`
- PR HEAD: `d83f8c81a5a28ce6500c41e69fdd706e79c2db23`
- Merge base: `6d2a10465954bc4235b9c86a62128511283a6bb5`
- Core file: `seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcOutputFormat.java:123-290`
- Test file: `seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcOutputFormatReconnectTest.java:33-145`
Before:
```java
if (!connectionProvider.isConnectionValid()) {
updateExecutor(true);
}
```
After:
```java
if (shouldRefreshExecutor(findSqlExceptions(e))) {
updateExecutor(true);
}
```
New decision point:
```java
private boolean shouldRefreshExecutor(List<SQLException> sqlExceptions) throws SQLException {
return hasConnectionErrorSqlState(sqlExceptions)
|| isStatementClosed(sqlExceptions)
|| !connectionProvider.isConnectionValid();
}
```
Full runtime path:
```text
Sink writer receives SeaTunnelRow
-> JdbcOutputFormat.writeRecord(record) [JdbcOutputFormat.java:99-114]
-> addToBatch(record)
-> batchCount++
-> batch size / interval threshold triggers flush()
Flush phase
-> JdbcOutputFormat.flush() [JdbcOutputFormat.java:123-165]
-> attemptFlush() [168-170]
-> jdbcStatementExecutor.executeBatch()
-> SQLException
-> findSqlExceptions(e)
-> walk the cause chain
-> for each SQLException, walk nextException as well
-> shouldRefreshExecutor(...)
-> SQLState 08xxx means connection failure
-> statement-closed class/message means current statement is invalid
-> fallback to connectionProvider.isConnectionValid()
-> updateExecutor(true) [219-231]
-> close old statements
-> connectionProvider.reestablishConnection()
-> jdbcStatementExecutor.prepareStatements(newConnection)
-> sleep and retry attemptFlush()
```
Key findings:
- The normal JDBC sink write path does hit this code during batch flush retry.
- The PR specifically covers driver behavior where the outer `BatchUpdateException` is generic but the nested SQLException carries the useful signal.
- The successful flush path is unchanged.
- Current CI is not in a merge-ready state yet, so I would wait for a green final run before merging.
Local command results:
- PR queue command returned 122 PRs; GraphQL `issueCount` also returned 122.
- `git fetch upstream pull/10793/head:refs/pr-review-batch/seatunnel-pr-review-2/10793`: succeeded.
- `git diff --stat`: 2 files, `+212/-1`.
- `git diff --unified=80`: confirmed the production change is limited to retry classification plus tests.
- `rg "new BufferedBatchStatementExecutor|new BufferReducedBatchStatementExecutor|new SimpleBatchStatementExecutor" ...`: confirmed the normal builder path uses buffered executors around statement execution, so retry can preserve the pending batch boundary.
- `gh pr checks` / check-run API: current Build is not finally green; the fork-side run still has queued jobs.
- I did not run local tests; this is source-level review as requested.
## 1.2 Compatibility Impact
Compatibility: fully compatible.
- API/config/defaults/protocol/serialization: unchanged.
- Historical behavior: successful writes are unchanged; failed flush retries get a more accurate refresh decision.
## 1.3 Performance / Side Effects
No impact on successful flushes. On exception paths, the new code allocates a small `ArrayList` and walks cause/nextException chains, which is appropriate for retry handling. `flush()` remains synchronized. Reconnect still uses the existing `updateExecutor(true)` resource path.
## 1.4 Error Handling And Logs
Issue 1: CI has not reached a merge-ready green state
- Location: GitHub check run `72126310088` / fork run `24666727835`
- Problem: the visible Build check is not finally green, and fork-side jobs are still queued. Because this PR touches JDBC sink flush retry, CI should complete before merge.
- Risk: merging before the JDBC-related test signal is available could hide a retry regression.
- Suggested fix: wait for the current run to finish; if it fails, inspect connector-jdbc and updated-modules integration logs first.
- Severity: Medium
# 2. Code Quality
## 2.1 Style
The code is focused and readable. The helper methods have clear boundaries.
## 2.2 Tests
The new tests cover SQLState `08006` nested inside `BatchUpdateException.nextException` and a statement-closed nested exception. Non-blocking suggestion: add one cause-chain test as well, so `findSqlExceptions()` is fully covered.
## 2.3 Documentation
No docs update is needed. This is internal retry behavior, not a user-facing option.
# 3. Architecture
## 3.1 Solution Quality
This is a precise fix at the shared JDBC output-format layer, so all JDBC dialects benefit without duplicating driver-specific retry logic.
## 3.2 Maintainability
The decision logic is isolated and easy to extend if another driver exposes a different statement-closed shape.
## 3.3 Extensibility
Good. Future JDBC retry classifications can be added centrally.
## 3.4 Historical Compatibility
Compatible. No migration is required.
# 4. Findings Summary
| No. | Finding | Location | Severity |
|---|---|---|---|
| 1 | CI has not reached a merge-ready green state | GitHub check run `72126310088` | Medium |
# 5. Merge Decision
### Conclusion: can merge after fixes
1. Blocking items
- Issue 1: wait for CI to complete and resolve any failures before merge.
2. Recommended non-blocking improvements
- Add one focused test for SQLState `08xxx` inside the cause chain, not only `nextException`.
Overall, the implementation direction looks correct and low-risk. Once CI is green, I think this can be merged.
--
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