Skip to content

Conversation

NingGUO520
Copy link

@NingGUO520 NingGUO520 commented Oct 2, 2025

Description

This PR introduces a mechanism that allows a CatalogStore implementation to proactively trigger a refresh of the catalogs managed by the CoordinatorDynamicCatalogManager. This enables Trino to dynamically respond to external changes in catalog configuration without requiring a restart.

Motivation and Context

#26760

Part of the motivation for this work is to support dynamic credential updates for catalogs. For example, a custom CatalogStore that resolves secrets from a service like HashiCorp Vault needs a way to refresh those secrets when they are rotated.

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:

## Section
*  Allow externally-triggered refresh of catalogs. ({issue}`26760`)

## Summary by Sourcery

Enable dynamic, externally-triggered catalog refreshes in the CoordinatorDynamicCatalogManager via the CatalogStore SPI, allowing catalogs to be added, updated, or removed at runtime without restarting Trino.

New Features:
- Allow custom CatalogStore implementations to register a CatalogManager and invoke on-demand catalog refreshes.
- Introduce refreshCatalogsFromStore in CoordinatorDynamicCatalogManager to dynamically add, update, and remove catalogs based on store-provided metadata.
- Extend the SPI with default setCatalogManager in CatalogStore and default refreshCatalogsFromStore in CatalogManager for backward compatibility.

Tests:
- Add TestFilePollingCatalogStore with a FilePollingCatalogStore fixture to verify that file changes trigger catalog refreshes correctly.

Copy link

cla-bot bot commented Oct 2, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@NingGUO520 NingGUO520 changed the title Allow custom catalogstore to trigger catalog refresh [WIP] Allow custom catalogstore to trigger catalog refresh Oct 2, 2025
@NingGUO520 NingGUO520 changed the title [WIP] Allow custom catalogstore to trigger catalog refresh Allow custom catalogstore to trigger catalog refresh Oct 2, 2025
Copy link

cla-bot bot commented Oct 3, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@NingGUO520 NingGUO520 force-pushed the refresh-catalog-in-manager branch from 06942f3 to b585cde Compare October 3, 2025 15:41
Copy link

cla-bot bot commented Oct 3, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@NingGUO520 NingGUO520 force-pushed the refresh-catalog-in-manager branch from b585cde to bed8718 Compare October 6, 2025 09:31
Copy link

cla-bot bot commented Oct 6, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@NingGUO520 NingGUO520 force-pushed the refresh-catalog-in-manager branch from bed8718 to e15b25f Compare October 6, 2025 09:33
Copy link

cla-bot bot commented Oct 6, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

1 similar comment
Copy link

cla-bot bot commented Oct 6, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@NingGUO520 NingGUO520 force-pushed the refresh-catalog-in-manager branch from d5e4a19 to a68e7fc Compare October 7, 2025 09:58
Copy link

cla-bot bot commented Oct 7, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@NingGUO520 NingGUO520 marked this pull request as ready for review October 10, 2025 15:00
Copy link

sourcery-ai bot commented Oct 10, 2025

Reviewer's Guide

This PR empowers Trino to detect external catalog configuration changes by registering a CatalogManager callback in the CatalogStore SPI and implementing a reconciliatory refreshCatalogsFromStore method in CoordinatorDynamicCatalogManager, while providing default interface methods for backward compatibility and end-to-end tests via a FilePollingCatalogStore.

Class diagram for updated CatalogStore and CoordinatorDynamicCatalogManager

classDiagram
    CatalogStore <|.. CoordinatorDynamicCatalogManager
    CatalogStore : +void removeCatalog(CatalogName catalogName)
    CatalogStore : +void setCatalogManager(Object catalogManager)
    CatalogStore : +Collection<StoredCatalog> getCatalogs()
    CatalogStore : <<interface>>
    CatalogStore : +interface StoredCatalog
    CatalogStore : +StoredCatalog.name()
    CatalogStore : +StoredCatalog.loadProperties()
    CatalogStore : +StoredCatalog.version()
    CoordinatorDynamicCatalogManager : +void refreshCatalogsFromStore()
    CoordinatorDynamicCatalogManager : +void dropCatalog(CatalogName catalogName, boolean exists)
    CoordinatorDynamicCatalogManager : +void createCatalog(...)
    CoordinatorDynamicCatalogManager : -CatalogStore catalogStore
    CoordinatorDynamicCatalogManager : -CatalogFactory catalogFactory
    CoordinatorDynamicCatalogManager : -Map activeCatalogs
    CoordinatorDynamicCatalogManager : -Map allCatalogs
    CoordinatorDynamicCatalogManager : -Lock catalogsUpdateLock
    CoordinatorDynamicCatalogManager : -State state
    CoordinatorDynamicCatalogManager : +CoordinatorDynamicCatalogManager(CatalogStore, CatalogFactory, Executor)
    CoordinatorDynamicCatalogManager --> CatalogStore
    CoordinatorDynamicCatalogManager --> CatalogFactory
    CoordinatorDynamicCatalogManager --> CatalogConnector
    CatalogConnector --> Catalog
    Catalog --> CatalogHandle
Loading

File-Level Changes

Change Details Files
Wire up CatalogManager to allow CatalogStore to trigger refreshes
  • Added default setCatalogManager in CatalogStore SPI
  • Added default refreshCatalogsFromStore in CatalogManager SPI
  • Called catalogStore.setCatalogManager(this) in CoordinatorDynamicCatalogManager constructor
CoordinatorDynamicCatalogManager.java
CatalogStore.java
CatalogManager.java
Implement refreshCatalogsFromStore in dynamic catalog manager
  • Lock around updates and check manager state
  • Compute desired vs. current catalogs, remove obsolete entries
  • Reload changed or new catalogs based on version
  • Log successes and errors
CoordinatorDynamicCatalogManager.java
Add file-polling store test triggering refreshs on external changes
  • Introduced FilePollingCatalogStore that hashes property files and polls for changes
  • Invoke catalogManager.refreshCatalogsFromStore on detected updates
  • Validate refresh behavior on add, modify, and delete in TestFilePollingCatalogStore
TestFilePollingCatalogStore.java

Possibly linked issues


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

@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 there - I've reviewed your changes and they look great!

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

## Individual Comments

### Comment 1
<location> `core/trino-main/src/test/java/io/trino/connector/TestFilePollingCatalogStore.java:73-74` </location>
<code_context>
+            assertThat(manager.getCatalog(new CatalogName("my_catalog")).get().getConnectorName())
+                    .isEqualTo(new ConnectorName("memory"));
+
+            // Wait for initial poll - should not trigger a refresh since nothing changed
+            Thread.sleep(150);
+            assertThat(manager.getRefreshCount()).isEqualTo(0);
+
</code_context>

<issue_to_address>
**nitpick (testing):** Tests rely on sleep for timing, which may lead to flakiness.

Using Thread.sleep and polling can cause unreliable tests, particularly in CI. Please use synchronization methods or event hooks to reliably detect refresh completion.
</issue_to_address>

### Comment 2
<location> `core/trino-main/src/test/java/io/trino/connector/TestFilePollingCatalogStore.java:127` </location>
<code_context>
+        throw new AssertionError("Expected refresh count " + expectedCount + " but got " + manager.getRefreshCount());
+    }
+
+    private static class FilePollingCatalogStore
+            implements CatalogStore, Closeable
+    {
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding a test for the case where setCatalogManager is called multiple times.

Testing repeated calls to setCatalogManager will help verify that polling is managed correctly and prevent resource leaks or unintended side effects.
</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.

Comment on lines +73 to +74
// Wait for initial poll - should not trigger a refresh since nothing changed
Thread.sleep(150);
Copy link

Choose a reason for hiding this comment

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

nitpick (testing): Tests rely on sleep for timing, which may lead to flakiness.

Using Thread.sleep and polling can cause unreliable tests, particularly in CI. Please use synchronization methods or event hooks to reliably detect refresh completion.

throw new AssertionError("Expected refresh count " + expectedCount + " but got " + manager.getRefreshCount());
}

private static class FilePollingCatalogStore
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Consider adding a test for the case where setCatalogManager is called multiple times.

Testing repeated calls to setCatalogManager will help verify that polling is managed correctly and prevent resource leaks or unintended side effects.

@raunaqmorarka raunaqmorarka requested review from dain and hashhar October 13, 2025 06:09
@NingGUO520
Copy link
Author

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

hi, i already signed the CLA, could you check the email please ?

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant