Skip to content
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

fix: use existing entries to update the round robin cache #739

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,26 @@ private void createCacheEntryForHosts(
final @NonNull List<HostSpec> hosts,
final @Nullable Properties props)
throws SQLException {
final List<HostSpec> hostsMissingCacheEntry = new ArrayList<>();
final List<HostSpec> hostsWithCacheEntry = new ArrayList<>();
for (final HostSpec host : hosts) {
if (roundRobinCache.get(host.getHost()) != null) {
hostsWithCacheEntry.add(host);
} else {
hostsMissingCacheEntry.add(host);
}
}

if ((hostsMissingCacheEntry.isEmpty() && !hostsWithCacheEntry.isEmpty())) {
// If there is a host with an existing entry, update the cache entries for all hosts to point each to the same
// RoundRobinClusterInfo object. If there are no cache entries, create a new RoundRobinClusterInfo.
if (!hostsWithCacheEntry.isEmpty()) {
for (final HostSpec host : hosts) {
roundRobinCache.put(
host.getHost(),
roundRobinCache.get(hostsWithCacheEntry.get(0).getHost()),
DEFAULT_ROUND_ROBIN_CACHE_EXPIRE_NANO);
}
} else if (hostsWithCacheEntry.isEmpty()) {
} else {
final RoundRobinClusterInfo roundRobinClusterInfo = new RoundRobinClusterInfo();
updateCachePropertiesForRoundRobinClusterInfo(roundRobinClusterInfo, props);
for (final HostSpec host : hostsMissingCacheEntry) {
for (final HostSpec host : hosts) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that mean that a new cache entry will be added for every host? including those that already had a cache entry?

let's add comments explaining each part of the conditions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, each host will have a cache entry. If the host already had an entry, it will just be updated.

roundRobinCache.put(
host.getHost(),
roundRobinClusterInfo,
Expand Down
Loading