SEPURI-SAI-KRISHNA opened a new pull request, #13775:
URL: https://github.com/apache/seatunnel/pull/13775

   Yes, glad to contribute to Apache SeaTunnel.
   
   ### Purpose of this pull request
   
   Fixes #13469.
   
   A plain sink committer commits the commit info of a checkpoint from task 
memory after the checkpoint completed. When that commit fails, or the worker 
stops before it runs, the restored pipeline continues after the checkpoint and 
the transaction is never committed, so its rows are lost. #13469 has the 
reproduction.
   
   This follows the first slice agreed on #13469: an opt in restorable 
committer, replay only on the Zeta engine's own automatic recovery, Kafka and 
Doris first, and no change for Flink and Spark.
   
   **API.** New `RestorableSinkCommitter` (extends `SinkCommitter`) with 
`restoreCommit(List<CommitInfoT>)`. It must return normally when the info is 
committed now or was committed before the restore, and throw for anything else 
(aborted, timed out, expired, unknown), so the recovery attempt fails instead 
of continuing without the rows. `MultiTableSink` returns a restorable multi 
table committer only when every table's committer is restorable, and routes the 
info to each table.
   
   **Engine (Zeta).**
   
   - For a sink whose committer is restorable, each checkpoint also stores the 
commit info, under its own state key next to the writer state (`<sink action 
key> - commit info`). Checkpoints of other sinks are unchanged, and an old 
checkpoint without that key restores as today.
   - On restore, `SinkFlowLifeCycle` calls `restoreCommit` with that info 
