-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix DevelopmentServer plugin.dir configuration #26898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis 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 lifecyclesequenceDiagram
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
Class diagram for updated DevelopmentServer and ClosingBinderclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
testing/trino-server-dev/src/main/java/io/trino/server/DevelopmentServer.java
Show resolved
Hide resolved
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ClosingBinder.java
Outdated
Show resolved
Hide resolved
edca999 to
4212ad2
Compare
|
red |
4212ad2 to
2a9505d
Compare
|
@losipiuk fixed |
testing/trino-server-dev/src/main/java/io/trino/server/DevelopmentServer.java
Show resolved
Hide resolved
2a9505d to
4221b65
Compare
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:
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: