Skip to content

feat(native): Add config for asyc cache numShards#27073

Merged
xiaoxmeng merged 1 commit intoprestodb:masterfrom
kewang1024:cache-config
Feb 4, 2026
Merged

feat(native): Add config for asyc cache numShards#27073
xiaoxmeng merged 1 commit intoprestodb:masterfrom
kewang1024:cache-config

Conversation

@kewang1024
Copy link
Copy Markdown
Collaborator

@kewang1024 kewang1024 commented Feb 3, 2026

== NO RELEASE NOTE ==

Summary by Sourcery

Add configurable shard count for the async data cache and wire it through server initialization.

New Features:

  • Introduce a new system config option to control the number of async cache shards with a default value.
  • Expose the async cache shard count to the async data cache options during server initialization.

Tests:

  • Add unit tests covering default and custom values for the async cache shard count system config.

@kewang1024 kewang1024 requested review from a team as code owners February 3, 2026 18:10
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Feb 3, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Feb 3, 2026

Reviewer's Guide

Introduce a new configuration property async-cache-num-shards to control the number of shards used by the async data cache, plumb it through SystemConfig with a default of 4, and pass it into AsyncDataCache options along with unit tests for the default and override behavior.

Sequence diagram for passing async cache numShards into AsyncDataCache

sequenceDiagram
    actor Admin
    participant SystemConfig
    participant PrestoServer
    participant AsyncDataCache

    Admin->>SystemConfig: Set async-cache-num-shards (optional)
    Admin->>PrestoServer: Start server
    PrestoServer->>SystemConfig: asyncCacheMaxSsdWriteRatio()
    SystemConfig-->>PrestoServer: maxSsdWriteRatio
    PrestoServer->>SystemConfig: asyncCacheSsdSavableRatio()
    SystemConfig-->>PrestoServer: ssdSavableRatio
    PrestoServer->>SystemConfig: asyncCacheMinSsdSavableBytes()
    SystemConfig-->>PrestoServer: minSsdSavableBytes
    PrestoServer->>SystemConfig: asyncCacheNumShards()
    SystemConfig-->>PrestoServer: numShards (default 4 or overridden)
    PrestoServer->>AsyncDataCache: create(allocator, ssd, Options{maxSsdWriteRatio, ssdSavableRatio, minSsdSavableBytes, numShards})
    AsyncDataCache-->>PrestoServer: cache_instance_with_shards
Loading

Class diagram for new async cache numShards configuration

classDiagram
    class ConfigBase

    class SystemConfig {
      <<Config>>
      +static constexpr string_view kAsyncCacheNumShards
      +int32_t asyncCacheMinSsdSavableBytes() const
      +int32_t asyncCacheNumShards() const
      +std_chrono_duration_double asyncCachePersistenceInterval() const
      +bool asyncCacheSsdDisableFileCow() const
    }

    class PrestoServer {
      +void initializeVeloxMemory()
      -shared_ptr_AsyncDataCache cache_
    }

    class AsyncDataCacheOptions {
      +double maxSsdWriteRatio
      +double ssdSavableRatio
      +int32_t minSsdSavableBytes
      +int32_t numShards
    }

    class AsyncDataCache {
      +static shared_ptr_AsyncDataCache create(Allocator allocator, unique_ptr_SsdCache ssd, AsyncDataCacheOptions options)
    }

    ConfigBase <|-- SystemConfig
    PrestoServer ..> SystemConfig : reads_config
    PrestoServer ..> AsyncDataCacheOptions : constructs
    PrestoServer ..> AsyncDataCache : create_with_numShards
    AsyncDataCacheOptions ..> AsyncDataCache : used_to_configure
Loading

File-Level Changes

Change Details Files
Add async-cache-num-shards as a new system configuration option with default and accessor
  • Declare new async-cache-num-shards key and documentation comment in the system configuration header
  • Register async-cache-num-shards in the SystemConfig constructor with a numeric default value of 4
  • Expose an asyncCacheNumShards() getter that reads the optional integer property
presto-native-execution/presto_cpp/main/common/Configs.h
presto-native-execution/presto_cpp/main/common/Configs.cpp
Wire async-cache-num-shards into PrestoServer async cache initialization
  • Extend AsyncDataCache::Options construction to include asyncCacheNumShards from SystemConfig when creating the cache
presto-native-execution/presto_cpp/main/PrestoServer.cpp
Add unit test coverage for async-cache-num-shards config behavior
  • Add a new ConfigTest case validating the default asyncCacheNumShards value and an overridden value via configuration initialization
presto-native-execution/presto_cpp/main/common/tests/ConfigTest.cpp

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

@kewang1024 kewang1024 requested review from xiaoxmeng and zacw7 February 3, 2026 18:11
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 left some high level feedback:

  • Given the comment that async-cache-num-shards "must be a power of 2", consider adding explicit validation (and a clear error message) when reading this config to guard against non-power-of-two or non-positive values rather than silently accepting bad input.
  • It may be worth clarifying in the new test (or via an additional one) how the system behaves when async-cache-num-shards is set to an invalid value (e.g., 0 or negative), to ensure the contract around this config is well-defined and enforced.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Given the comment that `async-cache-num-shards` "must be a power of 2", consider adding explicit validation (and a clear error message) when reading this config to guard against non-power-of-two or non-positive values rather than silently accepting bad input.
- It may be worth clarifying in the new test (or via an additional one) how the system behaves when `async-cache-num-shards` is set to an invalid value (e.g., 0 or negative), to ensure the contract around this config is well-defined and enforced.

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.

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.

Please include documentation for the new property, as described in Designing Your Code in CONTRIBUTING.md:

"All new language features, new functions, session and config properties, and major features have documentation added"

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.

@kewang1024 thanks!

@xiaoxmeng xiaoxmeng merged commit e100648 into prestodb:master Feb 4, 2026
83 of 84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:Meta PR from Meta

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants