Skip to content

feat: [DNM] Async instant generation fixes over 0.14.1 - #18768

Open
cshuo wants to merge 8 commits into
apache:release-0.14.1from
cshuo:cp_fixes_for_ub
Open

cshuo wants to merge 8 commits into
apache:release-0.14.1from
cshuo:cp_fixes_for_ub

Conversation

@cshuo

@cshuo cshuo commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Describe the issue this Pull Request addresses

Summary and Changelog

Impact

Risk Level

Documentation Update

Contributor's checklist

  • Read through contributor's guide
  • Enough context is provided in the sections above
  • Adequate tests were added if applicable

danny0405 and others added 4 commits May 18, 2026 13:59
)

The new instant time generation utilizes RPC request to coordinate creation of new instants.
Each write task will send an RPC request to the coordinator for the instant time, the coordinator
uses a global lock to guard the access from multiple tasks.

Now one checkpoint id corresponds to one instant.

Basic work flow:

* write task send request: current ckp id
* write task expected response: the instant time
* coordinator mappings of checkpoint and instant: ckp-id → {instant → {write-task-id → write meta event}}

Note that the ckp id used in the request is the last known id instead of the current checkpoint, if a task is restored
from a state of the current job, it is the state checkpoint id, otherwise -1 for fresh new job.

(cherry picked from commit e34a7ab)
@cshuo cshuo changed the title Cp fixes for ub [DNM] Cp fixes for ub May 18, 2026
@github-actions github-actions Bot added the size:XL PR with lines of changes > 1000 label May 18, 2026
@cshuo
cshuo force-pushed the cp_fixes_for_ub branch from 1c09f14 to 6c0e4cb Compare May 18, 2026 12:33
@cshuo
cshuo force-pushed the cp_fixes_for_ub branch from d94088c to 7e15ec6 Compare May 18, 2026 16:13
@cshuo
cshuo force-pushed the cp_fixes_for_ub branch from 7e15ec6 to d029073 Compare May 19, 2026 01:03
@cshuo cshuo changed the title [DNM] Cp fixes for ub feat: [DNM] Cp async instant generation fixes over 0.14.1 May 19, 2026
@cshuo cshuo changed the title feat: [DNM] Cp async instant generation fixes over 0.14.1 feat: [DNM] Async instant generation fixes over 0.14.1 May 19, 2026

@hudi-agent hudi-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This review was generated by an AI agent and may contain mistakes. Please verify any suggestions before applying.

Thanks for the contribution! This PR backports async instant generation to 0.14.1, replacing the file-based CkpMetadata queue with direct coordinator-task communication via CoordinationRequest/Response and refactoring the Flink write path and its tests accordingly. A few correctness concerns are worth a closer look — notably uninitialized maps in the new mock keyed state classes, an unguarded await in CommitGuard, a silent default change in HoodieFlinkTable.create, a default flip in FlinkOptions, exception handling in the new coordinator request path, and a primitive/boxed mismatch on WriteMetadataEvent. Please take a look at the inline comments, and this should be ready for a Hudi committer or PMC member to take it from here. A few minor naming and dead code nits below. a few naming and type-consistency suggestions below.

