SEPURI-SAI-KRISHNA opened a new issue, #13449:
URL: https://github.com/apache/seatunnel/issues/13449

   State: Under Review
   
   ## Background
   
   With `multi_table_sink_replica` above 1, a multi-table sink runs several 
writers per table in one subtask. On dev, a row goes to a writer by the hash of 
its key, or to a random writer when `primaryKey()` is empty. Most writers 
inherit the empty key, so two changes of one record can be applied out of order 
while the job still finishes (#13221). This affects the 35 connector modules 
whose sink implements `SupportMultiTableSink`.
   
   ## Motivation
   
   Only the connector knows whether its writes can run in parallel. That should 
be declared per connector, not taken from an empty key.
   
   ## Goals
   
   - Make multi-replica writes opt-in per connector.
   - Reject an unsupported setting before the save mode changes the target.
   - Send all changes of one key to one writer, binary keys included.
   - Define what a restore does with writer state after the replica count or 
the sink parallelism changes.
   
   ## Non-Goals
   
   - Changing the default of `multi_table_sink_replica` (1).
   - Enabling connectors other than the ordinary Jdbc writer. Each is its own 
row in #13223.
   
   ## Design
   
   `SupportMultiTableSinkWriter.replicaMode()` returns:
   
   | Mode | With more than 1 replica |
   |---|---|
   | `UNSUPPORTED` (default) | Rejected |
   | `KEYED` | Needs a valid `primaryKey()`; rows of one key go to one writer |
   | `RANDOM` | Random writer, for writes that do not depend on order |
   
   `KEYED` is never inferred from `primaryKey()`. With 1 replica every mode is 
accepted. `JdbcSinkWriter` returns `KEYED`, so only Jdbc without 
`is_exactly_once`, on a table with a key, can use replicas. #13243 implements 
this.
   
   Three points remain from the #13243 review:
   
   **F1. Restore after the replica count or parallelism changes (needs a 
decision).** On dev, writer state that no writer gets after the restore is 
dropped silently. Paimon, Doris, Iceberg, File and Pulsar (exactly-once) keep 
pending work there. #13243 fails the restore instead, so a Paimon job at 
replica 2, which must move to 1 after the upgrade, cannot restore.
   
   - A: fail the restore; the user drains the job and starts fresh.
   - B (proposed): give that state to the table's first writer in the subtask. 
`restoreWriter` already takes a list of states.
   
   Test: prepared commits at replica 2, restored at replica 1, each committed 
once.
   
   **F2. Check before the save mode.** The check runs when the writer is 
created, after the save mode. Proposal: the per-table sink also declares its 
mode and whether it has a key, and the check runs before the save mode on every 
engine.
   
   Test: an `UNSUPPORTED` sink at replica 2 with `DROP_DATA` is rejected and 
the target keeps its rows.
   
   **F7. Binary keys.** `byte[]` keys are hashed by identity. Proposal: hash by 
content, as #13242 does.
   
   Test: updates of one binary key at replica 4 end with the latest value.
   
   ## Compatibility, Deprecation, and Migration Plan
   
   Jobs with the default of 1 keep running, except a restore after a 
parallelism change (F1). Outside the Jdbc case above, a job above 1 fails at 
startup; the error names the tables and the option, and the fix is to set it to 
1. A custom writer that relied on `primaryKey()` must also return `KEYED`. 
`incompatible-changes.md` (EN and ZH) has the entry.
   
   ## Test Plan
   
   The unit tests in #13243, the three tests above, and an E2E that rejects a 
job with replicas. Each connector row adds an E2E with exact final rows.
   
   ## Alternatives Considered
   
   - Infer `KEYED` from a non-empty key: a key alone does not make parallel 
writes safe.
   - Warn instead of failing: the out-of-order writes continue.
   
   ## References
   
   - #13221 (bug), #13223 (umbrella), #13243 (Phase 1), #13242 (binary keys), 
#13268 (Iceberg)
   - dev@ request: 
https://lists.apache.org/thread/vboop5jwgjt35bqrjqc4tjsyrpchzxok
   
   Requesting a maintainer to add the design / STIP label.
   


-- 
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]

Reply via email to