Davis-Zhang-Onehouse opened a new pull request, #20795:
URL: https://github.com/apache/hudi/pull/20795

   ### Describe the issue this Pull Request addresses
   
   issue: #20794
   Part of #20683, RFC-118 (#20684).
   Stacked on #20793: review only the last commit. Until the PRs below it 
merge, this PR also shows their commits.
   
   A Hudi Streamer transformer can only reshape rows. A transformer that writes 
files of its own for the round (for example side files under the table's meta 
folder) needs the round's instant, and its files must follow the write 
protocol: a marker first, then the file, under an inflight instant, so that a 
rollback of the instant removes them. In the streamer the instant does not 
exist until after the transformer has run.
   
   Such a transformer also needs to take part in the commit: refuse the round 
inside the commit transaction before the instant completes, and learn when the 
round's commit is durable. A transformer that holds driver resources also needs 
to be closed when the streamer stops.
   
   ### Summary and Changelog
   
   A Hudi Streamer transformer can write files under the round's instant, 
refuse the round inside the commit, be told when the commit completed, and 
release its resources when the streamer closes.
   
   - New `InstantAwareTransformer` (public, evolving): `apply(..., 
instantTime)` and `apply(..., instantTime, toInflight)`, plus `needsInstant()`. 
With such a transformer in the chain, `StreamSync` starts the round's commit 
(REQUESTED) once the source returned data, retries the last pending inline 
compaction or clustering first, and moves the instant to INFLIGHT right before 
the first instant-aware transformer. The round's write takes that instant; a 
transformer failure rolls it back. A round whose checkpoint is unchanged starts 
no instant.
   - For insert, upsert and delete commits and delta commits, the INFLIGHT 
transition writes `ConcurrentOperation.pendingWorkloadProfileMetadata`, so a 
blocking clustering waits for the round; bulk insert and replace commits are 
not marked.
   - `Transformer.onPreCommit` (default no-op) runs inside the data-table 
commit transaction in every round with a transformer. Throwing the new 
`HoodiePreCommitRefusalException` refuses the round, and the streamer rolls the 
instant back before it rethrows.
   - `Transformer.onCommit` (default no-op) runs after a durable commit and the 
source's commit callback, only in rounds that started their instant before the 
transformer. New `CompletedWrite.exists` checks that the instant is a completed 
commit, delta commit or replace commit in the active timeline or the archive 
(legacy and LSM layouts), so a skipped empty commit is not reported.
   - `ChainedTransformer` implements `InstantAwareTransformer`: it passes the 
instant to each instant-aware member, forwards `onPreCommit` and `onCommit` 
with each member's scoped properties, and `ErrorTableAwareChainedTransformer` 
shares its per-member apply.
   - `Transformer` extends `AutoCloseable` with a default no-op `close()` 
(evolving). `StreamSync.close` closes its transformer once, even when called 
again or when that close fails, and `ChainedTransformer.close` closes every 
member, throwing the first failure with later ones suppressed.
   - The streamer's write configs set 
`HoodieWriteConfig.ALLOW_MULTI_WRITE_ON_SAME_INSTANT_ENABLE` only for such 
rounds, and `BaseDatasetBulkInsertCommitActionExecutor` / 
`DatasetBulkInsertOverwriteCommitActionExecutor` pass that setting to the 
INFLIGHT transition. A write client rebuilt during the round keeps the 
heartbeat of the started instant.
   - Tests: `TestStreamSyncInstantAwareTransformer`, 
`TestStreamSyncTransformerCommitHooks`, `TestStreamSyncCommitOrderFlag`, 
`TestStreamSyncInflightMarker`, `TestStreamSyncRollbackOnRefusal`, 
`TestTransformerCommitCallback`, `TestCompletedWrite`, 
`TestStreamSyncTransformerLifecycle`, and new cases in 
`TestErrorTableAwareChainedTransformer`, `TestChainedTransformer` and 
`TestHoodieClientOnCopyOnWriteStorage`.
   
   Existing files touched: `BaseDatasetBulkInsertCommitActionExecutor.java`, 
`DatasetBulkInsertOverwriteCommitActionExecutor.java`, `StreamSync.java`, 
`ChainedTransformer.java`, `ErrorTableAwareChainedTransformer.java`, 
`Transformer.java`, and tests `TestHoodieClientOnCopyOnWriteStorage.java`, 
`TestErrorTableAwareChainedTransformer.java`, `TestChainedTransformer.java`.
   No code was copied from other projects. 11 test files.
   
   ### Impact
   
   Adds public API: `InstantAwareTransformer`, `Transformer.onPreCommit`, 
`Transformer.onCommit`, `Transformer.close` (with `Transformer` extending 
`AutoCloseable`), `HoodiePreCommitRefusalException` and `CompletedWrite`. A 
stream without an instant-aware transformer starts its instant after the 
transformer, is not called back by `onCommit`, and its transformers' 
`onPreCommit` is the default no-op, so its behaviour is unchanged. Closing the 
streamer closes its transformer; the default `close()` does nothing.
   
   ### Risk Level
   
   medium: the change touches the order of instant creation, the commit call 
and rollback in `StreamSync` for instant-aware rounds, and the transformer 
close in `StreamSync.close`. Covered by 
`TestStreamSyncInstantAwareTransformer`, 
`TestStreamSyncTransformerCommitHooks`, `TestStreamSyncCommitOrderFlag`, 
`TestStreamSyncInflightMarker`, `TestStreamSyncRollbackOnRefusal`, 
`TestTransformerCommitCallback`, `TestCompletedWrite` and 
`TestStreamSyncTransformerLifecycle`; module compile, checkstyle and RAT on JDK 
11 / Spark 3.5 / Scala 2.12; GitHub Java CI runs on the stack tip.
   
   ### Documentation Update
   
   none. The new interfaces and hooks carry Javadoc; no new configs.
   
   ### Contributor's checklist
   
   - [x] Read through [contributor's 
guide](https://hudi.apache.org/contribute/how-to-contribute)
   - [x] Enough context is provided in the sections above
   - [x] Adequate tests were added if applicable
   


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