Skip to content

fix(flink): use partition-aware file groups for Flink NBCC bulk inserts - #19518

Open
cshuo wants to merge 2 commits into
apache:masterfrom
cshuo:fix/flink-nbcc-bulk-insert-file-groups
Open

fix(flink): use partition-aware file groups for Flink NBCC bulk inserts#19518
cshuo wants to merge 2 commits into
apache:masterfrom
cshuo:fix/flink-nbcc-bulk-insert-file-groups

Conversation

@cshuo

@cshuo cshuo commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Describe the issue this Pull Request addresses

Closes #19517.

With Flink bucket bulk inserts under non-blocking concurrency control (NBCC), fixed bucket file IDs can repeat across partitions. Sorting and caching write handles only by file ID can therefore mix records from different partitions or reuse the wrong handle.

Summary and Changelog

  • Include the partition path in regular and LSM bucket internal sort rows only when NBCC is enabled, and sort by the partition-aware file group identity.
  • Cache NBCC write handles by HoodieFileGroupId while retaining the existing file-ID-only path for non-NBCC writes.
  • Add regression coverage for both sorted and unsorted NBCC bucket bulk inserts with identical file IDs across partitions.

Impact

This change affects only Flink bucket bulk inserts using NBCC. It introduces no public API or configuration changes. Non-NBCC row schemas, sort keys, and handle lookup behavior remain unchanged, avoiding additional overhead on existing paths; NBCC sort rows carry one additional partition-path field.

Risk Level

Low. The behavior change is scoped to NBCC bucket bulk inserts and is covered by a parameterized regression test for sorted and unsorted input.

Documentation Update

None.

Contributor's checklist

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

@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 working on this! The PR makes Flink bucket bulk inserts under NBCC partition-aware by prepending the partition path to the internal sort row and keying write handles by HoodieFileGroupId, while leaving the non-NBCC path (which already gets unique per-partition file IDs) unchanged. The scoping is sound and the sorted/unsorted handle logic traces through correctly. One coupling worth double-checking noted inline. 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. Two small readability nits below.

@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 working on this! The PR fixes Flink bucket bulk inserts under NBCC where fixed bucket file IDs can repeat across partitions, by making sort rows and write-handle caching partition-aware only when NBCC is enabled. The scoping to NBCC looks correct — non-NBCC file IDs are UUID-based and already unique per partition — and the producer (row builders/sorters) and consumer (writer decode) both derive the flag from the same config, keeping the in-flight sort-row layouts consistent. No new issues flagged from this automated pass; the round-1 concerns appear addressed. 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. One naming concern where a needFixedFileIdSuffix value is passed into an isNonBlockingConcurrencyControl parameter.

cc @yihua

RowType sortRowType =
LsmBucketBulkInsertWriterHelper.rowTypeWithFileIdAndKey(rowType);
LsmBucketBulkInsertWriterHelper.rowTypeWithFileIdAndKey(
rowType, needFixedFileIdSuffix);

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: these helpers take a param named isNonBlockingConcurrencyControl, but here you're passing needFixedFileIdSuffix. Even if the two coincide today, conflating them makes this harder to reason about later — could you align the naming (or pass the NBCC flag explicitly)?

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

@github-actions github-actions Bot added the size:M PR with lines of changes in (100, 300] label Aug 5, 2026
HoodieRowDataCreateHandle rowCreateHandle = new HoodieRowDataCreateHandle(hoodieTable, writeConfig, partitionPath, fileId,
instantTime, taskPartitionId, totalSubtaskNum, taskEpochId, writerSchema, preserveHoodieMetadata, isAppendMode && !populateMetaFields);
handles.put(fileId, rowCreateHandle);
handles.put(handleKey, rowCreateHandle);

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.

can we just sort the inputs with _fg_id and partiiton fields instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Adding the _fg field wraps the input into a nested row, so the original partition field becomes record.partition_field. Reusing it directly would require enhancing the sorter to support nested fields, including comparator and normalized-key generation, since it currently supports only top-level fields.

Adding the partition path to the wrapper row has limited overhead: it was already computed in the writer helper, and now the same computation is simply moved earlier and reused for sorting and writing.

@cshuo
cshuo force-pushed the fix/flink-nbcc-bulk-insert-file-groups branch from ffd19fd to 87c32b1 Compare August 6, 2026 07:14

