Skip to content

Conversation

@Akanksha-kedia
Copy link
Contributor

@Akanksha-kedia Akanksha-kedia commented Oct 7, 2025

Description

. ClusterStatsJdbcMonitor.java - Complete Immutable Configuration Refactor

Problem: Mutable Properties field causing potential thread safety issues Solution: Created comprehensive immutable configuration system

New Files Created:

  • JdbcMonitorConfiguration.java - Immutable JDBC configuration class with factory methods

Key Changes:

  • ✅ Replaced private final Properties properties with private final JdbcMonitorConfiguration jdbcConfig
  • ✅ Added factory method JdbcMonitorConfiguration.from() for easy construction
  • ✅ Added toProperties() method for backward compatibility with JDBC drivers
  • ✅ Improved error handling with fail-fast validation
  • ✅ Enhanced SSL configuration based on URL protocol
  • ✅ Better resource management and exception handling

2. GatewayWebAppResource.java - Immutable UI Configuration

Problem: Mutable UIConfiguration field in web resource Solution: Created immutable wrapper with defensive copying

New Files Created:

  • ImmutableUIConfiguration.java - Thread-safe UI configuration wrapper

Key Changes:

  • ✅ Replaced private final UIConfiguration uiConfiguration with private final ImmutableUIConfiguration immutableUiConfiguration
  • ✅ Added ImmutableUIConfiguration.copyOf() factory method
  • ✅ Defensive copying in constructor to prevent external modification
  • ✅ Maintained API compatibility while ensuring thread safety
  • ✅ Used Guava's ImmutableList for collections

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required, with the following suggested text:

* Fix some things.

Summary by Sourcery

Eliminate mutable field anti-patterns by introducing immutable configuration handling in the JDBC monitor and web app resource to improve thread safety.

Enhancements:

  • Replace mutable Properties field in ClusterStatsJdbcMonitor with a Guava ImmutableMap and construct a Properties copy at connection time
  • Replace mutable UIConfiguration field in GatewayWebAppResource with an ImmutableUIConfiguration wrapper and perform defensive copying in the constructor
  • Leverage Guava’s immutable collections to ensure thread-safe configuration usage

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

sourcery-ai bot commented Oct 7, 2025

Reviewer's Guide

Replaces mutable configuration fields with immutable constructs by introducing JdbcMonitorConfiguration and ImmutableUIConfiguration, leveraging factory methods, defensive copying, and Guava immutable collections to improve thread safety, backward compatibility, and error handling.

Class diagram for immutable UI configuration (GatewayWebAppResource)

classDiagram
    class GatewayWebAppResource {
        - ImmutableUIConfiguration immutableUiConfiguration
        + GatewayWebAppResource(...)
        + getUIConfiguration() : Response
    }
    class ImmutableUIConfiguration {
        + copyOf(UIConfiguration) : ImmutableUIConfiguration
        + getSomeProperty() : ...
        + ...
    }
    class UIConfiguration {
        + getSomeProperty() : ...
        + ...
    }
    GatewayWebAppResource --> ImmutableUIConfiguration : uses
    ImmutableUIConfiguration --> UIConfiguration : "copyOf()"
    ImmutableUIConfiguration --> "ImmutableList<...>" : uses
    GatewayWebAppResource ..> Response : returns
Loading

File-Level Changes

Change Details Files
Immutable JDBC configuration system
  • Added JdbcMonitorConfiguration class with from()/toProperties() factory methods and validation
  • Refactored ClusterStatsJdbcMonitor to use JdbcMonitorConfiguration instead of Properties
  • Converted immutable config back to Properties at connection time for driver compatibility
  • Enhanced SSL detection based on URL protocol and fail-fast validation
JdbcMonitorConfiguration.java
ClusterStatsJdbcMonitor.java
Immutable UI configuration wrapper
  • Created ImmutableUIConfiguration with defensive copying and Guava ImmutableList support
  • Replaced UIConfiguration field in GatewayWebAppResource with ImmutableUIConfiguration
  • Used ImmutableUIConfiguration.copyOf() in constructor to prevent external mutation
  • Updated getUIConfiguration endpoint to return immutable configuration
ImmutableUIConfiguration.java
GatewayWebAppResource.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 and they look great!

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

## Individual Comments

### Comment 1
<location> `gateway-ha/src/main/java/io/trino/gateway/ha/clustermonitor/ClusterStatsJdbcMonitor.java:81-85` </location>
<code_context>
+            connectionProperties.putAll(properties);
             // automatically set ssl config based on url protocol
-            properties.setProperty("SSL", String.valueOf(parsedUrl.getProtocol().equals("https")));
+            connectionProperties.setProperty("SSL", String.valueOf(parsedUrl.getProtocol().equals("https")));
         }
         catch (MalformedURLException e) {
</code_context>

<issue_to_address>
**suggestion:** Overwriting SSL property may cause confusion if initial value differs.

Since the SSL property is set both from the initial properties and then overwritten based on the URL protocol, clarify which value should take precedence, or remove the initial assignment if it is always replaced.

```suggestion
            // Create connection properties from immutable map
            connectionProperties = new Properties();
            // Remove any existing SSL property to avoid confusion
            Properties filteredProperties = new Properties();
            for (String key : properties.stringPropertyNames()) {
                if (!key.equalsIgnoreCase("SSL")) {
                    filteredProperties.setProperty(key, properties.getProperty(key));
                }
            }
            connectionProperties.putAll(filteredProperties);
            // Set SSL config based on url protocol, always taking precedence
            connectionProperties.setProperty("SSL", String.valueOf(parsedUrl.getProtocol().equals("https")));
```
</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.

@Akanksha-kedia Akanksha-kedia force-pushed the feature/new_pp branch 3 times, most recently from 463f239 to faf5d4b Compare October 7, 2025 10:07
@Akanksha-kedia
Copy link
Contributor Author

@ebyhr @mosabua @oneonestar please review.

Copy link
Member

@oneonestar oneonestar left a comment

Choose a reason for hiding this comment

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

We should also remove BackendStateConfiguration.ssl since it's value is always being replaced by the url protocol.

@Akanksha-kedia
Copy link
Contributor Author

@oneonestar please review

Comment on lines +81 to +86
// Remove any existing SSL property to avoid confusion
for (String key : properties.keySet()) {
if (!key.equalsIgnoreCase("SSL")) {
connectionProperties.setProperty(key, properties.get(key));
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Since properties will not have "SSL" anymore, we don't need this logic.

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