Skip to content

feat: Add session property aggregation_memory_compaction_reclaim_enabled#27221

Merged
duxiao1212 merged 1 commit intoprestodb:masterfrom
duxiao1212:export-D94130609
Mar 4, 2026
Merged

feat: Add session property aggregation_memory_compaction_reclaim_enabled#27221
duxiao1212 merged 1 commit intoprestodb:masterfrom
duxiao1212:export-D94130609

Conversation

@duxiao1212
Copy link
Copy Markdown
Contributor

@duxiao1212 duxiao1212 commented Feb 26, 2026

Summary: Per title

Differential Revision: D94130609

Summary by Sourcery

Add a configurable session property to control lightweight aggregation memory compaction during memory reclaim before spilling.

New Features:

  • Introduce the native_aggregation_memory_compaction_reclaim_enabled session property to toggle lightweight aggregation memory compaction prior to spilling.

Tests:

  • Extend SessionProperties mapping tests to cover the new aggregation memory compaction reclaim session property.
== NO RELEASE NOTE ==

@duxiao1212 duxiao1212 requested review from a team, elharo and steveburnett as code owners February 26, 2026 20:21
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Feb 26, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Feb 26, 2026

Reviewer's Guide

Adds a new session property to control whether lightweight aggregation memory compaction is attempted during memory reclaim before spilling, wiring it through native Presto C++ session properties, Java native worker session properties, query config mapping tests, and updating related constants and documentation scaffolding.

Class diagram for new aggregation_memory_compaction_reclaim_enabled session property wiring

classDiagram
    class SessionProperties {
      +static const char* kAggregationCompactionUnusedMemoryRatio
      +static const char* kAggregationMemoryCompactionReclaimEnabled
      +SessionProperties()
      +std::string toVeloxConfig(const std::string& key)
      +bool hasVeloxConfig(const std::string& key)
    }

    class QueryConfig {
      +static const char* kAggregationCompactionUnusedMemoryRatio
      +static const char* kAggregationMemoryCompactionReclaimEnabled
      +double aggregationCompactionUnusedMemoryRatio()
      +bool aggregationMemoryCompactionReclaimEnabled()
    }

    class NativeWorkerSessionPropertyProvider {
      +static final String NATIVE_AGGREGATION_COMPACTION_BYTES_THRESHOLD
      +static final String NATIVE_AGGREGATION_COMPACTION_UNUSED_MEMORY_RATIO
      +static final String NATIVE_AGGREGATION_MEMORY_COMPACTION_RECLAIM_ENABLED
      +NativeWorkerSessionPropertyProvider(FeaturesConfig featuresConfig)
    }

    class FeaturesConfig {
      +boolean isNativeExecution()
    }

    SessionProperties --> QueryConfig : uses
    NativeWorkerSessionPropertyProvider --> FeaturesConfig : uses
    NativeWorkerSessionPropertyProvider ..> SessionProperties : aligns_property_keys
Loading

Flow diagram for aggregation_memory_compaction_reclaim_enabled behavior during memory reclaim

flowchart TD
    A["Start memory reclaim in aggregation operator"] --> B{"aggregation_memory_compaction_reclaim_enabled?"}
    B -- "true" --> C["Perform lightweight memory compaction\n(e.g., free dead aggregate state)"]
    C --> D{"Is further reclaim needed?"}
    D -- "yes" --> E["Spill aggregation state to disk"]
    D -- "no" --> F["Continue in-memory aggregation"]
    B -- "false" --> E
    E --> G["Resume query execution after spilling"]
    F --> G
Loading

File-Level Changes

Change Details Files
Introduce C++ session property and config wiring for aggregation memory compaction on reclaim.
  • Define kAggregationMemoryCompactionReclaimEnabled constant in SessionProperties header with detailed documentation.
  • Register the new boolean session property in SessionProperties constructor, including description, default value false, and binding to QueryConfig::kAggregationMemoryCompactionReclaimEnabled using the corresponding config getter.
  • Ensure the new property participates in conversion to Velox query config via existing mechanisms.
