-
Notifications
You must be signed in to change notification settings - Fork 72
Implement internal connection pools for the read-write plugin #359
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
Conversation
wrapper/src/main/java/software/amazon/jdbc/ConnectionProvider.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/ConnectionProviderManager.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/ConnectionProviderManager.java
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/HikariPoolConfigurator.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/HikariPooledConnectionProvider.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/HikariPooledConnectionProvider.java
Outdated
Show resolved
Hide resolved
| @Override | ||
| public Connection connect( | ||
| @NonNull String url, @NonNull Properties props) throws SQLException { | ||
| // TODO: Is this method ever called? It seems to only be referenced by tests/benchmarks. If |
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.
Agree, it don't recall it's ever used. Might consider to deprecate it.
wrapper/src/main/java/software/amazon/jdbc/HikariPooledConnectionProvider.java
Outdated
Show resolved
Hide resolved
| JdbcCallable<Connection, SQLException> connectFunc) throws SQLException { | ||
| final Connection conn = connectFunc.call(); | ||
|
|
||
| if (conn != null) { |
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.
That may need additional checks to avoid generating keys for connections that already have keys and come from connection pool. It's not part of POC certainly.
…ols (#27) - updated HikariPooledConnectionProvider to use jdbcUrl instead of dataSourceClassName - fixed issue in StaleDnsHelper where the URL was included in the comparison between cluster and instance DNS. Only the IP address should be compared - fixed some incorrect test code in ReadWriteSplittingTests - disabled flaky test in ReadWriteSplittingTests. The HostListProvider should be improved to verify the initial host spec role before re-enabling it
- added test for failover failure (no instances available) - added test for failover while in a transaction
|
|
||
| ### Internal connection pooling | ||
|
|
||
| Whenever `setReadOnly(true)` is first called on a `Connection` object, the read-write plugin will internally open a new physical connection to a reader. After this first call, the physical reader connection will be cached for the given `Connection`. Future calls to `setReadOnly `on the same `Connection` object will not require opening a new physical connection. However, calling `setReadOnly(true)` for the first time on a new `Connection` object will require the plugin to establish another new physical connection to a reader. If your application frequently establishes new read-only connections, you can enable internal connection pooling to improve performance. When enabled, the wrapper driver will maintain an internal connection pool for each instance in the cluster. This allows the read-write plugin to reuse reader connections that were established by previous `Connection` objects. |
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.
However, calling setReadOnly(true) for the first time on a new Connection object will require the plugin to establish another new physical connection to a reader.
Seems to just repeat the information above.
fix: hanging pooled connection test
Add functionality to use internal connection pools to establish connections. The motivation for using pools comes from the read-write plugin's need to regularly establish new connections. Using pools will increase performance and decrease demands on the database by allowing connections to be re-used.
Additional Reviewers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.