-
Notifications
You must be signed in to change notification settings - Fork 97
Fix buildJdbcUrl to apply connection properties #651
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
base: main
Are you sure you want to change the base?
Conversation
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 |
@cla-bot check |
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 |
The cla-bot has been summoned, and re-checked this pull request! |
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
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.
I think this requires a pretty static format for the JDBC URL. Can you confirm that this works for MySQL, Oracle, and PostgreSQL as we suggest. At a minimum I think we should add some simple test to verify that the property you reported as failing now works in terms of passing it through. Overall I am ok with this approach though. Might be worth looking in the Trino codebase if we have any similar setup and tests for it.
@mosabua |
gateway-ha/src/main/java/io/trino/gateway/ha/persistence/JdbcConnectionManager.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/persistence/TestJdbcConnectionManager.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/persistence/TestJdbcConnectionManager.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/persistence/TestJdbcConnectionManager.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/persistence/TestJdbcConnectionManager.java
Show resolved
Hide resolved
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.
This looks good to me now. Can you squash commits @seoyoniee ?
Anything else to change @ebyhr ?
01de0f9
to
f38be06
Compare
|
||
final class TestJdbcConnectionManager | ||
{ | ||
private JdbcConnectionManager createConnectionManager(String jdbcUrl) |
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.
Please move this method to the bottom. We locate helper method after the caller in this project.
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.
@@ -60,11 +63,26 @@ public Jdbi getJdbi(@Nullable String routingGroupDatabase) | |||
.registerRowMapper(new RecordAndAnnotatedConstructorMapper()); | |||
} | |||
|
|||
private String buildJdbcUrl(@Nullable String routingGroupDatabase) | |||
public String buildJdbcUrl(@Nullable String routingGroupDatabase) |
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.
The package-private is sufficient, right? Please add @VisibleForTesting
annotation.
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.
yes right! 7d2d2ae
} | ||
catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} |
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.
Please return jdbcUrl
early when routingGroupDatabase
is null so we can avoid redundant nesting:
if (routingGroupDatabase == null) {
return jdbcUrl;
}
try {
...
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.
|
||
final class TestJdbcConnectionManager | ||
{ | ||
private JdbcConnectionManager createConnectionManager(String jdbcUrl) |
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.
This method can be static.
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.
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.
Can you add some failures in test cases? For incorrect jdbc urls?
@@ -60,13 +64,29 @@ public Jdbi getJdbi(@Nullable String routingGroupDatabase) | |||
.registerRowMapper(new RecordAndAnnotatedConstructorMapper()); | |||
} | |||
|
|||
private String buildJdbcUrl(@Nullable String routingGroupDatabase) | |||
@VisibleForTesting | |||
String buildJdbcUrl(@Nullable String routingGroupDatabase) | |||
{ | |||
String jdbcUrl = configuration.getJdbcUrl(); |
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.
maybe check?
if (jdbcUrl == null) {
throw new IllegalArgumentException("JDBC URL cannot be null");
}
catch (URISyntaxException e) { | ||
throw new RuntimeException(e); |
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 @ebyhr WDYT of catching more broder exception like RuntimeException or Exception
Because NPE could happen if jdbcUrl is none, or IndexOutOfBounds if / is not present, or IllegalArgumentException if Path.of(uri.getPath())
is malformed path.
catch (URISyntaxException e) { | |
throw new RuntimeException(e); | |
catch (Exception e) { // catch all | |
Logger.get(getClass()).error(e, "Failed to build JDBC URL for routing group '%s'", routingGroupDatabase); | |
throw new RuntimeException(e); | |
} |
return jdbcUrl; | ||
} | ||
try { | ||
int index = jdbcUrl.indexOf("/") + 1; |
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.
Maybe add check?
int index = jdbcUrl.indexOf("/") + 1; | |
int index = jdbcUrl.indexOf("/") + 1; | |
if (index < 0) { | |
throw new IllegalArgumentException("Invalid JDBC URL: no '/' found in " + jdbcUrl); | |
} |
Description
Fixing buildJdbcUrl to apply connection properties
Additional context and related issues
fixing #650
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: