-
Notifications
You must be signed in to change notification settings - Fork 155
Improve disposal of broken connections #387
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
Round-robin load balancing was previously coupled with the address set implementation and made it hard to use different load balancing algorithm. This commit turns RoundRobinAddressSet into a simple concurrent set of addresses and moves load balancing logic into a separate component that takes list of available addresses and returns one that should be used next. This allows easier implementation of new load balancing algorithms. Rediscovery procedure will now not use load balancing and query routers in a known order (which is randomized by the database).
This replaces the existing round-robin. It gives us better performance with clusters composed of different machine capacities. Lease connected load balancing strategy selects start index in round-robin fashion to avoid always selecting same machine when cluster does not have any running transactions or all machines have same number of active connections.
And removed unused test events based infrastructure.
Connection pool can discard broken connections during acquisition (when connection liveness check timeout is configured) and when connections are returned to the pool. In both cases connections should be disposed and removed from the set of active connections. This is especially important with least connected load balancing strategy which examines amount of active connections for each address. This commit makes sure broken connections are disposed through the connections queue to make sure active set is always updated.
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.
Looks good.
createLoadBalancingStrategy( config, connectionPool ) ); | ||
} | ||
|
||
private LoadBalancingStrategy createLoadBalancingStrategy( Config config, ConnectionPool connectionPool ) |
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.
Method can be static
* @param message the warning message | ||
* @param cause the cause of the warning | ||
*/ | ||
void warn( String message, Throwable cause ); |
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 API change that will probably break user's code. Just saying...
Connection pool can discard broken connections during acquisition (when connection liveness check timeout is configured) and when connections are returned to the pool. In both cases connections should be disposed and removed from the set of active connections. This is especially important with least connected load balancing strategy which examines amount of active connections for each address.
This PR makes sure broken connections are disposed through the connections queue to make sure active set is always updated.
Based on #386, only last commit is new.