aws / aws-advanced-jdbc-wrapper

The Amazon Web Services JDBC Driver has been redesigned as an advanced JDBC wrapper. This wrapper is complementary to and extends the functionality of an existing JDBC driver to help an application take advantage of the features of clustered databases such as Amazon Aurora.
Apache License 2.0
225 stars 47 forks source link

`.setCatalog` causes invalid `USE` statement when connection is released #1042

Closed rgueldem closed 4 months ago

rgueldem commented 5 months ago

Describe the bug

When using a connection string without specifying a database and explicitly calling setCatalog on the connection, releasing the connection triggers an empty USE statement.

Expected Behavior

Releasing the connection should not trigger any invalid SQL.

What plugins are used? What other connection properties were set?

default settings only

Current Behavior

~ ❯❯❯ scala-cli ./aws-mysql-issue.sc
Compiling project (Scala 3.4.1, JVM (21))
Compiled project (Scala 3.4.1, JVM (21))
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.targetdriverdialect.TargetDriverDialectManager logDialect
FINEST: Target driver dialect set to: 'mysql-connector-j', software.amazon.jdbc.targetdriverdialect.MysqlConnectorJTargetDriverDialect@6be46e8f.
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.dialect.DialectManager logCurrentDialect
FINEST: Current dialect: mysql, software.amazon.jdbc.dialect.MysqlDialect, canUpdate: true
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.ConnectionPluginChainBuilder getPlugins
FINEST: Plugins order has been rearranged. The following order is in effect: AuroraConnectionTrackerPluginFactory, FailoverConnectionPluginFactory, HostMonitoringConnectionPluginFactory
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.plugin.failover.FailoverConnectionPlugin initHostProvider
FINER: failoverMode=STRICT_WRITER
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.plugin.failover.FailoverConnectionPlugin notifyNodeListChanged
FINEST: Changes:
        Host '127.0.0.1:3306/': [NODE_ADDED]
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.PluginServiceImpl getCurrentHostSpec
FINEST: Set current host to HostSpec[host=127.0.0.1, port=3306, WRITER, AVAILABLE, weight=100, null]
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.DriverConnectionProvider connect
FINEST: Connecting with properties:
[password] ...
[wrapperLoggerLevel] FINEST
[user] root
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.DriverConnectionProvider connect
FINEST: Connecting to jdbc:mysql://127.0.0.1:3306/
with properties:
[password] ***
[user] root
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.dialect.DialectManager logCurrentDialect
FINEST: Current dialect: mysql, software.amazon.jdbc.dialect.MysqlDialect, canUpdate: false
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.plugin.OpenedConnectionTracker populateOpenedConnectionQueue
FINEST: [Internal Error] The driver is unable to track this opened connection because the instance endpoint is unknown.
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.plugin.DefaultConnectionPlugin execute
FINEST: Executing method: 'Connection.setCatalog'
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.states.SessionStateServiceImpl logCurrentState
FINEST: Current session state:
autoCommit: (blank) -> (blank)
readOnly: (blank) -> (blank)
catalog:  -> (blank)
schema: (blank) -> (blank)
holdability: (blank) -> (blank)
networkTimeout: (blank) -> (blank)
transactionIsolation: (blank) -> (blank)
typeMap: (blank) -> (blank)

Jun 25, 2024 3:31:58 PM software.amazon.jdbc.states.SessionStateServiceImpl logCurrentState
FINEST: Current session state:
autoCommit: (blank) -> (blank)
readOnly: (blank) -> (blank)
catalog:  -> performance_schema
schema: (blank) -> (blank)
holdability: (blank) -> (blank)
networkTimeout: (blank) -> (blank)
transactionIsolation: (blank) -> (blank)
typeMap: (blank) -> (blank)

Jun 25, 2024 3:31:58 PM software.amazon.jdbc.plugin.DefaultConnectionPlugin execute
FINEST: Executing method: 'Connection.close'
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.states.SessionStateServiceImpl logCurrentState
FINEST: Current session state:
autoCommit: (blank) -> (blank)
readOnly: (blank) -> (blank)
catalog:  -> performance_schema
schema: (blank) -> (blank)
holdability: (blank) -> (blank)
networkTimeout: (blank) -> (blank)
transactionIsolation: (blank) -> (blank)
typeMap: (blank) -> (blank)

