Skip to content

[AMORO-4166] [Improvement]: Implement heap-based flush mechanism for SortedPosDeleteWriter to prevent OOM.#4276

Open
slfan1989 wants to merge 2 commits into
apache:masterfrom
slfan1989:amoro-4166
Open

[AMORO-4166] [Improvement]: Implement heap-based flush mechanism for SortedPosDeleteWriter to prevent OOM.#4276
slfan1989 wants to merge 2 commits into
apache:masterfrom
slfan1989:amoro-4166

Conversation

@slfan1989

Copy link
Copy Markdown
Contributor

Why are the changes needed?

Close #4166.

SortedPosDeleteWriter currently only flushes buffered position deletes based on a record count threshold, which can cause OutOfMemoryError (OOM) in memory-constrained environments when processing large-scale delete operations.

There was a TODO comment in the code indicating the need for a heap memory-based flush policy:

// TODO Flush buffer based on the policy that checking whether whole heap memory size exceed the
// threshold.

This PR implements the heap-based flush mechanism to prevent OOM issues by monitoring JVM heap usage and triggering flush when memory pressure is detected, while maintaining backward compatibility.

Brief change log

Core Implementation:

  • SortedPosDeleteWriter:
    • Added HeapUsageProvider interface to monitor JVM heap memory (max/used)
    • Implemented shouldFlushByHeap() method with safety guards (minimum records, valid ratio check)
    • Modified delete() logic to flush when records >= recordsNumThreshold || shouldFlushByHeap()
    • Added multiple constructor overloads to support new parameters while maintaining backward compatibility

Configuration:

  • TableProperties: Added three new table properties:
    • pos-delete.flush.heap.ratio (default: 0.8) - Heap usage ratio threshold
    • pos-delete.flush.records (default: Long.MAX_VALUE) - Record count threshold
    • pos-delete.flush.heap.min-records (default: 1000) - Minimum records before heap flush

How was this patch tested?

  • Add some test cases that check the changes thoroughly including negative and positive cases if possible
    • Added TestSortedPosDeleteWriterHeapFlush with mock HeapUsageProvider to test heap-based flush logic
    • Test case 1: Verify flush is triggered when heap usage exceeds threshold
    • Test case 2: Verify heap flush is disabled when ratio is set to 0

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? JavaDocs

@github-actions github-actions Bot added module:mixed-spark Spark module for Mixed Format module:mixed-hive Hive moduel for Mixed Format labels Jul 19, 2026
@slfan1989

Copy link
Copy Markdown
Contributor Author

@zhoujinsong Could you please help review this PR when available? Thank you very much!

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

Labels

module:mixed-hive Hive moduel for Mixed Format module:mixed-spark Spark module for Mixed Format

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement]: Implement heap-based flush mechanism for SortedPosDeleteWriter to prevent OOM

1 participant