presto-native-execution/presto_cpp/main/SessionProperties.h
presto-native-execution/presto_cpp/main/SessionProperties.cpp
Expose the new aggregation memory compaction reclaim property on the Java side for native workers and include it in mapping tests.
  • Add NATIVE_AGGREGATION_MEMORY_COMPACTION_RECLAIM_ENABLED constant to NativeWorkerSessionPropertyProvider.
  • Register a new booleanProperty in NativeWorkerSessionPropertyProvider constructor with description, default false, and disabled when nativeExecution is enabled.
  • Extend SessionPropertiesTest mapping validation to include the new property to QueryConfig::kAggregationMemoryCompactionReclaimEnabled.
presto-main-base/src/main/java/com/facebook/presto/sessionpropertyproviders/NativeWorkerSessionPropertyProvider.java
presto-native-execution/presto_cpp/main/tests/SessionPropertiesTest.cpp
Prepare documentation hook for the new session property in the Presto C++ session properties docs.
  • Touch the C++ session properties documentation file to later document the new aggregation memory compaction reclaim property; actual property text may be added in a follow-up.
presto-docs/src/main/sphinx/presto_cpp/properties-session.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="presto-native-execution/presto_cpp/main/tests/SessionPropertiesTest.cpp" line_range="137-138" />
<code_context>
        core::QueryConfig::kAggregationCompactionBytesThreshold},
       {SessionProperties::kAggregationCompactionUnusedMemoryRatio,
        core::QueryConfig::kAggregationCompactionUnusedMemoryRatio},
+      {SessionProperties::kAggregationMemoryCompactionReclaimEnabled,
+       core::QueryConfig::kAggregationMemoryCompactionReclaimEnabled},
       {SessionProperties::kMergeJoinOutputBatchStartSize,
        core::QueryConfig::kMergeJoinOutputBatchStartSize}};
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding tests that cover default and overridden values for the new session property, not just the mapping key.

Right now this only verifies the wiring between the session property name and the `QueryConfig` key. Please also add tests in this file that (1) check the default value of `aggregationMemoryCompactionReclaimEnabled` from `QueryConfig` is propagated through `SessionProperties::toVeloxConfig`, and (2) confirm that explicitly setting the session property to true/false results in the corresponding Velox config value. This will validate the full config → session property → Velox config path for this flag.

Suggested implementation:

```cpp
      {SessionProperties::kAggregationCompactionUnusedMemoryRatio,
       core::QueryConfig::kAggregationCompactionUnusedMemoryRatio},
      {SessionProperties::kAggregationMemoryCompactionReclaimEnabled,
       core::QueryConfig::kAggregationMemoryCompactionReclaimEnabled},
      {SessionProperties::kMergeJoinOutputBatchStartSize,
       core::QueryConfig::kMergeJoinOutputBatchStartSize}};

// Verify the default value from QueryConfig is propagated when the session
// property is not set.
TEST(SessionPropertiesTest,
     AggregationMemoryCompactionReclaimEnabled_DefaultPropagation) {
  // Empty session properties => use QueryConfig defaults.
  std::unordered_map<std::string, std::string> sessionProperties;

  // Construct QueryConfig with defaults.
  core::QueryConfig queryConfig{{}};

  // Build Velox config from session properties + query config.
  velox::Config veloxConfig;
  SessionProperties::toVeloxConfig(sessionProperties, queryConfig, veloxConfig);

  // The Velox config value should match the QueryConfig default.
  EXPECT_EQ(
      veloxConfig.getBool(
          core::QueryConfig::kAggregationMemoryCompactionReclaimEnabled),
      queryConfig.aggregationMemoryCompactionReclaimEnabled());
}

// Verify that explicitly setting the session property to true/false is
// reflected in the resulting Velox config value.
TEST(SessionPropertiesTest,
     AggregationMemoryCompactionReclaimEnabled_OverrideViaSessionProperty) {
  core::QueryConfig queryConfig{{}};

  {
    // Override to true.
    std::unordered_map<std::string, std::string> sessionProperties;
    sessionProperties.emplace(
        SessionProperties::kAggregationMemoryCompactionReclaimEnabled, "true");

    velox::Config veloxConfig;
    SessionProperties::toVeloxConfig(
        sessionProperties, queryConfig, veloxConfig);

    EXPECT_TRUE(veloxConfig.getBool(
        core::QueryConfig::kAggregationMemoryCompactionReclaimEnabled));
  }

  {
    // Override to false.
    std::unordered_map<std::string, std::string> sessionProperties;
    sessionProperties.emplace(
        SessionProperties::kAggregationMemoryCompactionReclaimEnabled, "false");

    velox::Config veloxConfig;
    SessionProperties::toVeloxConfig(
        sessionProperties, queryConfig, veloxConfig);

    EXPECT_FALSE(veloxConfig.getBool(
        core::QueryConfig::kAggregationMemoryCompactionReclaimEnabled));
  }
}

```

