-
Notifications
You must be signed in to change notification settings - Fork 47
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: round robin host selection strategy #603
Conversation
6f74c08
to
046fa2b
Compare
wrapper/src/main/java/software/amazon/jdbc/DataSourceConnectionProvider.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/DataSourceConnectionProvider.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/DriverConnectionProvider.java
Outdated
Show resolved
Hide resolved
"ConnectionProvider.unsupportedHostSpecSelectorStrategy", | ||
new Object[] {strategy, HikariPooledConnectionProvider.class})); | ||
switch (strategy) { | ||
case "leastConnections": |
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.
strings
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
wrapper/src/main/java/software/amazon/jdbc/LeastConnectionsHostSelector.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/DataSourceConnectionProvider.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/DriverConnectionProvider.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/LeastConnectionsHostSelector.java
Show resolved
Hide resolved
3847b5c
to
a241109
Compare
wrapper/src/main/java/software/amazon/jdbc/DataSourceConnectionProvider.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.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/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
6d9cb35
to
bffdcce
Compare
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/RoundRobinHostSelector.java
Outdated
Show resolved
Hide resolved
5f91613
to
614592f
Compare
wrapper/src/main/java/software/amazon/jdbc/ConnectionPlugin.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/ConnectionProvider.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
wrapper/src/main/java/software/amazon/jdbc/HikariPooledConnectionProvider.java
Outdated
Show resolved
Hide resolved
5acfb32
to
9911abb
Compare
@@ -98,6 +103,8 @@ public HikariPooledConnectionProvider( | |||
HikariPoolConfigurator hikariPoolConfigurator, HikariPoolMapping mapping) { | |||
this.poolConfigurator = hikariPoolConfigurator; | |||
this.poolMapping = mapping; | |||
final LeastConnectionsHostSelector hostSelector = new LeastConnectionsHostSelector(databasePools); | |||
acceptedStrategies.put(LeastConnectionsHostSelector.STRATEGY_LEAST_CONNECTIONS, hostSelector); |
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 can't add this strategy to a static map. The strategy belongs to a particular instance of this connection provider and uses it resources (databasePools). If you add it to a static collection, other connection providers may use it and it's bad.
@@ -145,44 +154,21 @@ public boolean acceptsUrl( | |||
|
|||
@Override | |||
public boolean acceptsStrategy(@NonNull HostRole role, @NonNull String strategy) { | |||
return LEAST_CONNECTIONS_STRATEGY.equals(strategy); | |||
return acceptedStrategies.containsKey(strategy); |
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.
return acceptedStrategies.containsKey(strategy) || LEAST_CONNECTIONS_STRATEGY.equals(strategy);
throws SQLException { | ||
if (!LEAST_CONNECTIONS_STRATEGY.equals(strategy)) { | ||
if (!acceptedStrategies.containsKey(strategy)) { |
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.
Similar to previous comment.
* @return a host matching the requested role | ||
* @throws SQLException if the host list does not contain any hosts matching the requested role or | ||
* an error occurs while selecting a host | ||
*/ | ||
HostSpec getHost(List<HostSpec> hosts, HostRole role) throws SQLException; | ||
HostSpec getHost(List<HostSpec> hosts, HostRole role, Properties props) throws SQLException; |
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.
Should we annotate props with @nullable? It seems that some implementation may not need properties.
return eligibleHosts.get(targetHostIndex); | ||
} | ||
|
||
private synchronized void createCacheEntryForHosts( |
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 method is private and is used in getHost() that is public and synchronized. You can safely remove "synchronized" here.
} | ||
} | ||
|
||
private synchronized void updateCachePropertiesForRoundRobinClusterInfo( |
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.
Similar note about synchronized
9e2c3b4
to
f403c72
Compare
f403c72
to
68e4f03
Compare
Summary
Round robin host selection strategy
Description
Additional Reviewers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.