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/09/08 14:41:03 UTC
[PR] [Fix][Connector-V2][Assert] Scope AssertSinkWriter row/table-name counters per sink instance [seatunnel]
DanielLeens opened a new pull request, #12216:
URL: https://github.com/apache/seatunnel/pull/12216
## Purpose
Fixes #12116: `TestFilterRowKindIT#testFilterRowKindMultiTable` fails intermittently on Flink-only CI legs (row counts like `75`/`97`/`125`/`150` instead of the expected `100`), which surfaces on many unrelated PRs since it is a pre-existing bug in `connector-assert`, not something any of those PRs' own diffs touch.
Reproduced again this week, identically, on:
- #12064 (Flink 11 leg)
- #12150 (Flink 8 leg)
- #12182 (Flink 11 leg)
...and previously on #11077/#11458/#11503 (see #12116 for full evidence).
## Root cause
`AssertSinkWriter` keeps its row-count and table-name rule state in two `static` maps (`LONG_ACCUMULATOR`, `TABLE_NAMES`), keyed only by table name, and neither is ever cleared:
- On Zeta, each job runs under its own classloader, so the statics are effectively scoped per job.
- On Flink, every per-table writer and every sink subtask across the whole TaskManager JVM shares those same statics, and each writer's `close()` evaluates its own MIN_ROW/MAX_ROW or table-set rule against them independently.
Since a table name can be (and in this suite's case, is) reused across unrelated jobs/tests within one JVM lifetime, and nothing ever removes an entry:
- a writer that closes before a same-named table in a *different*, still-running job finishes contributing can see a partial total (`MIN_ROW` failures - the `75`/`97` cases), and
- a writer whose table name collides with an already-accumulated (and never cleared) entry from an *earlier* job can see an inflated total (`MAX_ROW` failures - the `125`/`150` cases, i.e. 100 + 25/50 leftover).
Both directions appearing across the same suite's runs matches shared mutable static state plus per-writer independent evaluation, not test data or a race in the transform/source under test.
## Fix
Give each `AssertSink` construction (one per job/table) a fresh `sinkInstanceId`, and thread it into every `AssertSinkWriter` that sink creates. Both static maps are now keyed by `(sinkInstanceId, tableName)` / `sinkInstanceId` instead of table name alone.
This keeps the *intentional* behavior the statics exist for - aggregating row counts and table names across every parallel subtask writer of the **same** sink instance, which Flink's shared-JVM subtask execution model still needs - while eliminating cross-job/cross-test contamination. Not a test-only workaround: the test and its assertion are already correct (see #12116); this fixes the shared production connector code whose bug the test's failures were exposing.
Minimal, contained change: no new constructor parameters on any public-facing `Sink`/`SinkFactory` API, no change to `AssertSink`'s own public constructor - only `AssertSinkWriter`'s package-internal construction gained one new parameter, updated at its one production call site (`AssertSink#createWriter`) and its two existing direct-construction unit tests.
## Tests
Added three tests to `AssertSinkWriterCloseTest`:
- `testRowCountIsIsolatedAcrossUnrelatedSinkInstances` - two sink instances (different `sinkInstanceId`, same table name) each write 1 row against `MAX_ROW=1`; both must close successfully, proving one job's count can no longer leak into the other's.
- `testRowCountStillAggregatesAcrossSubtasksOfSameSinkInstance` - two writers sharing the *same* `sinkInstanceId` and table (simulating two parallel subtasks), writing 3 and 2 rows respectively against `MIN_ROW=5`; the second writer's `close()` must see the combined total of 5, proving the intentional cross-subtask aggregation still works.
- `testTableNamesRuleIsIsolatedAcrossUnrelatedSinkInstances` - same isolation proof for the `assert_table` table-set rule.
Also updated the two existing `AssertSinkWriterCloseTest` cases to pass a `sinkInstanceId` (previously not needed to reproduce their scenario) - their existing assertions are unchanged.
Per this repository's contribution guidance for Apache SeaTunnel, local execution was limited to `./mvnw spotless:apply`/`spotless:check` (passing); full compilation, the new/existing unit tests, and any E2E impact are verified by this PR's own GitHub Actions CI run.
--
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
Re: [PR] [Fix][Connector-V2][Assert] Keep row counts local to each writer [seatunnel]
Posted by "DanielLeens (via GitHub)" <gi...@apache.org>.
DanielLeens commented on PR #12216:
URL: https://github.com/apache/seatunnel/pull/12216#issuecomment-5617133892
Reworked the fix in `68c0185b0970fd6b337d5c64fb8cd38d2fc410c1` after tracing the previous CI failures.
The prior head was not valid: its UUID was created once per per-table `AssertSink`, so multi-table writers did not share table-name state and E2E jobs failed with errors such as `[people] is not equal to [people, companies]`. The same file also contained an embedded NUL, which made both Windows unit jobs fail Spotless.
The current head now follows #12116's confirmed writer-local row-count contract:
- `LONG_ACCUMULATOR` is replaced by a non-static map owned by each `AssertSinkWriter`.
- UUID plumbing and constructor changes are removed.
- `TABLE_NAMES` behavior is restored unchanged and remains explicitly out of scope pending its separate contract decision.
- The regression now deterministically proves two same-table writers cannot affect each other's MAX_ROW result.
Module Spotless and `git diff --check` pass. The effective PR diff is two files with no public API or serialization change; fresh CI has started from this head.
--
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
Re: [PR] [Fix][Connector-V2][Assert] Evaluate row-count rules once per table after the last writer closes [seatunnel]
Posted by "DanielLeens (via GitHub)" <gi...@apache.org>.
DanielLeens commented on PR #12216:
URL: https://github.com/apache/seatunnel/pull/12216#issuecomment-5846321542
Thanks for running this empirically rather than just reasoning about it in the abstract — the numbers line up exactly with what I'd expect from the bug this PR targets, and it's valuable to have that confirmed by someone who wasn't already anchored on my own review.
On the `dev` vs. this PR vs. #12454 comparison: 8/14 failures on `dev`, matching the two-phase signature #12116 describes (first writer fails `MIN_ROW` on a partial total, then restarts fail `MAX_ROW` against never-reset static counters), against 0/13 on this PR's `AssertSinkWriter`, is consistent with the fix actually closing that window rather than just narrowing it. The 5/5 vs. 2/5 result for `AssertSinkWriterCloseTest` against the unpatched `AssertSinkWriter` is a good sanity check that the regression test is load-bearing rather than passing by construction.
On your two questions about the "last open writer in this JVM" rule, I went back to the current head (`f424385`) to check both against the actual code rather than from memory:
1. You're right that `OPEN_WRITERS` counts writers by construction order, not by the sink's configured parallelism — the constructor does `OPEN_WRITERS.computeIfAbsent(openWritersKey, key -> new AtomicInteger()).incrementAndGet()` with no reference anywhere in the file to subtask count or parallelism. In the steady-state case this doesn't actually bite: every engine constructs all of a table's parallel writers together, before any of them has written enough rows to close, so the full population is always registered by the time the first `close()` runs. Where it could bite is a table whose writer set grows after a sibling has already closed — for example a dynamically-added table in a schema-evolving multi-table job. That's a real, if narrow, gap, and keying off the writer's actual subtask/parallelism count instead of construction order would remove the ambiguity outright. I don't think it changes the merge calculus for the flake this PR was written to fix, since that flake hap
pens on the ordinary parallel-close path, not this one — but it's worth tracking as a real follow-up rather than dropping it.
2. This one isn't new on my end — it's the same Issue 2 I raised after the 2026-09-13 revision and reaffirmed as still open after CI ran on the current head on 2026-09-15: a writer that never reaches a graceful `close()` (task failure, forced kill, a retried attempt whose predecessor's slot was never released) leaves that table's `OPEN_WRITERS` count permanently above zero for the life of the JVM/classloader, and `MIN_ROW`/`MAX_ROW` silently stop being evaluated for every writer that closes after it. I still haven't been able to confirm from this connector's own code whether Zeta, Flink, or Spark guarantee `writer.close()` runs on task failure, which is exactly the question that needs answering before this can merge. A test for "writer dropped without a close, new writer created for the same table" is a good way to pin the actual behavior down either way — I'd support adding it.
On #12454: if it's scoped to just the one `parallelism = 1` conf, then it only removes the specific reproduction under discussion here, not the underlying exposure for every other multi-table Assert conf running with `parallelism > 1`. Assuming that characterization holds, I agree this PR is the more complete fix of the two — conditional on point 2 above getting a real answer rather than staying open.
For the record: `origin/dev` still carries the pre-fix `AssertSinkWriter` (no `OPEN_WRITERS`, each writer still evaluates on its own `close()`), so the underlying #12116 bug is not fixed upstream yet — this PR, or something like it, is still needed.
--
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
Re: [PR] [Fix][Connector-V2][Assert] Evaluate row-count rules once per table after the last writer closes [seatunnel]
Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on PR #12216:
URL: https://github.com/apache/seatunnel/pull/12216#issuecomment-5841704094
I ran `TestFilterRowKindIT#testFilterRowKindMultiTable` in a loop locally on the Flink 1.15.3 and 1.18.0 containers only, which are the legs that fail in CI. I compared `dev` (`deb16a3c3`), this PR (`AssertSinkWriter` patched into the connector-assert jar the containers pick up), and #12454 (its `parallelism = 1` conf change). The host test JVM was JDK 8. Six CPU burners ran on the host for most runs.
| variant | runs (2 Flink invocations each) | failed |
|---|---|---|
| `dev` | 14 | 8 (Flink 1.15 ×6, 1.18 ×2) |
| this PR | 13 | 0 |
| #12454 conf | 6 | 0 |
The `dev` failures match CI:
- The sink runs as `Writer (x/4)`.
- The first writer to close fails `MIN_ROW` on a partial total.
- Flink restarts the task, and the next attempts fail `MAX_ROW` with 125 and then 150, because the static counters were never reset.
`AssertSinkWriterCloseTest` passes 5/5 with the change and fails 2/5 against the current `AssertSinkWriter`, so it does catch the bug.
Two questions on the "last open writer in this JVM" rule:
1. The count comes from writers *constructed* so far, not from the sink's parallelism. If one subtask's writer is created late, after another subtask has already closed, the earlier close would still see a partial total. That seems unlikely in these tests, but it is possible in principle.
2. If a failed attempt's writer is never `close()`d before the task restarts, its slot in `OPEN_WRITERS` is never released. The rules would then never be evaluated for that table. A job that should fail on MIN/MAX_ROW would pass silently, where today it fails loudly. A unit test for "writer dropped without close, new writer created" would settle it either way. Keying off the sink parallelism from the writer context might avoid both cases.
#12454 fixes only this one conf (`parallelism = 1`), and the other multi-table Assert confs keep the same exposure. This PR is the more complete fix if the two points above hold up.
--
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
Re: [PR] [Fix][Connector-V2][Assert] Evaluate row-count rules once per table after the last writer closes [seatunnel]
Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo merged PR #12216:
URL: https://github.com/apache/seatunnel/pull/12216
--
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