DanielLeens commented on PR #13310:
URL: https://github.com/apache/seatunnel/pull/13310#issuecomment-7195188942
## Implementation Notes and Trade-offs
**Head:** `26411ff37c87f84a085277b14d3a050b1ba46315`
### Problem and execution path
The original backfill implementation now reads WAL between snapshot LOW and
HIGH, but its completion condition advanced only inside decoded-message
callbacks. PostgreSQL WAL positions are cluster-wide while a logical slot
decodes one database. Therefore, WAL generated only in another database can
make HIGH greater than LOW without producing a callback for the captured
database, leaving the snapshot reader waiting forever and never emitting END.
The corrected path is:
```text
LOW -> snapshot SELECT -> HIGH
-> bounded logical stream from LOW
-> process every decoded record in protocol order
-> finish when either:
1. the last completely processed decoded LSN reaches HIGH, or
2. an idle read proves that the client received server WAL through
HIGH
-> emit END -> reconcile buffered snapshot rows -> start incremental
split
```
### Final implementation
- Added `WalProgressAwareReplicationStream` as the smallest connector-local
progress contract.
- OpenGauss already owns a source copy of its Debezium replication
connection, so that wrapper now records pgjdbc `getLastReceiveLSN()` after
every read, including primary keepalive processing.
- PostgreSQL keeps the dependency implementation unchanged. After an idle
read, the bounded loop queries the active WAL sender for the current slot and
reads `write_lsn` on PostgreSQL 10+ or `write_location` on PostgreSQL 9.6.
pgjdbc reports its last received LSN in the first standby-status field, which
PostgreSQL exposes as that write position.
- The existing decoded-message condition remains the fast path. The new
boundary proof is consulted only for a bounded stream after no pending message,
so normal unbounded streaming is unchanged.
- Added a real E2E that blocks the snapshot SELECT after LOW, generates
committed WAL in the separate `postgres` database, releases the snapshot, and
requires the backfill slot to disappear plus exact source/sink equality.
- Updated the controlled enumerator test proxy to accept the new default
`openEnumerator` lifecycle method, fixing the four previously failing unit-test
lanes without weakening their assertions.
- Reworked the concurrent-DML E2E cleanup so the snapshot gate, pending DML
futures, running job, executor, and both shared tables are all handled. The
original failure stays primary and later cleanup failures are suppressed onto
it.
- Removed the method-local fully qualified Debezium schema type by
constructing the task context directly; behavior is unchanged.
The no-event completion rule follows PostgreSQL own `pg_recvlogical
--endpos` implementation: after the socket has no data through a keepalive
whose WAL end reaches the endpoint, PostgreSQL states that nothing else can
have committed before that endpoint. See the PostgreSQL 11 source at
https://github.com/postgres/postgres/blob/REL_11_STABLE/src/bin/pg_basebackup/pg_recvlogical.c#L487-L494.
The pgjdbc receive-LSN and status behavior is documented at
https://jdbc.postgresql.org/documentation/server-prepare/#replication.
### Alternatives evaluated and not used
- **Idle timeout followed by END:** rejected because elapsed time is not
proof that all transactions through HIGH were decoded; it can reintroduce data
loss.
- **Write a marker row or logical message in the captured database:**
rejected because it mutates a user database, needs extra privileges/schema
lifecycle, and is not uniformly supported by decoderbufs, pgoutput, wal2json,
and OpenGauss.
- **Copy the complete Debezium PostgreSQL replication-connection
implementation only to expose pgjdbc progress:** rejected because it would
vendor hundreds of dependency lines and materially increase maintenance and
review cost. The existing OpenGauss source copy is changed in place; PostgreSQL
uses its slot-specific server status instead.
- **Use only the server sent position:** rejected because server send
progress alone can race with unread client data. The implementation uses the
client-reported receive position after an idle read.
### Assumptions and constraints
Verified from source:
- PostgreSQL keepalive WAL end is a transaction-complete bounded-stream
termination proof when prior socket data is drained.
- pgjdbc updates its receive LSN for XLogData and primary keepalive messages
and sends that value in standby status.
- PostgreSQL exposes one `active_pid` per active logical slot, allowing the
query to select this reader rather than another parallel reader.
- OpenGauss uses its repository-owned pgjdbc stream wrapper, so it can
expose the receive LSN directly without relying on PostgreSQL catalog column
names.
Pending remote verification:
- Compilation, unit tests, PostgreSQL E2E, and native OpenGauss behavior
must be established by the exact-head GitHub CI. Repository policy does not
permit local compilation, unit tests, E2E, Docker, or runtime execution for
this task.
### Verification performed
- `./mvnw spotless:apply` on the four affected modules: passed.
- `./mvnw spotless:check` on the same modules: passed.
- `git diff --check`: passed before commit.
- Current `apache/dev` is the merge base
(`9ba5a94a41ba5914a9fa1e4f450c134fa7476021`), so the branch is behind by 0 and
ahead by 27 after this commit.
- No `pom.xml`, dependency version, workflow, connector registration, saved
split format, or user-visible configuration was changed.
- Local compilation and tests were not run under the SeaTunnel
local-verification rule. Exact-head CI is the remaining functional gate.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]