These edits assume the following, based on existing conventions in similar tests:
1. `SessionProperties::toVeloxConfig` has a signature compatible with:
   `static void toVeloxConfig(const std::unordered_map<std::string, std::string>&, const core::QueryConfig&, velox::Config&);`
2. `velox::Config` exposes `getBool(const std::string&)` (or a compatible API) and is already included in this test file.
3. `core::QueryConfig` has a method `aggregationMemoryCompactionReclaimEnabled()` returning the typed default for the new flag, and the config map constructor `core::QueryConfig{{}}` (or similar) is valid in this file as used for other tests.

If the existing tests in this file use different container types for session properties, a different Velox config type, or a helper method to build the config (for example a `makeVeloxConfig(...)` helper), you should:
- Replace `std::unordered_map<std::string, std::string>` with the same type used elsewhere (e.g. `facebook::presto::protocol::SessionProperties` or a typedef).
- Replace `velox::Config` and `getBool(...)` with the actual config type and getter used by the other tests (for example `velox::core::Config` and `get<bool>(...)`).
- Construct `core::QueryConfig` using the same initialization pattern already used in this file so that the default value of `aggregationMemoryCompactionReclaimEnabled` is not overridden (e.g. via a helper like `createQueryConfig()` if one exists).

Keep the three expectations identical in spirit:
1. No session property set → Velox config value equals `QueryConfig` default.
2. Session property set to `"true"` → Velox config flag is true.
3. Session property set to `"false"` → Velox config flag is false.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@duxiao1212 duxiao1212 requested a review from xiaoxmeng February 26, 2026 20:23
Copy link
Copy Markdown
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

Thank you for the documentation! Just one nit of phrasing.

xiaoxmeng
xiaoxmeng previously approved these changes Feb 26, 2026
Copy link
Copy Markdown
Contributor

@xiaoxmeng xiaoxmeng left a comment

Choose a reason for hiding this comment

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

@duxiao1212 please address comments before land. Thanks!

duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Feb 26, 2026
…led (prestodb#27221)

Summary:

Per title

Differential Revision: D94130609
Copy link
Copy Markdown
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

LGTM! (docs)

Pull updated branch, new local doc build, looks good. Thanks!

duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 1, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 1, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 1, 2026
…led (prestodb#27221)

Summary:
Pull Request resolved: prestodb#27221

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 1, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 1, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 2, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 2, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 2, 2026
…led (prestodb#27221)

Summary:
Pull Request resolved: prestodb#27221

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 2, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 2, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 3, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 3, 2026
…led (prestodb#27221)

Summary:
Pull Request resolved: prestodb#27221

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Mar 3, 2026
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
…led (prestodb#27221)

Summary:

Per title

Reviewed By: xiaoxmeng

Differential Revision: D94130609
@duxiao1212 duxiao1212 merged commit a9094ae into prestodb:master Mar 4, 2026
81 of 82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants