Skip to content

Conversation

@sopel39
Copy link
Member

@sopel39 sopel39 commented Jun 11, 2025

Description

- reserve memory before creating a LookupSource
- yield if unspilled pages cannot fit memory immediately

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text:

## General
* Improve spilling reliability for join queries. ({issue}`25976`)

Fixes #25976

sopel39 added 2 commits June 11, 2025 17:43
- reserve memory before creating a LookupSource
- yield if unspilled pages cannot fit memory immediately
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the HashBuilderOperator to better handle reserved memory during lookup source creation and unspilling, and updates revocable memory after compaction. It also adds new tests to validate these memory-waiting behaviors under spill/no-spill scenarios.

  • Reserve memory before building the lookup source in finishInput and finishLookupSourceUnspilling, and yield if reservation is pending.
  • Update startMemoryRevoke to adjust the revocable memory context after compaction.
  • Add DriverTestContext helper and new tests in TestHashJoinOperator to verify that the operator waits for memory when finishing input and unspilling.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
core/trino-main/src/main/java/io/trino/operator/join/HashBuilderOperator.java Added pre-reservation of memory contexts in finishInput, unspill logic changes, and compaction update in startMemoryRevoke.
core/trino-main/src/test/java/io/trino/operator/join/TestHashJoinOperator.java Introduced DriverTestContext helper and new tests to assert that HashBuilderOperator waits for memory under spill/unspill conditions.
Comments suppressed due to low confidence (2)

core/trino-main/src/main/java/io/trino/operator/join/HashBuilderOperator.java:513

  • [nitpick] Add a comment explaining that finishInput should be retried once the pending memory reservation completes, so readers understand why we return early here.
if (!reserved.isDone()) {

core/trino-main/src/main/java/io/trino/operator/join/HashBuilderOperator.java:587

  • [nitpick] The flag unspilledPagesAdded could be renamed to something like pagesUnspilled or unspillCompleted to more clearly reflect that it tracks whether pages have been transferred into the index.
if (!unspilledPagesAdded) {

@sopel39 sopel39 force-pushed the oss/spill_report_improvement branch from 3b7da8e to dbb8e62 Compare June 12, 2025 08:55
@sopel39 sopel39 requested a review from raunaqmorarka June 12, 2025 08:55
This reduces congestion in the memory tracking system by coarsening the granularity of memory tracking.
In this paradigm, the most small incremental increases at the byte granularity will not actually result in a different coarse granularity value, so no reporting into memory tracking is necessary.
@sopel39 sopel39 force-pushed the oss/spill_report_improvement branch from 2c6594c to bc1bc31 Compare June 12, 2025 09:44
@sopel39 sopel39 requested a review from raunaqmorarka June 12, 2025 11:45
Copy link
Member

@raunaqmorarka raunaqmorarka left a comment

Choose a reason for hiding this comment

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

lgtm % test failures

@sopel39
Copy link
Member Author

sopel39 commented Jun 13, 2025

flakes due to #21078

@sopel39 sopel39 merged commit 223bcc5 into trinodb:master Jun 13, 2025
283 of 290 checks passed
@sopel39 sopel39 deleted the oss/spill_report_improvement branch June 13, 2025 09:39
@github-actions github-actions bot added this to the 477 milestone Jun 13, 2025
@sopel39
Copy link
Member Author

sopel39 commented Jun 13, 2025

cc @osscm

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

Development

Successfully merging this pull request may close these issues.

Improve memory tracking for spillable HashBuilderOperator.

2 participants