-
Notifications
You must be signed in to change notification settings - Fork 120
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
refactor: Refactor RefreshAheadConnectionInfoCache. Part of #992. #1997
Conversation
* @param executor executor used to schedule asynchronous tasks | ||
* @param keyPair public/private key pair used to authenticate connections | ||
*/ | ||
public static RefreshAheadConnectionInfoCache newInstance( |
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 have to use a static factory method instead of a constructor because it has to instantiate an AccessTokenSupplier and RefreshAheadStrategy before it calls the constructor.,
e0fa4bb
to
e9708f6
Compare
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.
What if the ConnectinInfoCache just returned the connection info instead of creating SSL sockets? Recently, in Go and Python we've been pulling apart the thing that caches connection info (e.g., the "cache") from the thing that creates SSL sockets (e.g., the "connector"). That's what we're doing in AlloyDB and it's working well: https://github.com/GoogleCloudPlatform/alloydb-java-connector/blob/main/alloydb-jdbc-connector/src/main/java/com/google/cloud/alloydb/ConnectionInfoCache.java
I'll remove the |
e9708f6
to
3716afd
Compare
this.instanceName = new CloudSqlInstanceName(config.getCloudSqlInstance()); | ||
this.config = config; | ||
|
||
abstract class BaseConnectionInfoCache implements ConnectionInfoCache { |
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 base class is delegating all calls to the refresh strategy. What if we avoid introducing more indirection and just had the implementations of ConnectionInfoCache call through to their refresher?
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 removed the base class.
|
||
RefreshStrategy getRefresher(); | ||
|
||
CloudSqlInstanceName getInstanceName(); |
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 is used only in test. Let's remove the method here and either drop the usages in test or find a more direct way at getting at the information the test wants.
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 removed this method too.
|
||
void refreshIfExpired(); | ||
|
||
RefreshStrategy getRefresher(); |
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 is a test-only method. How can we avoid adding it here?
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've removed it from the interface.
long minRefreshDelayMs) { | ||
|
||
AccessTokenSupplier accessTokenSupplier = | ||
BaseConnectionInfoCache.newAccessTokenSupplier(config, tokenSourceFactory); |
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 static method is making our lives harder. Why don't we pass in the access token supplier from where we instantiate the cache?
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.
Refactored, removing the base class, so that this can be a normal constructor.
6143994
to
84ef897
Compare
@@ -51,4 +52,29 @@ Map<IpType, String> getIpAddrs() { | |||
SslData getSslData() { | |||
return sslData; | |||
} | |||
|
|||
ConnectionMetadata toConnectionMetadata( |
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.
Moved here because BaseConnectionInfoCache
was deleted.
(Additional context: ConnectionMetadata
is part of the legacy public Java API contract.)
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 seems like the perfect place for such concerns -- basically the connection info data class.
@@ -43,6 +44,14 @@ class DefaultAccessTokenSupplier implements AccessTokenSupplier { | |||
private final int retryCount; | |||
private final Duration retryDuration; | |||
|
|||
static AccessTokenSupplier newInstance(AuthType authType, CredentialFactory tokenSourceFactory) { |
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.
Moved here because BaseConnectionInfoCache was deleted.
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.
Perfect spot.
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's one use of public to probably remove. Otherwise LGTM.
@@ -51,4 +52,29 @@ Map<IpType, String> getIpAddrs() { | |||
SslData getSslData() { | |||
return sslData; | |||
} | |||
|
|||
ConnectionMetadata toConnectionMetadata( |
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 seems like the perfect place for such concerns -- basically the connection info data class.
package com.google.cloud.sql.core; | ||
|
||
/** ConnectionInfoCache is the contract for a caching strategy for ConnectionInfo. */ | ||
public interface ConnectionInfoCache { |
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.
Do we want this to be public?
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 removed public
.
@@ -43,6 +44,14 @@ class DefaultAccessTokenSupplier implements AccessTokenSupplier { | |||
private final int retryCount; | |||
private final Duration retryDuration; | |||
|
|||
static AccessTokenSupplier newInstance(AuthType authType, CredentialFactory tokenSourceFactory) { |
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.
Perfect spot.
84ef897
to
86a443e
Compare
86a443e
to
f7de7c0
Compare
This makes a number of refactoring changes to align the Java connector with other implementations.