This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 25326dcf0e improve: Improve host address resolution logic for bookie
id (#4588)
25326dcf0e is described below
commit 25326dcf0e3c51bab4a3e82c1f6f90b064ef6783
Author: Zixuan Liu <[email protected]>
AuthorDate: Mon Apr 21 19:20:08 2025 +0800
improve: Improve host address resolution logic for bookie id (#4588)
* improve: Improve host address resolution logic for bookie id
* Use InetAddress instead of InetSocketAddress
* Fix style
* Catch exception
---
.../org/apache/bookkeeper/bookie/BookieImpl.java | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java
index a37d559c7c..4ca771a40b 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java
@@ -37,7 +37,6 @@ import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.InetAddress;
-import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.file.FileStore;
@@ -267,16 +266,16 @@ public class BookieImpl implements Bookie {
iface = "default";
}
- String hostName = DNS.getDefaultHost(iface);
- InetSocketAddress inetAddr = new InetSocketAddress(hostName,
conf.getBookiePort());
- if (inetAddr.isUnresolved()) {
- throw new UnknownHostException("Unable to resolve default
hostname: "
- + hostName + " for interface: " + iface);
- }
- String hostAddress = null;
- InetAddress iAddress = inetAddr.getAddress();
+ String hostAddress = DNS.getDefaultIP(iface);
if (conf.getUseHostNameAsBookieID()) {
- hostAddress = iAddress.getCanonicalHostName();
+ try {
+ hostAddress =
InetAddress.getByName(hostAddress).getCanonicalHostName();
+ } catch (Exception e) {
+ UnknownHostException unknownHostException =
+ new UnknownHostException("Unable to resolve hostname
for interface: " + iface);
+ unknownHostException.initCause(e);
+ throw unknownHostException;
+ }
if (conf.getUseShortHostName()) {
/*
* if short hostname is used, then FQDN is not used. Short
@@ -284,8 +283,6 @@ public class BookieImpl implements Bookie {
*/
hostAddress = hostAddress.split("\\.", 2)[0];
}
- } else {
- hostAddress = iAddress.getHostAddress();
}
BookieSocketAddress addr =