Jun 25, 2024 3:31:58 PM software.amazon.jdbc.ConnectionPluginManager releaseResources
FINE: Releasing resources.
Jun 25, 2024 3:31:58 PM software.amazon.jdbc.PluginServiceImpl releaseResources
FINE: Releasing resources.
~ ❯❯❯ mysql -h 127.0.0.1 -u root -p                                                                                     
MySQL [(none)]> select * from mysql.general_log;

| 2024-06-25 13:31:58.847114 | [root] @  [192.168.65.1]     |       412 |         1 | Connect      | root@192.168.65.1 on  using SSL/TLS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| 2024-06-25 13:31:58.852026 | root[root] @  [192.168.65.1] |       412 |         1 | Query        | /* mysql-connector-j-8.4.0 (Revision: 1c3f5c149e0bfe31c7fbeb24e2d260cd890972c4) */SELECT  @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@collation_server AS collation_server, @@collation_connection AS collation_connection, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout, @@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet, @@net_write_timeout AS net_write_timeout, @@performance_schema AS performance_schema, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone, @@transaction_isolation AS transaction_isolation, @@wait_timeout AS wait_timeout |
| 2024-06-25 13:31:58.857303 | root[root] @  [192.168.65.1] |       412 |         1 | Query        | SET character_set_results = NULL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| 2024-06-25 13:31:58.859645 | root[root] @  [192.168.65.1] |       412 |         1 | Query        | SET autocommit=1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| 2024-06-25 13:31:58.870655 | root[root] @  [192.168.65.1] |       412 |         1 | Query        | SELECT 1 AS tmp FROM information_schema.tables WHERE table_schema = 'mysql' AND table_name = 'rds_topology'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| 2024-06-25 13:31:58.887742 | root[root] @  [192.168.65.1] |       412 |         1 | Query        | SHOW VARIABLES LIKE 'aurora_version'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| 2024-06-25 13:31:58.890124 | root[root] @  [192.168.65.1] |       412 |         1 | Query        | SHOW VARIABLES LIKE 'version_comment'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| 2024-06-25 13:31:58.898368 | root[root] @  [192.168.65.1] |       412 |         1 | Query        | USE `performance_schema`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| 2024-06-25 13:31:58.900897 | root[root] @  [192.168.65.1] |       412 |         1 | Query        | USE ``                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| 2024-06-25 13:31:58.921227 | root[root] @  [192.168.65.1] |       412 |         1 | Quit         |                                                                                                                                                         

Reproduction Steps

//> using dep "com.mysql:mysql-connector-j:8.4.0"
//> using dep "software.amazon.jdbc:aws-advanced-jdbc-wrapper:2.3.7"

import java.sql.DriverManager
import java.util.Properties

val properties = new Properties()
properties.setProperty("user", "root")
properties.setProperty("password", "...")
properties.setProperty("wrapperLoggerLevel", "FINEST")
val connection = DriverManager.getConnection("jdbc:aws-wrapper:mysql://127.0.0.1:3306", properties)
connection.setCatalog("performance_schema")
connection.close()

Possible Solution

No response

Additional Information/Context

No response

The AWS Advanced JDBC Driver version used

2.3.7

JDK version used

openjdk version "21.0.2" 2024-01-16 LTS

Operating System and version

NixOS 24.05

sergiyvamz commented 5 months ago

Hi @rgueldem

We have just merged in a PR with a fix. Could you kindly checkout our snapshot build and let us know if the issue still persists?

Thank you!

rgueldem commented 5 months ago

Thanks @sergiyvamz, I'd be happy to test the snapshot build but the latest one I can see in the repo is from June 11. Could you provide a new build?

sergiyvamz commented 5 months ago

Hi @rgueldem Sorry for a delay with a snapshot build. A new build is available now (Jul 4th)

rgueldem commented 4 months ago

Thank you, I tested the snapshot build and it works as expected. Feel free to close the issue.

hsuamz commented 4 months ago

Thanks for confirming @rgueldem . We will be issuing a new release by the end of July. We will close this issue once the release has been made.

Thanks again!