-
Notifications
You must be signed in to change notification settings - Fork 893
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
Cache InetSocketAddress if hostname is IPAddress #1789
Conversation
- in BookieSocketAddress if IPAddress is hostname then it is okay to cache InetSocketAddress, since the canonicalhostname of the node dont change.
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.
Good.
What about adding some test case?
I am interested in having tests with ipv6 addresses for instance
@reddycharan One other option could be to use |
@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 - bookkeeper/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java Line 578 in 3188933
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; |
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.
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.
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.
fixed it
@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 |
@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 |
fyi it is a known issue that ipv6 is not supported #1513 |
- addressing review comments
@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; |
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.
With “optional” the Boolean shouldn’t be needed anymore
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.
removed boolean variable
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.
I can't see the new test. Maybe you did not push
- review comments
@eolivelli my bad. fixed it. |
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.
👍
run integration tests |
1 similar comment
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(() -> { |
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.
nit:
return socketAddress.orElseGet(() -> new InetSocketAddress(hostname, port));
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.
multiline was suggestion from code formatter.
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>
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>
Descriptions of the changes in this PR:
to cache InetSocketAddress, since the canonicalhostname of the node
dont change.