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:56:32 UTC
Re: [PR] [Improve][Postgres-CDC] Fix postgresql-cdc ,Resolving NullPointerExc… [seatunnel]
DanielLeens commented on PR #10058:
URL: https://github.com/apache/seatunnel/pull/10058#issuecomment-4278482725
Hi @liujishui87, thanks for the focused PostgreSQL CDC fix. I reviewed this from a local branch against current `dev`, following the snapshot split path and the Debezium schema lookup path.
# What This PR Solves
- User pain point: PostgreSQL CDC snapshot reading can fail with a `NullPointerException` when the split table id and Debezium schema cache use different catalog values.
- Fix approach: keep the catalog from `snapshotSplit.getTableId()`, and only fall back to `connectorConfig.databaseName()` when the catalog is null.
- One-line summary: this is a narrow and useful fix that aligns snapshot data reading with the schema cache key.
# 1. Code Change Review
## 1.1 Core Logic Analysis
Local review basis:
- Branch: `seatunnel-review-10058`
- Head: `76ef46a4fe9f491cdfc1c98e395c21fa26790f00`
- Merge base with `upstream/dev`: `3f1fd541fe3818cd9b1052a6ebadfcfe9c039a9d`
- `git diff --stat upstream/dev...HEAD`: 1 file changed, 17 insertions, 1 deletion
- `git diff --check upstream/dev...HEAD`: clean
- Local `git merge-tree` against current `dev`: no conflict markers found
- GitHub metadata: `mergeable=MERGEABLE`, `mergeStateStatus=BLOCKED`
- GitHub checks: `Build` is failing; `Notify test workflow` and `labeler` are passing
- I tried `gh run view --repo apache/seatunnel --job 61836024464 --log-failed`, but GitHub returned `log not found`, so I could not inspect the failed Build step locally
- I did not run Maven tests locally for this batch review; this is source-level review plus Git/GitHub metadata inspection
Before this PR, the snapshot read task forced the catalog to null:
```java
private void createDataEvents(PostgresSnapshotContext snapshotContext, TableId tableId)
throws Exception {
EventDispatcher.SnapshotReceiver snapshotReceiver =
dispatcher.getSnapshotChangeEventReceiver();
log.debug("Snapshotting table {}", tableId);
TableId newTableId = new TableId(null, tableId.schema(), tableId.table());
createDataEventsForTable(
snapshotContext, snapshotReceiver, databaseSchema.tableFor(newTableId));
snapshotReceiver.completeSnapshot();
}
```
After this PR, the catalog is preserved, with a database-name fallback:
```java
String catalog = tableId.catalog();
log.debug(catalog);
if (catalog == null) {
log.warn(
"TableId catalog is null/empty for table {}.{}, using database name as fallback",
tableId.schema(),
tableId.table());
catalog = connectorConfig.databaseName();
if (catalog == null || catalog.isEmpty()) {
throw new IllegalStateException(
String.format(
"Cannot determine catalog for table %s.%s. "
+ "Please check your PostgreSQL CDC configuration.",
tableId.schema(), tableId.table()));
}
}
TableId newTableId = new TableId(catalog, tableId.schema(), tableId.table());
createDataEventsForTable(
snapshotContext, snapshotReceiver, databaseSchema.tableFor(newTableId));
snapshotReceiver.completeSnapshot();
```
Key findings:
- The normal PostgreSQL CDC snapshot path does hit this code: `doExecute()` dispatches the LOW watermark and then calls `createDataEvents(ctx, snapshotSplit.getTableId())`.
- The real covered scenario is snapshot schema lookup. This does not alter WAL streaming, checkpoint serialization, offsets, or event format.
- The fix is precise: table discovery creates a `TableId` with catalog, and the schema cache is also populated with a catalog-aware key, so snapshot reading should not force the catalog to null.
- I did not find a blocking code issue. The current blocker is the failing GitHub Build check.
Complete runtime flow:
```text
Table discovery and split creation
-> TableDiscoveryUtils.listTables(...) [L61-L75]
-> new TableId(database/catalog, schema, table)
-> AbstractJdbcSourceChunkSplitter.createSnapshotSplit(...) [L374-L385]
-> new SnapshotSplit(splitId, tableId, splitKeyType, splitStart, splitEnd)
Schema cache loading
-> PostgresSchema.getTableSchema(jdbc, tableId) [PostgresSchema L49-L55]
-> readTableSchema(jdbc, tableId) [L58-L94]
-> readSchema(..., null catalog, schema, ...) [L65-L71]
-> for each Debezium table id:
-> idWithCatalog = new TableId(tableId.catalog(), id.schema(), id.table()) [L73]
-> schemasByTableId.put(idWithCatalog, tableChange) [L81]
Snapshot split reading
-> PostgresSnapshotSplitReadTask.doExecute(...) [L116-L149]
-> currentLsn() -> dispatch LOW watermark
-> createDataEvents(ctx, snapshotSplit.getTableId()) [L135-L136]
-> before: new TableId(null, schema, table)
-> databaseSchema.tableFor(nullCatalogId) can return null
-> createDataEventsForTable(..., null)
-> table.id() can throw NPE [L199]
-> after: new TableId(catalog, schema, table)
-> matches the schema cache key
-> createDataEventsForTable(...) builds the split scan SQL and emits snapshot events
-> currentLsn() -> dispatch HIGH watermark
-> SnapshotResult.completed(ctx.offset)
```
## 1.2 Compatibility Impact
Verdict: fully compatible.
- API: no public API/SPI changes.
- Config: no config changes.
- Defaults: unchanged.
- Protocol and serialization: unchanged.
- Historical behavior: this only fixes PostgreSQL CDC snapshot table lookup.
## 1.3 Performance / Side Effects
CPU, memory, GC, network, lock, retry, idempotency, and resource-release impact are negligible. The change uses local variables only and does not add any JDBC query.
## 1.4 Error Handling and Logs
The fallback error is clearer than the previous downstream NPE. There is one small non-blocking polish point: `log.debug(catalog)` would be easier to read as a contextual message, but it does not affect correctness.
Issue 1: the GitHub Build check is currently failing
- Location: GitHub check `Build`
- Description: `gh pr checks 10058 --repo apache/seatunnel` shows `Build` failed after about 2h55m. I tried to fetch failed logs with `gh run view --repo apache/seatunnel --job 61836024464 --log-failed`, but GitHub returned `log not found`.
- Risk: the PR cannot be merged while required CI is red. Since the failed logs are unavailable from my local check, I cannot confirm whether the failure is related to this code path or external/flaky.
- Suggested fix: rerun or fix the Build check. If the logs become available, please first confirm whether any PostgreSQL CDC test failed.
- Severity: High
# 2. Code Quality
## 2.1 Style
The change is small and localized. A contextual debug log would be nicer than `log.debug(catalog)`, but I do not consider that a blocker.
## 2.2 Tests
No regression test was added. A focused test for catalog-aware `TableId` lookup in snapshot reading would be helpful. Given the small first contribution, I am not treating this as an additional blocker; the mandatory item is to get Build green.
## 2.3 Docs
No docs update is needed because this is an internal PostgreSQL CDC bug fix and does not introduce user-facing configuration or behavior changes.
# 3. Architecture
## 3.1 Elegance
This is a precise fix. It aligns the snapshot read path with the existing schema cache key instead of adding a workaround elsewhere.
## 3.2 Maintainability
The fix is easy to reason about. A regression test would make it safer long term.
## 3.3 Extensibility
The change stays inside PostgreSQL CDC and does not leak connector-specific logic into common CDC code.
## 3.4 Historical Compatibility
Fully compatible. No state or config migration is required.
# 4. Issue Summary
| No. | Issue | Location | Severity |
|---|---|---|---|
| Issue 1 | GitHub Build check is currently failing | GitHub check `Build` | High |
# 5. Merge Decision
### Conclusion: can merge after fixes
1. Blocking items
- Issue 1: the Build check must be green before merge.
2. Suggested non-blocking improvements
- Add a small regression test for catalog-aware PostgreSQL snapshot schema lookup.
- Change `log.debug(catalog)` to a contextual debug message.
Overall, the code change looks correct and nicely focused. Once CI is green, this should be safe to move forward.
--
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