zhangshenghang opened a new pull request, #13754:
URL: https://github.com/apache/seatunnel/pull/13754
Yes. This change is a contribution to Apache SeaTunnel.
### Problem
The incremental stream filter of the CDC base connector resolves the binlog
offset of every
change record before it decides whether the record should be emitted:
`IncrementalSourceStreamFetcher#shouldEmit` calls
`taskContext.getStreamOffset(record)` first and
only then checks whether the record's table already reached its pure binlog
phase
(`pureBinlogPhaseTables`). A table enters that phase once the reader has
passed the snapshot high
watermark, and from then on **every** change record of that table is
accepted. The offset built for
those records is therefore thrown away immediately, but it is not free: for
MySQL it is a
`HashMap` with five to seven entries, each value converted to a `String`,
wrapped in a
`BinlogOffset`. At the same time, `SourceRecordUtils#getTableId`, which runs
for every record,
streamed the source struct's field list to look up the `schema_name` field,
and
`SourceRecordUtils#isSchemaChangeEvent`, which runs for every record on the
emitter path,
allocated a stream pipeline plus a lambda.
On a running incremental read (the steady state) this is a fixed per-record
cost that has no effect
on the filtering decision.
### Change
- `IncrementalSourceStreamFetcher`: check the per-table pure binlog phase
set before building the
binlog offset. Records of a table that already passed its snapshot high
watermark are accepted
without materializing an offset. The offset is still built whenever a
record can actually be
filtered (not yet in the pure binlog phase, or a non exactly-once read,
which is the only mode
that consults the split start watermark).
- `SourceRecordUtils#getSchemaName`: resolve the field through the schema
field lookup instead of
streaming the field list per record. Same case-sensitive semantics.
- `SourceRecordUtils#isSchemaChangeEvent`: compare the supported
schema-change key schema names in a
plain loop instead of a stream pipeline. Same case-insensitive semantics.
### Acceptance criteria
- Emitted records and checkpoint offsets are unchanged for exactly-once and
non exactly-once reads.
- The incremental filter no longer builds an offset for a record whose table
is in the pure binlog
phase (asserted by the new unit test).
- The per-record cost of the filter path drops measurably in the CDC
benchmark.
### Modules and compatibility
Only `connector-cdc-base` and the `seatunnel-benchmarks` module change. No
public API, SPI,
configuration option, default value, state or file format changes:
`IncrementalSourceStreamFetcher#shouldEmit` keeps its signature and its
decision table, and the two
utility methods keep their results. All CDC dialects are affected only in
that the fast path applies
to them as well; each `getStreamOffset` implementation only constructs an
offset and has no side
effects.
### Verification
```
./mvnw -o -pl seatunnel-connectors-v2/connector-cdc/connector-cdc-base
spotless:apply
./mvnw -o -pl seatunnel-connectors-v2/connector-cdc/connector-cdc-base test
Tests run: 149, Failures: 0, Errors: 0, Skipped: 0
./mvnw -pl seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql test
Tests run: 59, Failures: 0, Errors: 0, Skipped: 0
./mvnw -o -Pbenchmark -pl seatunnel-benchmarks -DskipTests package
```
The new unit test
`testShouldEmitSkipsOffsetLookupOnceTableIsInPureBinlogPhase` asserts that
after a
table reaches its high watermark, `shouldEmit` returns `true` without
calling `getStreamOffset`.
JMH `IncrementalSourceRecordEmitterBenchmark`, extended in this change with
a `filterOnly` method so
that the filter path is measured without the emitter. Command:
```
java -jar seatunnel-benchmarks/target/benchmarks.jar
IncrementalSourceRecordEmitterBenchmark \
-f 1 -wi 3 -i 5 -w 1s -r 1s -p columns=20 -p operation=INSERT -p
exactlyOnce=true
```
256 prepared binlog events per invocation, throughput normalized per record
(throughput mode, ops/s = records/s):
| benchmark | before | after | delta |
| --- | --- | --- | --- |
| `filterOnly` (stream filter only) | 7,795,581 | 21,053,044 | +170% (2.7x) |
| `filterAndEmit` (filter + record emitter) | 1,240,216 | 1,580,924 | +27% |
| `filterOnly`, `exactlyOnce=false` (path unchanged by this patch) |
6,139,259 | 6,469,726 | +5% |
The same benchmark fixtures verify, in every run, that all 256 events are
still emitted, that the
row kinds and values are unchanged, that the checkpoint offset equals the
last event offset, and
that the CDC lag metric is unchanged.
### Remaining risk and follow-up
- The benchmark uses prepared in-memory Debezium events, not a live
database, so the absolute
numbers describe the per-record client-side cost only. A MySQL CDC E2E
suite was not run here
(Testcontainers/Docker is not available in this environment); the change
does not alter any
observable behaviour that an E2E test asserts.
- `IncrementalSourceRecordEmitter` copies the offset map once more per
record for the split state.
Reducing that map copy would be a separate change.
--
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]