before it creates the writer.
   - **`-r` never replays the checkpoint it restores from** (the K edge 
discussed on #13469). For a pipeline with a restorable committer, a job started 
with `-r` writes `checkpoint_state_<job>_<pipeline>_restore_run` to the job 
state IMap before deployment: the baseline K and an empty list. When the run 
completes a checkpoint C, C is added to that list before C is stored, and older 
ids are dropped after the store. Commit info is replayed only for a checkpoint 
the list names, so K is never replayed, a missing record never replays, and 
pipeline restore and master switch use the same rule. A master that takes over 
keeps the record of the run. Jobs not started with `-r` replay on every 
automatic recovery. Other pipelines keep no record, so nothing changes for them.
   - The record key is in the JobMaster cleanup record next to 
`_ready_to_close`, and the terminal zombie cleanup in `CoordinatorService` 
already removes every `checkpoint_state_<job>_` key.
   
   **Connectors.**
   
   - Kafka (`semantics = EXACTLY_ONCE`): `KafkaSinkCommitter` implements 
`restoreCommit` with the existing resume and commit. Measured on a real broker 
(below): a committed transaction commits again without error and its rows stay 
visible once; aborted, timed out and expired transactional ids fail with the 
broker's error, and the message names the transactional ids.
   - Doris (`sink.enable-2pc = true`): `DorisCommitter` implements 
`restoreCommit` with the existing commit, which already accepts a transaction 
Doris reports as committed or visible. Aborted and unknown transactions fail.
   
   **Not covered.** Pulsar and SelectDB Cloud committers do not implement the 
interface, so the loss described in #13469 remains for them. Flink and Spark 
never call `restoreCommit` and are unchanged. Plain committers that do not opt 
in keep today's behavior.
   
   If you prefer another behavior for any of this, in particular for the `-r` 
rule, I am happy to change the code.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, for Zeta jobs with a Kafka exactly once sink or a Doris 2PC sink, 
recorded in `incompatible-changes.md` (en and zh) with migration notes:
   
   - A checkpoint whose commit failed, or whose worker stopped before the 
commit, is now committed on automatic recovery instead of being lost.
   - A transaction that can no longer be committed now fails the recovery 
attempt, and the job fails once `job.retry.times` is used up, instead of 
continuing without those rows.
   - For Kafka, keep `transaction.timeout.ms` longer than a recovery can take.
   
   The Kafka and Doris sink pages and `sink-architecture.md` (en and zh) 
describe the behavior.
   
   ### How was this patch tested?
   
   All on JDK 17, rebased on dev `954136a0c6`.
   
   **Engine, `RestorableSinkCommitterTest`** (new, a real Zeta server in the 
test JVM with a test sink that can fail or block its commit):
   
   - `testFailedCommitIsCommittedAgainOnRecovery`: the commit of the first 
checkpoint with rows fails; the recovery restores that checkpoint and commits 
its info; every row is committed once.
   - `testRetryableRestoreCommitFailure`: the first `restoreCommit` throws, the 
next attempt commits.
   - `testTerminalRestoreCommitFailureFailsTheJob`: `restoreCommit` always 
throws; with `job.retry.times = 1` the job ends FAILED after one call.
   - `testPlainCommitterKeepsTodaysBehavior`: the same failure with a plain 
committer; nothing is replayed and the rows stay lost, as on dev.
   - `testWorkerLostBeforeCommitIsCommittedOnRecovery`: master and two workers; 
the worker that runs the commit is terminated while the commit blocks; the 
recovery commits it.
   - `testRestoredCheckpointIsNotCommittedAgain`: savepoint K holding rows, 
restart with `-r`, the first restored writer fails so the pipeline restores K 
again; `restoreCommit` is never called, the record holds only K, and it is 
removed when the job is cancelled.
   
   **Engine, `CheckpointCoordinatorTest`** (a real coordinator and a real 
Hazelcast IMap):
   
   - `testRestoreRunNeverReplaysItsBaseline`: `-r` from K; first deployment, 
pipeline restore, a new master, and a missing record never replay K.
   - `testRestoreRunReplaysOnlyCheckpointsItCompleted`: after the run completes 
K+1 (listed before it was stored), a pipeline restore and a new master replay 
K+1, and a restore of K still does not.
   - `testCheckpointRecordedButNotStoredKeepsTheStoredOneReplayable`: the store 
of C fails after C was recorded; the new master restores the stored one and 
replays it.
   - `testRestoreRunWithoutRestorableSinkKeepsNoRecord`: a `-r` run with a 
plain sink writes no record.
   - `testRunWithoutRestoreReplaysOnAutomaticRecovery`: a job not started with 
`-r` replays and keeps no record.
   
   `CoordinatorServiceJobCleanupTest`: the terminal zombie test now also checks 
that the record is removed.
   
   **Negative controls**, each restored byte for byte afterwards:
   
   - With replay always on, 3 tests fail. On the real engine `restoreCommit` 
was called twice for K.
   - With the checkpoint recorded after the store instead of before, 2 tests 
fail.
   - With the record kept for every `-r` job, the plain sink test fails.
   - With replay disabled in `SinkFlowLifeCycle`, 
`testFailedCommitIsCommittedAgainOnRecovery` fails with `expected: <20> but 
was: <15>` (measured before the `-r` record was added; that path did not 
change).
   
   **Connector unit tests:** `KafkaSinkCommitterTest` (new, 1), 
`DorisCommitterTest` (16, two new ones use the real Doris 2.1.0 responses for 
"already visible", which is accepted, and "not found", which fails), 
`MultiTableSinkCommitterTest` (2, one new).
   
   **Connector E2E, run locally with Docker:**
   
   - `KafkaRestoreCommitIT` (new, its own `confluentinc/cp-kafka:7.0.9` broker, 
Kafka 3.0 line, client 3.4.0): 5/5. A committed transaction commits again and 
is visible once; an open one is committed; aborted, timed out and expired 
transactional ids fail the restore.
   - `DorisRestoreCommitIT` (new, `apache/doris:doris-all-in-one-2.1.0`): 4/4. 
An open transaction is committed; a committed one commits again and is visible 
once; aborted and unknown transactions fail the restore. On my machine the 
Doris container needed more than the 60 s port wait of `AbstractDorisIT` (its 
start copies a 2 GB binary on first write), so I ran it with a longer local 
timeout that is not part of this PR.
   
   These two ran before the last engine change; the connector code they test 
did not change since.
   
   **Suites that already existed:** the checkpoint package tests plus 
`SubPlanTest`, `TaskTest`, `CoordinatorServiceTest` and `JobMasterTest`, run 
before the last change (no record for plain sinks): 128 run, 0 failures, 4 
skipped (all `@Disabled` on dev). After the rebase: 48 engine tests (the new 
ones plus `SavePointTest`), 0 failures, 1 skipped (`@Disabled` on dev). 
`spotless:check` and `-DskipTests verify` pass on api, engine-core, 
engine-server, connector-kafka and connector-doris.
   
   ### Check list
   
   * [x] If any new Jar binary package adding in your PR, please add License 
Notice according
     [New License 
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
 (no new dependency)
   * [x] If necessary, please update the documentation to describe the new 
feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [x] If necessary, please update `incompatible-changes.md` to describe the 
incompatibility caused by this PR.
   * [ ] If you are contributing the connector code, please check that the 
following files are updated: not a new connector.
   


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