@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 working on this! This PR fixes Flink NBCC bucket bulk inserts so that fixed bucket file IDs repeating across partitions no longer mix records or reuse the wrong write handle, by making the sort rows and handle cache partition-aware. I traced the row encode/decode paths and confirmed the NBCC flag is derived from the same config everywhere (Pipelines' needFixedFileIdSuffix and the helper's isNonBlockingConcurrencyControl both come from OptionsResolver.isNonBlockingConcurrencyControl), so encoding and decoding stay consistent. No new correctness issues flagged from this automated pass beyond what prior rounds raised — a Hudi committer or PMC member can take it from here for a final review. One naming inconsistency worth addressing, otherwise the code is clean and well-commented.

cc @yihua

needFixedFileIdSuffix);
return GenericRowData.of(StringData.fromString(fileId), record);
return needFixedFileIdSuffix
? GenericRowData.of(

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: needFixedFileIdSuffix is used here (and in LsmBucketBulkInsertWriterHelper.rowWithFileIdAndKey) as a stand-in for the NBCC flag, while every other new method in this PR names the same concept isNonBlockingConcurrencyControl. A future reader has to independently verify these are always equivalent. Could you rename the parameter to isNonBlockingConcurrencyControl (or at least add a brief inline comment) to make the connection explicit?

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

@codecov-commenter

codecov-commenter commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.84127% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.59%. Comparing base (c4b3893) to head (87c32b1).
⚠️ Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
...hudi/sink/bucket/BucketBulkInsertWriterHelper.java 63.33% 3 Missing and 8 partials ⚠️
...i/sink/bucket/LsmBucketBulkInsertWriterHelper.java 82.14% 0 Missing and 5 partials ⚠️
...ain/java/org/apache/hudi/sink/utils/Pipelines.java 40.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #19518      +/-   ##
============================================
- Coverage     76.60%   76.59%   -0.01%     
- Complexity    32226    32230       +4     
============================================
  Files          2520     2520              
  Lines        139014   139050      +36     
  Branches      16699    16706       +7     
============================================
+ Hits         106492   106511      +19     
- Misses        24909    24919      +10     
- Partials       7613     7620       +7     
Components Coverage Δ
hudi-common 83.20% <ø> (-0.02%) ⬇️
hudi-client 81.95% <ø> (-0.02%) ⬇️
hudi-flink 83.94% <69.84%> (-0.04%) ⬇️
hudi-spark-datasource 70.62% <ø> (+<0.01%) ⬆️
hudi-utilities 73.67% <ø> (+0.04%) ⬆️
hudi-cli 15.32% <ø> (ø)
hudi-hadoop 63.50% <ø> (ø)
hudi-sync 70.95% <ø> (+0.02%) ⬆️
hudi-io 79.36% <ø> (-0.10%) ⬇️
hudi-timeline-service 83.44% <ø> (ø)
hudi-cloud 64.06% <ø> (ø)
hudi-kafka-connect 53.20% <ø> (ø)
Flag Coverage Δ
common-and-other-modules 49.82% <55.55%> (-0.01%) ⬇️
flink-integration-tests 48.81% <69.84%> (+0.01%) ⬆️
hadoop-mr-java-client 43.75% <ø> (-0.01%) ⬇️
integration-tests 13.57% <0.00%> (-0.01%) ⬇️
spark-client-hadoop-common 49.62% <ø> (-0.01%) ⬇️
spark-java-tests 51.50% <ø> (-0.02%) ⬇️
spark-scala-tests 45.99% <ø> (-0.03%) ⬇️
utilities 36.60% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ain/java/org/apache/hudi/sink/utils/Pipelines.java 85.76% <40.00%> (-0.33%) ⬇️
...i/sink/bucket/LsmBucketBulkInsertWriterHelper.java 86.11% <82.14%> (-13.89%) ⬇️
...hudi/sink/bucket/BucketBulkInsertWriterHelper.java 68.96% <63.33%> (-10.53%) ⬇️

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hudi-bot

hudi-bot commented Aug 6, 2026

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

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

Labels

size:M PR with lines of changes in (100, 300]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flink NBCC bulk insert may mix file groups across partitions

5 participants