Skip to content

Conversation

@wendigo
Copy link
Contributor

@wendigo wendigo commented Oct 9, 2025

Description

Additional context and related issues

Release notes

(x) 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.
( ) Release notes are required, with the following suggested text:

## Section
* Fix some things. ({issue}`issuenumber`)

Summary by Sourcery

Generate a temporary plugins directory in DevelopmentServer, inject it into ServerPluginsProviderConfig, and ensure it is cleaned up on shutdown; extend ClosingBinder to register arbitrary Closeable instances

Enhancements:

  • Create temporary plugin directory in DevelopmentServer and bind it as the default installedPluginsDirs
  • Register cleanup of the temporary directory via ClosingBinder
  • Wrap plugin directory creation in try/catch and rethrow IOException as UncheckedIOException
  • Add registerCloseable method to ClosingBinder to support registering arbitrary Closeable instances for cleanup

@cla-bot cla-bot bot added the cla-signed label Oct 9, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 9, 2025

Reviewer's Guide

This PR enhances the DevelopmentServer to create a temporary plugins directory at startup—injecting it via ServerPluginsProviderConfig defaults—and automatically cleans it up on shutdown, while also extending ClosingBinder with a new registerCloseable helper.

Sequence diagram for DevelopmentServer plugin directory lifecycle

sequenceDiagram
    participant DevelopmentServer
    participant Files
    participant ClosingBinder
    participant ServerPluginsProviderConfig

    DevelopmentServer->>Files: createTempDirectory("plugins")
    DevelopmentServer->>ServerPluginsProviderConfig: setInstalledPluginsDirs([pluginPath])
    DevelopmentServer->>ClosingBinder: registerCloseable(() -> Files.deleteIfExists(pluginPath))
    Note over ClosingBinder: On shutdown, pluginPath is deleted
Loading

Class diagram for updated DevelopmentServer and ClosingBinder

classDiagram
    class DevelopmentServer {
        +getAdditionalModules() : Iterable<Module>
        -Creates temporary plugin directory
        -Binds ServerPluginsProviderConfig default with plugin dir
        -Registers directory for cleanup via ClosingBinder
    }
    class ClosingBinder {
        +registerResource(Key<T>, Consumer<? super T>)
        +registerCloseable(Closeable instance)
    }
    DevelopmentServer --> ClosingBinder : uses
Loading

File-Level Changes

Change Details Files
Implement temporary plugin directory creation and cleanup in DevelopmentServer
  • Wrap getAdditionalModules in a try/catch to handle IO
  • Create a temp directory using Files.createTempDirectory
  • Bind default installedPluginsDirs to the new temp directory
  • Register a closeable task to delete the directory on shutdown
  • Convert IOException into UncheckedIOException
testing/trino-server-dev/src/main/java/io/trino/server/DevelopmentServer.java
Add registerCloseable method to ClosingBinder for direct resource registration
  • Introduce registerCloseable(Closeable) to add instances to the closeables binder
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ClosingBinder.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

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 - here's some feedback:

  • Use a recursive delete when cleaning up the temp plugin directory instead of Files.deleteIfExists, since deleteIfExists will fail on non‐empty directories and could leave files behind.
  • Extract the temp directory creation and its binding into a separate helper or factory method to keep getAdditionalModules concise and easier to test.
  • Consider having ClosingBinder.registerCloseable accept AutoCloseable (or rename it) so you can register any AutoCloseable uniformly instead of only Closeable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Use a recursive delete when cleaning up the temp plugin directory instead of Files.deleteIfExists, since deleteIfExists will fail on non‐empty directories and could leave files behind.
- Extract the temp directory creation and its binding into a separate helper or factory method to keep getAdditionalModules concise and easier to test.
- Consider having ClosingBinder.registerCloseable accept AutoCloseable (or rename it) so you can register any AutoCloseable uniformly instead of only Closeable.

## Individual Comments

