-
Notifications
You must be signed in to change notification settings - Fork 46
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
Implement the CustomEndpointPlugin #1122
Conversation
Qodana Community for JVMIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/[email protected]
with:
upload-result: true Contact Qodana teamContact us at [email protected]
|
a0d0e7f
to
0c267e2
Compare
…rvice.getAllowedHosts()
…over, changed synchronized block to lock
0c267e2
to
87dea47
Compare
wrapper/src/main/java/software/amazon/jdbc/util/SlidingExpirationCache.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/ConnectionPluginChainBuilder.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointMonitorImpl.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointMonitorImpl.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointMonitorImpl.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
// The custom endpoint info has changed, so we need to update the info in the registered plugin services. | ||
customEndpointInfoCache.put(this.endpointIdentifier, endpointInfo, this.cacheEntryExpirationNano); |
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.
Another thread might add such item in the cache. Would it be damaging? Can we use computeIfAbsent()?
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 don't think any other thread will be placing info at this key, the logic in CustomEndpointPlugin should only be creating one thread per custom endpoint which is shared among all connections, which means there is only one thread updating info for a given custom endpoint. computeIfAbsent would allow us to place an initial custom endpoint info object in the cache but it cannot be used to update the info later since it will already exist in the cache
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointMonitorImpl.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointPlugin.java
Outdated
Show resolved
Hide resolved
LOGGER.info(Messages.get("CustomEndpointMonitorImpl.interrupted", new Object[]{ this.customEndpointHostSpec })); | ||
Thread.currentThread().interrupt(); | ||
} catch (Exception e) { | ||
LOGGER.log(Level.SEVERE, |
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 unhandled exception effectively stops monitoring thread. I believe we need to report the issue and continue with the main monitoring loop.
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 to continue monitoring even if there is an unexpected problem? I adjusted the code to continue monitoring if an exception occurs (unless its an interrupted exception), but I'm not sure if it makes sense to continue or not.
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointMonitorImpl.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointPlugin.java
Outdated
Show resolved
Hide resolved
* @return true if the custom endpoint info is available, or false if we timed out while waiting for the info to | ||
* become available. | ||
*/ | ||
protected boolean waitForCustomEndpointInfo() { |
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 a user doesn't want to wait? Can we not wait and proceed with a custom endpoint and let DNS resolve it for us?
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 problem with not waiting is that, if the custom endpoint info isn't discovered yet, there will be no disallowed hosts. Which means that failover and the read write splitting plugin may connect to hosts outside of the custom endpoint. It seems like the user would not want this to happen if they are enabling this plugin. I believe the user will not have to wait long or often, on my machine it takes ~260ms for the API call to complete and the user will only need to wait when info isn't in the cache already (cache entries last 5 minutes but will be extended by active monitors).
wrapper/src/main/java/software/amazon/jdbc/plugin/customendpoint/CustomEndpointPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/plugin/staledns/AuroraStaleDnsHelper.java
Show resolved
Hide resolved
{ | ||
addAll(SubscribedMethodHelper.NETWORK_BOUND_METHODS); | ||
add("connect"); | ||
add("forceConnect"); |
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 don't think we need forceConnect(). It's usually used by various monitoring threads and failover.
protected void waitForCustomEndpointInfo(CustomEndpointMonitor monitor) throws SQLException { | ||
boolean hasCustomEndpointInfo = monitor.hasCustomEndpointInfo(); | ||
|
||
if (!hasCustomEndpointInfo) { |
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.
So we always wait if cache is empty? Is it so essential to wait for monitoring thread fetch custom endpoint definition? Can we make it configurable (wait/not wait)?
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 problem with not waiting is that, if the custom endpoint info isn't discovered yet, there will be no disallowed hosts. Which means that failover and the read write splitting plugin may connect to hosts outside of the custom endpoint. It seems like the user would not want this to happen if they are enabling this plugin. I believe the user will not have to wait long or often, on my machine it takes ~260ms for the API call to complete and the user will only need to wait when info isn't in the cache already (cache entries last 5 minutes but will be extended by active monitors). If you want I can make it configurable, but if the wait is disabled the custom endpoint plugin may allow connections to instances outside the endpoint.
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'd prefer to delegate this decision to a user so a new configuration parameter would be great. Also I see that after calling waitForCustomEndpointInfo()
the driver continues with connectFunc
to get a connection. That means that custom endpoint info isn't directly required at this point.
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.
It might be required, there are two problem scenarios I can think of:
- user has enableConnectFailover set to true, they try to connect but it fails and failover is kicked off, failover connects to a host outside of the custom endpoint info because we did not wait for the info to be found.
- user connects successfully and then executes setReadOnly or hits failover while executing some other method, in both cases we could connect to an instance outside of the custom endpoint if we did not wait for the info to be found
Summary
Implement the CustomEndpointPlugin
Description
Additional Reviewers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.