Skip to content

perf(flink): buffer unsorted data and index writes in sequential pages - #21004

Queued
cshuo wants to merge 2 commits into
apache:masterfrom
cshuo:perf/flink-sequential-bucket-buffer
Queued

cshuo wants to merge 2 commits into
apache:masterfrom
cshuo:perf/flink-sequential-bucket-buffer

Conversation

@cshuo

@cshuo cshuo commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Describe the issue this Pull Request addresses

Closes apache/hudi#20993.

The Flink stream writer uses a StableSortBuffer even for data buckets and record-index batches that it reads in arrival order. On these paths, the buffer stores an 8-byte row offset and a 1-byte normalized key per row, then looks up each offset during flush. The rows are already laid out in the required order, so the index consumes writer memory without changing the output order.

Summary and Changelog

Commit: perf(flink): buffer unsorted data and index writes in sequential pages (3994b655525)

  • Use SequentialRowDataBuffer for non-LSM data buckets and for IndexWriteFunction. LSM data buckets retain StableSortBuffer so they still sort by record key and preserve arrival order for equal keys.
  • Reuse Flink's paged row serializer and read rows sequentially. Advance the row count only after a complete append, so a flush cannot expose a partially written row if the page pool is exhausted.
  • After an index flush, return the old buffer's pages to the pool and create a fresh buffer. If an append triggered the flush, retry that row once in the fresh buffer. The existing index deduplication logic is unchanged.

Impact

Buffer usage for 100,000 BIGINT/VARBINARY rows with 32 KiB pages:

Typical payload Before After Reduction
16 B 193 pages 165 pages 14.51%
128 B 535 pages 507 pages 5.23%

Both inputs saved 896 KiB and preserved row contents and order. LSM sorting is unchanged. End-to-end performance was not measured.

Risk Level

Medium. This changes buffering on two Flink write paths, where incorrect page traversal or reuse after a failed append could lose or corrupt rows. On the final commit, 53 targeted tests passed on Flink 1.20.1 with JDK 17. Coverage includes cross-page nested rows, mid-append exhaustion, bucket preemption and retry, checkpoint flushes, managed-page reclamation, and a record-index update after a pressure-triggered flush.

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

@cshuo
cshuo requested a review from danny0405 December 1, 2026 03:37
@github-actions github-actions Bot added the size:M PR with lines of changes in (100, 300] label Dec 1, 2026
@codecov-commenter

codecov-commenter commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.95%. Comparing base (b546f28) to head (bcd8125).
⚠️ Report is 43 commits behind head on master.

Files with missing lines Patch % Lines
...ache/hudi/sink/buffer/SequentialRowDataBuffer.java 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #21004   +/-   ##
=========================================
  Coverage     80.95%   80.95%           
  Complexity    36550    36550           
=========================================
  Files          2593     2593           
  Lines        148934   148979   +45     
  Branches      18529    18535    +6     
=========================================
+ Hits         120571   120610   +39     
- Misses        20000    20004    +4     
- Partials       8363     8365    +2     
Components Coverage Δ
hudi-common 84.21% <ø> (-0.03%) ⬇️
hudi-client 84.18% <ø> (+0.02%) ⬆️
hudi-flink 86.43% <97.61%> (+0.09%) ⬆️
hudi-spark-datasource 74.40% <ø> (-0.10%) ⬇️
hudi-utilities 79.27% <ø> (-0.02%) ⬇️
hudi-cli 70.92% <ø> (ø)
hudi-hadoop 71.21% <ø> (+0.01%) ⬆️
hudi-sync 77.30% <ø> (ø)
hudi-io 81.57% <ø> (-0.10%) ⬇️
hudi-timeline-service 84.22% <ø> (+0.65%) ⬆️
hudi-cloud 81.11% <ø> (+0.09%) ⬆️
hudi-kafka-connect 58.40% <ø> (ø)
Flag Coverage Δ
common-and-other-modules 44.77% <97.61%> (+0.01%) ⬆️
flink-integration-tests 41.18% <83.33%> (+<0.01%) ⬆️
hadoop-mr-java-client 44.66% <ø> (-0.01%) ⬇️
integration-tests 14.62% <ø> (+<0.01%) ⬆️
spark-client-hadoop-common 38.13% <ø> (-0.01%) ⬇️
spark-java-tests 52.51% <ø> (+0.01%) ⬆️
spark-scala-tests 53.41% <ø> (-0.01%) ⬇️
utilities 42.48% <ø> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
...java/org/apache/hudi/sink/StreamWriteFunction.java 81.18% <100.00%> (+0.24%) ⬆️
...g/apache/hudi/sink/buffer/RowDataBinaryBuffer.java 100.00% <100.00%> (ø)
...ava/org/apache/hudi/sink/buffer/RowDataBucket.java 100.00% <100.00%> (ø)
.../org/apache/hudi/sink/buffer/StableSortBuffer.java 94.20% <100.00%> (+0.26%) ⬆️
...udi/sink/partitioner/index/IndexWriteFunction.java 98.50% <100.00%> (ø)
...n/java/org/apache/hudi/sink/utils/BufferUtils.java 71.42% <ø> (-1.91%) ⬇️
...ache/hudi/sink/buffer/SequentialRowDataBuffer.java 96.87% <96.87%> (ø)

... and 27 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.

@github-actions github-actions Bot added size:L PR with lines of changes in (300, 1000] and removed size:M PR with lines of changes in (100, 300] labels Dec 2, 2026
@hudi-bot

hudi-bot commented Dec 2, 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

@danny0405 danny0405 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.

+1, let's make the CI pass

@danny0405
danny0405 added this pull request to the merge queue Dec 3, 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:L PR with lines of changes in (300, 1000]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flink] Use a sequential paged buffer for write buckets emitted in arrival order

4 participants