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

Cache InetSocketAddress if hostname is IPAddress #1789

Merged
merged 3 commits into from
Nov 8, 2018

Conversation

reddycharan
Copy link
Contributor

Descriptions of the changes in this PR:

  • in BookieSocketAddress if IPAddress is hostname then it is okay
    to cache InetSocketAddress, since the canonicalhostname of the node
    dont change.

- in BookieSocketAddress if IPAddress is hostname then it is okay
to cache InetSocketAddress, since the canonicalhostname of the node
dont change.
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Good.

What about adding some test case?
I am interested in having tests with ipv6 addresses for instance

@merlimat
Copy link
Contributor

merlimat commented Nov 6, 2018

@reddycharan One other option could be to use InetSocketAddress.createUnresolved(), though I haven't tested if the cached gets updated when the name is finally resolved. If it doesn't, it might be a good solution too.

@reddycharan
Copy link
Contributor Author

@merlimat we cannt use InetSocketAddress.createUnresolved() here, because InetSocketAddress.getAddress would return null if it is unresolved https://docs.oracle.com/javase/7/docs/api/java/net/InetSocketAddress.html#getAddress()

in many places in our code we would use address of InetSocketAddress -

if (addr.getSocketAddress().getAddress().isLoopbackAddress()

https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/tools/cli/helpers/CommandHelpers.java#L44

@@ -38,11 +39,19 @@
// Member fields that make up this class.
private final String hostname;
private final int port;
private final boolean isHostnameIPAddress;
private final InetSocketAddress socketAddress;
Copy link
Contributor

@dlg99 dlg99 Nov 6, 2018

Choose a reason for hiding this comment

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

I'd do Optional<InetSocketAddress>
assign Optional.empty() if it should not be cached
and use
socketAddress.orElseGet(() -> new InetSocketAddress(hostname, port)) to get address as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed it

@reddycharan
Copy link
Contributor Author

@eolivelli regarding testing I'm in the same boat as Matteo here, 3d8bad4

for ipv4/ipv6 i can confirm that InetAddresses.isInetAddress handles both ipv4/ipv6 - https://github.com/google/guava/blob/master/guava/src/com/google/common/net/InetAddresses.java#L186

@reddycharan
Copy link
Contributor Author

@eolivelli actually i just noticed that our current code wouldn't work with IPV6 address format, https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/net/BookieSocketAddress.java#L50 here (and other places) we are assuming that COLON is the separator between bookie hostname/ipaddress and port in the bookieid.

but in the ipv6 format ':' is used instead of '.' in its ipv6 address string representation - for eg - 2001:db8:85a3:0:0:8a2e:370:7334

@sijie
Copy link
Member

sijie commented Nov 7, 2018

fyi it is a known issue that ipv6 is not supported #1513

@reddycharan
Copy link
Contributor Author

@eolivelli added basic testcases validating cache functionality.

@@ -38,11 +40,26 @@
// Member fields that make up this class.
private final String hostname;
private final int port;
private final boolean isHostnameIPAddress;
Copy link
Contributor

Choose a reason for hiding this comment

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

With “optional” the Boolean shouldn’t be needed anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed boolean variable

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

I can't see the new test. Maybe you did not push

@reddycharan
Copy link
Contributor Author

@eolivelli my bad. fixed it.

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

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

👍

@sijie
Copy link
Member

sijie commented Nov 7, 2018

run integration tests

1 similar comment
@sijie
Copy link
Member

sijie commented Nov 7, 2018

run integration tests

* instance, if bookies are advertising hostnames and the IP change, the
* BK client will keep forever to try to connect to the old IP.
*/
return socketAddress.orElseGet(() -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

        return socketAddress.orElseGet(() -> new InetSocketAddress(hostname, port));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

multiline was suggestion from code formatter.

sijie pushed a commit that referenced this pull request Nov 8, 2018
Descriptions of the changes in this PR:

- in BookieSocketAddress if IPAddress is hostname then it is okay
to cache InetSocketAddress, since the canonicalhostname of the node
dont change.

Reviewers: Sijie Guo <sijie@apache.org>, Enrico Olivelli <eolivelli@gmail.com>, Matteo Merli <mmerli@apache.org>, Andrey Yegorov <None>

This closes #1789 from reddycharan/bookieaddressonlywhenhostname

(cherry picked from commit 102475a)
Signed-off-by: Sijie Guo <sijie@apache.org>
sijie pushed a commit that referenced this pull request Nov 8, 2018
Descriptions of the changes in this PR:

- in BookieSocketAddress if IPAddress is hostname then it is okay
to cache InetSocketAddress, since the canonicalhostname of the node
dont change.

Reviewers: Sijie Guo <sijie@apache.org>, Enrico Olivelli <eolivelli@gmail.com>, Matteo Merli <mmerli@apache.org>, Andrey Yegorov <None>

This closes #1789 from reddycharan/bookieaddressonlywhenhostname

(cherry picked from commit 102475a)
Signed-off-by: Sijie Guo <sijie@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants