Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Optimize CassandraService#getAddressForHost #6648

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
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 @@ -287,17 +287,15 @@ private CassandraServer getAddressForHostThrowUnchecked(String host) {
CassandraServer getAddressForHost(String inputHost) throws UnknownHostException {
Map<String, String> hostnamesByIp = hostnameByIpSupplier.get();
String cassandraHostName = hostnamesByIp.getOrDefault(inputHost, inputHost);
return CassandraServer.of(cassandraHostName, getReachableProxies(cassandraHostName));
}

private ImmutableSet<InetSocketAddress> getReachableProxies(String inputHost) throws UnknownHostException {
InetAddress[] resolvedHosts = InetAddress.getAllByName(inputHost);
InetAddress[] resolvedHosts = InetAddress.getAllByName(cassandraHostName);
int knownPort = getKnownPort();

// It is okay to have reachable proxies that do not have a hostname
return Stream.of(resolvedHosts)
.map(inetAddr -> new InetSocketAddress(inetAddr, knownPort))
.collect(ImmutableSet.toImmutableSet());
ImmutableSet.Builder<InetSocketAddress> proxies = ImmutableSet.builderWithExpectedSize(resolvedHosts.length);
for (InetAddress host : resolvedHosts) {
proxies.add(new InetSocketAddress(host, knownPort));
}
return CassandraServer.of(cassandraHostName, proxies.build());
Comment on lines +294 to +298
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that this is eagerly building ImmutableSet<InetSocketAddress> as ImmutableCassandraServer constructor will this.reachableProxyIps = ImmutableSet.copyOf(reachableProxyIps); so just avoiding unnecessary additional intermediate collection.

}

private int getKnownPort() throws UnknownHostException {
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-6648.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Optimize CassandraService#getAddressForHost
links:
- https://github.com/palantir/atlasdb/pull/6648