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
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.

@trinodb trinodb deleted a comment from sourcery-ai bot Jan 10, 2026
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