### Comment 1
<location> `testing/trino-server-dev/src/main/java/io/trino/server/DevelopmentServer.java:35-55` </location>
<code_context>
-                    .to(DevelopmentPluginsProvider.class).in(Scopes.SINGLETON);
-            configBinder(binder).bindConfig(DevelopmentLoaderConfig.class);
-        });
+        try {
+            Path pluginPath = Files.createTempDirectory("plugins");
+
+            return ImmutableList.of(binder -> {
+                newOptionalBinder(binder, PluginsProvider.class).setBinding()
+                        .to(DevelopmentPluginsProvider.class).in(Scopes.SINGLETON);
+                configBinder(binder).bindConfig(DevelopmentLoaderConfig.class);
+
+                configBinder(binder).bindConfigDefaults(ServerPluginsProviderConfig.class, config ->
+                        config.setInstalledPluginsDirs(ImmutableList.of(pluginPath.toFile())));
+
+                closingBinder(binder).registerCloseable(() -> Files.deleteIfExists(pluginPath));
+            });
+        }
+        catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Consider cleaning up pluginPath if initialization fails after creation.

If an exception occurs after creating pluginPath but before it is registered for cleanup, the directory may not be deleted. Consider deleting pluginPath in the catch block or using a try-with-resources approach.

```suggestion
    @Override
    protected Iterable<? extends Module> getAdditionalModules()
    {
        Path pluginPath = null;
        try {
            pluginPath = Files.createTempDirectory("plugins");

            return ImmutableList.of(binder -> {
                newOptionalBinder(binder, PluginsProvider.class).setBinding()
                        .to(DevelopmentPluginsProvider.class).in(Scopes.SINGLETON);
                configBinder(binder).bindConfig(DevelopmentLoaderConfig.class);

                configBinder(binder).bindConfigDefaults(ServerPluginsProviderConfig.class, config ->
                        config.setInstalledPluginsDirs(ImmutableList.of(pluginPath.toFile())));

                closingBinder(binder).registerCloseable(() -> Files.deleteIfExists(pluginPath));
            });
        }
        catch (IOException e) {
            if (pluginPath != null) {
                try {
                    Files.deleteIfExists(pluginPath);
                }
                catch (IOException cleanupException) {
                    // Optionally log cleanup failure, but do not mask the original exception
                }
            }
            throw new UncheckedIOException(e);
        }
    }
```
</issue_to_address>

### Comment 2
<location> `lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ClosingBinder.java:89-92` </location>
<code_context>
         closeables.addBinding().toProvider(new ResourceCloser<T>(key, close));
     }

+    public <T> void registerCloseable(Closeable instance)
+    {
+        closeables.addBinding().toInstance(instance);
</code_context>

<issue_to_address>
**suggestion:** Consider accepting AutoCloseable instead of Closeable for broader compatibility.

This change would enable support for a wider range of resource types, increasing API flexibility.

```suggestion
    public <T> void registerCloseable(AutoCloseable instance)
    {
        closeables.addBinding().toInstance(instance);
    }
```
</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.

@wendigo wendigo force-pushed the serafin/fix-development-server branch 2 times, most recently from edca999 to 4212ad2 Compare October 9, 2025 13:58
@wendigo wendigo requested review from ebyhr and losipiuk October 9, 2025 14:01
@losipiuk
Copy link
Member

losipiuk commented Oct 9, 2025

red

@wendigo wendigo force-pushed the serafin/fix-development-server branch from 4212ad2 to 2a9505d Compare October 9, 2025 14:22
@wendigo
Copy link
Contributor Author

wendigo commented Oct 9, 2025

@losipiuk fixed

@wendigo wendigo force-pushed the serafin/fix-development-server branch from 2a9505d to 4221b65 Compare October 9, 2025 14:27
@wendigo wendigo merged commit 7950d8e into trinodb:master Oct 9, 2025
96 of 98 checks passed
@github-actions github-actions bot added this to the 478 milestone Oct 9, 2025
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.

2 participants