-
Notifications
You must be signed in to change notification settings - Fork 119
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
feat: Add lazy refresh strategy to the connector. Fixes #992. #1990
Conversation
core/src/main/java/com/google/cloud/sql/core/DefaultConnectionInfoCache.java
Outdated
Show resolved
Hide resolved
MIN_REFERSH_DELAY_MS); | ||
|
||
ConnectionMetadata gotMetadata = connectionInfoCache.getConnectionMetadata(TEST_TIMEOUT_MS); | ||
assertThat(gotMetadata.getKeyManagerFactory()) |
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 is the significance of this assertion? Would the counter check be enough for an assertion?
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.
Fixed. I added comments to explain.
AuthType authType, | ||
KeyPair keyPair) { | ||
try { | ||
Thread.sleep(100); |
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.
Why do we need to sleep 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.
The test needs to simulate a blocking call.
1abf29b
to
84967d7
Compare
84967d7
to
0c74936
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.
I've elaborated below, but the gist of this review is: we should be using a ConnectionInfoCache interface and then provide multiple implementations (refresh ahead, lazy, etc).
} catch (InterruptedException | ExecutionException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return new DefaultConnectionInfoCache( |
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.
Looking more closely at this, I see we're missing a ConnectionInfoCache interface in this repo (which exists in Go and in AlloyDB Java). Instead of having multiple constructors for one cache type, we should be introducing separate caches that both implement a ConnectionInfoCache interface. This makes for better separation of concerns. The refresher strategy might still be useful, but the most important thing it to think of connection info cache as being the interface for which we have multiple implementations.
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 ConnectionInfoCache interface is a blocking concern here.
0c74936
to
a42f60c
Compare
a42f60c
to
f8091ae
Compare
f8091ae
to
31e7eab
Compare
0ca91ff
to
6143994
Compare
31e7eab
to
155809a
Compare
🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use -- conventional-commit-lint bot |
6143994
to
84ef897
Compare
496b4f1
to
ccb7678
Compare
84ef897
to
86a443e
Compare
ccb7678
to
cd26691
Compare
86a443e
to
f7de7c0
Compare
cd26691
to
9518af3
Compare
10b3cf1
to
e5d7f08
Compare
Refactoring is complete. Please give this Lazy Refresh implementation another look. |
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.
One small test change and then LGTM.
ConnectionMetadata gotMetadata = connectionInfoCache.getConnectionMetadata(300); | ||
|
||
// Assert that the underlying ConnectionInfo was retrieved exactly once. | ||
assertThat(instanceDataSupplier.counter.get()).isEqualTo(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.
Let's call the method above twice to prove we're calling the underlying instance data supplier only once.
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.
Fixed.
e5d7f08
to
fa7848e
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.
You'll need to fix the conventional commit error. Otherwise LGTM.
The lazy refresh strategy only refreshes credentials and certificate information when the application attempts
to establish a new database connection. On Cloud Run and other serverless runtimes, this is more reliable
than the default background refresh strategy.
Fixes #992.