Skip to content

Conversation

@sergiyvamz
Copy link
Contributor

Summary

Introduce target driver dialects

Additional Reviewers

@karenc-bq
@aaron-congo
@davecramer

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sergiyvamz sergiyvamz force-pushed the target-driver-dialects branch from de7b877 to bb64f60 Compare May 18, 2023 22:21
@sergiyvamz sergiyvamz changed the title [WIP] feat: introduce target driver dialects feat: introduce target driver dialects May 23, 2023
customProps.setProperty(urlPropertyName, finalUrl);
}

LOGGER.finest(() -> PropertyUtils.logProperties(customProps, "Connecting with properties: \n"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we log the properties and the url in one message? It helps the debugging process in multithreaded applications

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm they are different properties. Url may be missed. Let's find a separate solution for multithreaded logs.

final @Nullable String databasePropertyName) throws SQLException {

// The logic is isolated to a separated class since it uses
// direct reference to org.postgresql.ds.common.BaseDataSource
Copy link
Contributor

Choose a reason for hiding this comment

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

Referring to the code comments above, is the idea to decouple the Dialect class from org.postgresql.ds.common.BaseDataSource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct. The idea is to decouple different dialect classes. Since PgTargetDriverDialect is instantiated in TargetDriverDialectManager, it's impossible to use any classes from org.postgresql package in PgTargetDriverDialect. In this case AWS JDBC Driver would have a dependency on org.postgresql package. That's why all logic is isolated in PgDataSourceHelper class. This helper class has direct references to org.postgresql package but it's instantiated when it's needed only, i.e. when the target driver is actually pgjdbc driver.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the explanation!

@sergiyvamz sergiyvamz force-pushed the target-driver-dialects branch from 7f06bff to 8039457 Compare May 24, 2023 23:26
documentation
jacoco min coverage
code style
fix issue with MariaDb driver for Mysql protocol
add checkstyle import exceptions
introduce target driver dialects
@sergiyvamz sergiyvamz force-pushed the target-driver-dialects branch from 8039457 to 38abe6f Compare May 24, 2023 23:29
* Dialect objects are shared between different connections.
* The order of entries in this map is the order in which dialects are called/verified.
*/
protected static final Map<String, TargetDriverDialect> knownDialectsByCode =
Copy link
Contributor

@aaronchung-bitquill aaronchung-bitquill May 25, 2023

Choose a reason for hiding this comment

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

Nit: would it be better to have this mapping located in the TargetDriverDialectCodes class? That way if a new dialect is introduced, it is one less class that needs to be updated, and it is harder for the developer to forget updating this mapping.

Also sorry about the lateness of the comment.

*/
@Deprecated
Connection connect(@NonNull String url, @NonNull Properties props)
throws SQLException; // TODO: this method is only called by tests/benchmarks and can likely be deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we remove the comment now that this is deprecated or no?

Throwable exception = throwable;

while (exception != null) {
if (exception instanceof SQLLoginException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we move this check to isLoginException?

protected PluginService pluginService;

static {
PropertyDefinition.registerPluginProperties(AwsSecretsManagerConnectionPlugin.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it work to register the properties for all available plugins automatically in the ConnectionPluginManager so that we don't need to add this block to every plugin? Might not be necessary but it would be nice to avoid the need to add this to every plugin if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Registering properties is direct responsibility of a particular plugin. Register properties for all know plugins in ConnectionPluginManager doesn't look like direct responsibilities of the this class. Also, such approach doesn't cover user custom plugins. I'd prefer to let plugins be responsible for such registration.

}

if (hostSpec.isPortSpecified() && !isNullOrEmpty(portPropertyName)) {
customProps.put(portPropertyName, hostSpec.getPort());
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be setProperty instead of put?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically it's the same call to put(). I'll fix it for consistency.

public class TargetDriverDialectCodes {
public static final String PG_JDBC = "pgjdbc";
public static final String MYSQL_CONNECTOR_J = "mysql-connector-j";
public static final String MARIADB_CONNECTOR_J_VER_3 = "mariadb-connector-j-3"; // ver 3.0.3+
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious, why do we need the version in this string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a chance that different versions of the same driver may require different dialects. MariaDb driver changed behaviour in version 3+. So I think it makes sense to be explicit in defining dialect codes.

@sergiyvamz sergiyvamz merged commit 811a454 into main May 26, 2023
@sergiyvamz sergiyvamz deleted the target-driver-dialects branch May 26, 2023 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants