Skip to content

fix: Register worker functions before system access control#26945

Merged
kevintang2022 merged 1 commit intoprestodb:masterfrom
kevintang2022:register-native-functions-before-load-access-control
Jan 12, 2026
Merged

fix: Register worker functions before system access control#26945
kevintang2022 merged 1 commit intoprestodb:masterfrom
kevintang2022:register-native-functions-before-load-access-control

Conversation

@kevintang2022
Copy link
Copy Markdown
Contributor

@kevintang2022 kevintang2022 commented Jan 12, 2026

Description

Register the functions earlier so that they are available before the Presto server begins taking traffic.

Motivation and Context

There is a race condition where a query is submitted before all functions are fully registered, so there might be function not registered errors.

Impact

No impact on functionality

Test Plan

No impact, so just keep existing behaviors

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== NO RELEASE NOTE ==

@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Jan 12, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Jan 12, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Moves registration of built-in sidecar worker functions earlier in PrestoServer startup so functions are available before system access control is loaded and the server starts taking traffic, eliminating a race where queries can arrive before function registration completes.

Sequence diagram for updated PrestoServer startup function registration

sequenceDiagram
    participant PrestoServer
    participant Injector
    participant FeaturesConfig
    participant WorkerFunctionRegistryTool
    participant FunctionAndTypeManager
    participant AccessControlManager

    PrestoServer->>Injector: getInstance FeaturesConfig
    Injector-->>PrestoServer: FeaturesConfig
    PrestoServer->>FeaturesConfig: isBuiltInSidecarFunctionsEnabled
    alt builtInSidecarFunctionsEnabled
        PrestoServer->>Injector: getInstance WorkerFunctionRegistryTool
        Injector-->>PrestoServer: WorkerFunctionRegistryTool
        PrestoServer->>WorkerFunctionRegistryTool: getWorkerFunctions
        WorkerFunctionRegistryTool-->>PrestoServer: List SqlFunction
        PrestoServer->>Injector: getInstance FunctionAndTypeManager
        Injector-->>PrestoServer: FunctionAndTypeManager
        PrestoServer->>FunctionAndTypeManager: registerWorkerFunctions functions
    end

    PrestoServer->>Injector: getInstance AccessControlManager
    Injector-->>PrestoServer: AccessControlManager
    PrestoServer->>AccessControlManager: loadSystemAccessControl

    PrestoServer->>PrestoServer: continue startup and begin taking traffic
Loading

Flow diagram for updated PrestoServer startup order

graph TD
    A[PrestoServer run start] --> B[Create Injector and core services]
    B --> C[Load type managers]
    C --> D[Load session property configuration]
    D --> E[Load resource group configuration]

    E --> F{builtInSidecarFunctionsEnabled}
    F -- Yes --> G[Get WorkerFunctionRegistryTool]
    G --> H[Get worker functions List SqlFunction]
    H --> I[Get FunctionAndTypeManager]
    I --> J[Register worker functions]
    F -- No --> K[Skip worker function registration]

    J --> L{isResourceManager}
    K --> L

    L -- No --> M[Load system access control]
    L -- Yes --> N[Skip system access control load]

    M --> O[Load remaining managers and filters]
    N --> O

    O --> P[Server ready and begins taking traffic]
Loading

File-Level Changes

Change Details Files
Register worker functions earlier in server startup, before system access control is loaded, instead of later after plan checker providers.
  • Invoke FeaturesConfig to check if built-in sidecar functions are enabled immediately after loading type managers and configuration managers.
  • When enabled, obtain worker functions from WorkerFunctionRegistryTool via the injector and register them with FunctionAndTypeManager at this earlier point in run().
  • Remove the later worker function registration block that used to run after plan checker providers were loaded to avoid duplicate registration.
presto-main/src/main/java/com/facebook/presto/server/PrestoServer.java

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

@kevintang2022 kevintang2022 changed the title fix: Register worker functions after system access control fix: Register worker functions before system access control Jan 12, 2026
@kevintang2022 kevintang2022 marked this pull request as ready for review January 12, 2026 17:36
@kevintang2022 kevintang2022 requested a review from a team as a code owner January 12, 2026 17:36
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:

  • Consider adding a short comment around the new worker function registration block explaining why it must occur before loadSystemAccessControl() to prevent future refactors from reintroducing the race condition.
  • You can slightly improve readability and avoid repeated injector calls by caching FeaturesConfig, WorkerFunctionRegistryTool, and FunctionAndTypeManager in local variables before using them in the new block.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding a short comment around the new worker function registration block explaining why it must occur before `loadSystemAccessControl()` to prevent future refactors from reintroducing the race condition.
- You can slightly improve readability and avoid repeated injector calls by caching `FeaturesConfig`, `WorkerFunctionRegistryTool`, and `FunctionAndTypeManager` in local variables before using them in the new block.

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.

@kevintang2022 kevintang2022 merged commit b200d1f into prestodb:master Jan 12, 2026
86 of 90 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.

3 participants