public MockKeyedListState(MockKeyContext keyContext) {
Objects.requireNonNull(keyContext, "keyContext is null");
this.keyContext = keyContext;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 mockListStateMap is declared on line 34 but never initialized — the constructor only assigns keyContext. Any call to update/add/get/addAll/clear will NPE at the mockListStateMap.computeIfAbsent(...) line. Compare with MockKeyedValueState which initializes this.keyValueStateMap = new HashMap<>() in its constructor. Could you add this.mockListStateMap = new HashMap<>(); here?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

public MockKeyedMapState(MockKeyContext keyContext) {
Objects.requireNonNull(keyContext, "keyContext is null");
this.keyContext = keyContext;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Same issue as MockKeyedListState — mockMapStateMap is never initialized in the constructor, so the first call to any method (get/put/contains/etc.) will NPE on mockMapStateMap.computeIfAbsent(...). Could you add this.mockMapStateMap = new HashMap<>(); here?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

try {
if (!condition.await(commitAckTimeout, TimeUnit.MILLISECONDS)) {
throw new HoodieException("Timeout(" + commitAckTimeout + "ms) while waiting for instants [" + instants + "] to commit");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This await isn't guarded by a predicate, which exposes two issues: (1) if unblock() runs before another thread enters await(), the signal is lost and the waiter blocks for the full commitAckTimeout; (2) every EventBuffers.reset(...) calls unblock(), so if multiple checkpoints are pending, the first commit will wake the waiter and blockFor returns even though there are still pending instants. For CoW upsert (where isBlockingInstantGeneration is true), that breaks the intended serialization across instants. Could we loop while pendingInstants is non-empty (similar to the supplier-based pattern), so the awaiter only proceeds when all pending instants are actually drained? @danny0405

- AI-generated; verify before applying. React 👍/👎 to flag quality.

}

public static <T> HoodieFlinkTable<T> create(HoodieWriteConfig config, HoodieEngineContext context) {
return create(config, context, false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This silently changes the default loadActiveTimelineOnLoad from true to false for every caller of the 2-arg create(config, context). That includes HoodieFlinkWriteClient.getHoodieTable(), FlinkUpgradeDowngradeHelper.getTable(), WriteProfile.getTable(), and FlinkTables.createTableInternal. The new lazy default is the right intent for the per-task write client path, but FlinkUpgradeDowngradeHelper (and arguably WriteProfile) likely expect the timeline to be loaded - upgrade/downgrade reasons over completed instants, and WriteProfile walks getCommitsTimeline(). Was this intentional for those callers, or would it be safer to keep the 2-arg version returning true and have only HoodieFlinkWriteClient.getHoodieTable(false) opt in to lazy loading?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

instantTime = startInstant();
this.eventBuffers.initNewEventBuffer(checkpointId, instantTime, this.parallelism);
} else {
instantTime = instantTimeAndEventBuffer.getLeft();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 If startInstant() throws here (e.g. timeline transition fails, or the lock can't be acquired), the response future is never completed - it's not in a try/catch that completes it exceptionally. The executor's exception hook will call context.failJob(...), but until the JM tears the task down the writer is blocked on response.get() inside Correspondent.requestInstantTime. Could we wrap this body in try { ... } catch (Throwable t) { response.completeExceptionally(t); throw t; } so the writer fails fast rather than hanging?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

private final ClassLoader cl;
private final Thread.UncaughtExceptionHandler errorHandler;

private Thread t;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 nit: t is a pretty opaque name for the field tracking the single created thread — thread (or singleThread) would make the if (t != null) guard in newThread immediately readable.

- AI-generated; verify before applying. React 👍/👎 to flag quality.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Line 269: This silently overrides the user-configured hoodie.cleaner.policy.failed.writes to LAZY whenever non-blocking instant generation is enabled, with no log message. If a user explicitly set EAGER they'll likely be confused when behavior doesn't match their config. Could you at least log a warning when overriding a user-provided value (e.g. when the conf already contains the key with a non-LAZY value)? Or consider validating up-front and failing fast with a clear error.

- AI-generated; verify before applying. React 👍/👎 to flag quality.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Line 306: AssertionError extends Error, not Exception, so if checkWrittenData(expected, 1) fails inside t1, the catch block won't catch it — the thread will die silently and t1.join() will return normally, leaving the test passing despite the failed assertion. This may be why TestWriteMergeOnReadWithCompact.testBlockedInstantTimeRequest documents the test as flaky. Could you catch Throwable and store it in an AtomicReference for the main thread to rethrow after join()?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Line 185: nit: writeConfig is assigned here but never used after this point — it looks like a leftover from the CkpMetadata replacement. Could you remove it (or actually use it if something depends on this call)?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Line 556: nit: assertDataFilesExists — the subject "files" is plural, so it might read more naturally as assertDataFilesExist (and the sibling assertEmptyBaseFiles already follows this pattern implicitly).

- AI-generated; verify before applying. React 👍/👎 to flag quality.

@hudi-agent hudi-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This review was generated by an AI agent and may contain mistakes. Please verify any suggestions before applying.

Thanks for the additional cleanup work! This incremental change is in a different area — it tightens resource handling in HoodieAppendHandle, HoodieMergeHandle, HoodieSortedMergeHandle, the parquet stream writers, HFileBootstrapIndex, and SparkHelpers.scala, adds a new AutoCloseableUtils helper, and makes HoodieFileWriter extend AutoCloseable. The new code looks like a clear net improvement (closes-on-exception, suppressed-exception chaining, second writer still attempted on partial failure in HFileBootstrapIndex.Writer.close). Note: none of the prior findings from earlier rounds (the uninitialized mock state maps, CommitGuard lost-wakeup, HoodieFlinkTable.create default change, StreamWriteOperatorCoordinator uncompleted future, TestWriteCopyOnWrite swallowed AssertionError, the silent FAILED_WRITES_CLEANER_POLICY override in FlinkWriteClients, the FlinkOptions -1 default change, and the assorted nits/javadoc/naming items) appear addressed in this delta — those files were not touched here, so the earlier comments remain open. Please take a look at any inline comments, and this should be ready for a Hudi committer or PMC member to take it from here.

@@ -549,6 +569,7 @@ public void write(Map<String, HoodieRecord<T>> recordMap) {
appendDataAndDeleteBlocks(header, true);
estimatedNumberOfBytesWritten += averageRecordSize * numberOfRecords;
} catch (Exception e) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Closing the writer here (good for the leak) but not calling markClosed() means the handle ends up in a half-state: writer == null but isClosed() is still false. If any caller ever wraps write(recordMap) in a try-finally and then calls close(), close() will skip the early-return, reach appendDataAndDeleteBlocks(...), and NPE on writer.appendBlocks(...) / writer.getLogFile(). Current callers (HoodieSparkMergeOnReadTable, HoodieFlinkMergeOnReadTable) do write(); close(); without finally so this is latent, but would calling markClosed() here too be a cheap way to make the contract safe for future try-with-resources style use?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

@hudi-bot

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

@voonhous

voonhous commented Nov 7, 2026

Copy link
Copy Markdown
Member

Temporarily closing this PR while we debug a GitHub settings error on master (#20471); it will be reopened shortly, no action needed.

@voonhous voonhous closed this Nov 7, 2026
@voonhous voonhous reopened this Nov 7, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL PR with lines of changes > 1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants