You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2020/01/10 07:54:40 UTC

[GitHub] [bookkeeper] liudezhi2098 opened a new pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

liudezhi2098 opened a new pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240
 
 
   
   ### Motivation
   In some cases, Bookie obtained the local IP of 127.0.0.1, which caused an abnormal report status.
   get ip method:
   `InetAddress.getLocalHost().getHostAddress();`
   host
   ```
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
     ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
   ```
   _Although it can be solved by setting up the host, but the customer does not necessarily set it when using it, so if you do not rely on this when obtaining the IP, it will be much more friendly_
   
   fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
   
   
   ### Changes
   
   Added a method to get the local IP in NetUtils, and replaced the other places to get the IP
   
   
   
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r365136492
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +85,52 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+   public static String getLocalHost() throws UnknownHostException {
+        try {
+            String ip = InetAddress.getLocalHost().getHostAddress();
+            if (ip.equals("127.0.0.1")) {
+                return getAddress();
+            } else
+                return ip;
+        } catch (Throwable e) {
+            String ip = getAddress();
+            if (ip != null && !ip.isEmpty()) {
+                return ip;
+            }
+            throw new UnknownHostException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException,"
+                    + e.getMessage());
+        }
+    }
+    
+    private static boolean isboolIp(String ipAddress) {
+        String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
+        Pattern pattern = Pattern.compile(ip);
 
 Review comment:
   You are right

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r398498456
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +92,46 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+    public static String getLocalHost() throws UnknownHostException {
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        if (InetAddress.getLocalHost().isLoopbackAddress()) {
+            return getAddress();
+        } else {
+            return ip;
+        }
+
+    }
+
+    private static boolean isboolIp(String ipAddress) {
 
 Review comment:
   I will call this method isIpAddressValid 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] eolivelli commented on issue #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
eolivelli commented on issue #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#issuecomment-603694632
 
 
   @liudezhi2098  do you have time to fix my comments.
   It would be good to have this patch delivered in 4.11.0

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r398499062
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +92,46 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+    public static String getLocalHost() throws UnknownHostException {
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        if (InetAddress.getLocalHost().isLoopbackAddress()) {
+            return getAddress();
+        } else {
+            return ip;
+        }
+
+    }
+
+    private static boolean isboolIp(String ipAddress) {
+        Matcher matcher = pattern.matcher(ipAddress);
+        return matcher.matches();
+    }
+
+    private static String getAddress() throws UnknownHostException {
 
 Review comment:
   Already dealt with at  910f6c7

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r365127862
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +85,52 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+   public static String getLocalHost() throws UnknownHostException {
+        try {
+            String ip = InetAddress.getLocalHost().getHostAddress();
+            if (ip.equals("127.0.0.1")) {
+                return getAddress();
+            } else
+                return ip;
+        } catch (Throwable e) {
 
 Review comment:
   Please catch the exact expected exception type

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on issue #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on issue #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#issuecomment-610153661
 
 
   retest this please

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r369246388
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +85,52 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+   public static String getLocalHost() throws UnknownHostException {
+        try {
+            String ip = InetAddress.getLocalHost().getHostAddress();
+            if (ip.equals("127.0.0.1")) {
+                return getAddress();
+            } else
+                return ip;
+        } catch (Throwable e) {
+            String ip = getAddress();
+            if (ip != null && !ip.isEmpty()) {
+                return ip;
+            }
+            throw new UnknownHostException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException,"
+                    + e.getMessage());
+        }
+    }
+    
+    private static boolean isboolIp(String ipAddress) {
+        String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
+        Pattern pattern = Pattern.compile(ip);
 
 Review comment:
   You are missing this change

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r369247197
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +86,44 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+    public static String getLocalHost() throws UnknownHostException {
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        if (ip.equals("127.0.0.1")) {
+            return getAddress();
+        } else
+            return ip;
+        
+    }
+    
+    private static boolean isboolIp(String ipAddress) {
+        Pattern pattern = Pattern.compile(ip);
+        Matcher matcher = pattern.matcher(ipAddress);
+        return matcher.matches();
+    }
+    
+    private static String getAddress() throws UnknownHostException {
+        try {
+            for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements();) {
+                NetworkInterface networkInterface = interfaces.nextElement();
+                if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp()) {
+                    continue;
+                }
+                Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
+                if (addresses.hasMoreElements()) {
+                    while (addresses.hasMoreElements()) {
+                        String ip = addresses.nextElement().getHostAddress();
+                        if (isboolIp(ip)) {
+                            return ip;
+                        }
+                    }
+                }
+            }
+            throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException");
+        } catch (Throwable e) {
 
 Review comment:
   Please catch only specific exceptions

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r365136851
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +85,52 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+   public static String getLocalHost() throws UnknownHostException {
+        try {
+            String ip = InetAddress.getLocalHost().getHostAddress();
+            if (ip.equals("127.0.0.1")) {
+                return getAddress();
+            } else
+                return ip;
+        } catch (Throwable e) {
 
 Review comment:
   This exception is superfluous and has been removed

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r369246969
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +86,44 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+    public static String getLocalHost() throws UnknownHostException {
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        if (ip.equals("127.0.0.1")) {
 
 Review comment:
   We should use a better way, this approach does not deal with the whole 127.0.0.0/24 class and with ipv6
   
   I think there is some InteAddress.isLoopback method

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r375218430
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +86,44 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+    public static String getLocalHost() throws UnknownHostException {
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        if (ip.equals("127.0.0.1")) {
 
 Review comment:
   You are right

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on issue #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on issue #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#issuecomment-589523096
 
 
   retest this please

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r375218056
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +86,44 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+    public static String getLocalHost() throws UnknownHostException {
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        if (ip.equals("127.0.0.1")) {
+            return getAddress();
+        } else
+            return ip;
+        
+    }
+    
+    private static boolean isboolIp(String ipAddress) {
+        Pattern pattern = Pattern.compile(ip);
+        Matcher matcher = pattern.matcher(ipAddress);
+        return matcher.matches();
+    }
+    
+    private static String getAddress() throws UnknownHostException {
+        try {
+            for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements();) {
+                NetworkInterface networkInterface = interfaces.nextElement();
+                if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp()) {
+                    continue;
+                }
+                Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
+                if (addresses.hasMoreElements()) {
+                    while (addresses.hasMoreElements()) {
+                        String ip = addresses.nextElement().getHostAddress();
+                        if (isboolIp(ip)) {
+                            return ip;
+                        }
+                    }
+                }
+            }
+            throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException");
+        } catch (Throwable e) {
 
 Review comment:
   ok,catch  SocketException 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r365126659
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
 ##########
 @@ -466,7 +466,7 @@ private void fillReadAheadCache(long orginalLedgerId, long firstEntryId, long fi
             long size = 0;
 
             while (count < readAheadCacheBatchSize && currentEntryLogId == firstEntryLogId) {
-                ByteBuf entry = entryLogger.internalReadEntry(orginalLedgerId, -1, currentEntryLocation,
+                ByteBuf entry = entryLogger.internalReadEntry(orginalLedgerId, firstEntryId, currentEntryLocation,
 
 Review comment:
   This change is not part of this task.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r388745909
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +92,46 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+    public static String getLocalHost() throws UnknownHostException {
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        if (InetAddress.getLocalHost().isLoopbackAddress()) {
+            return getAddress();
+        } else {
+            return ip;
+        }
+
+    }
+
+    private static boolean isboolIp(String ipAddress) {
+        Matcher matcher = pattern.matcher(ipAddress);
+        return matcher.matches();
+    }
+
+    private static String getAddress() throws UnknownHostException {
 
 Review comment:
   please call this method **getValidAddress** or something like that

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r365127350
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +85,52 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+   public static String getLocalHost() throws UnknownHostException {
+        try {
+            String ip = InetAddress.getLocalHost().getHostAddress();
+            if (ip.equals("127.0.0.1")) {
+                return getAddress();
+            } else
+                return ip;
+        } catch (Throwable e) {
+            String ip = getAddress();
+            if (ip != null && !ip.isEmpty()) {
+                return ip;
+            }
+            throw new UnknownHostException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException,"
+                    + e.getMessage());
+        }
+    }
+    
+    private static boolean isboolIp(String ipAddress) {
+        String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
+        Pattern pattern = Pattern.compile(ip);
 
 Review comment:
   You can make this variable static

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r365135231
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/SingleDirectoryDbLedgerStorage.java
 ##########
 @@ -466,7 +466,7 @@ private void fillReadAheadCache(long orginalLedgerId, long firstEntryId, long fi
             long size = 0;
 
             while (count < readAheadCacheBatchSize && currentEntryLogId == firstEntryLogId) {
-                ByteBuf entry = entryLogger.internalReadEntry(orginalLedgerId, -1, currentEntryLocation,
+                ByteBuf entry = entryLogger.internalReadEntry(orginalLedgerId, firstEntryId, currentEntryLocation,
 
 Review comment:
   ok , removed

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r388745813
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +92,46 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+    public static String getLocalHost() throws UnknownHostException {
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        if (InetAddress.getLocalHost().isLoopbackAddress()) {
+            return getAddress();
+        } else {
+            return ip;
+        }
+
+    }
+
+    private static boolean isboolIp(String ipAddress) {
 
 Review comment:
   please call this method **acceptIpAddress** or **isIpAddressValid** or **canUseIpAddress**
   please make it visibility "package" and add unit tests.
   
   from the regexp I see that we won't allow IPv6 addresses

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [bookkeeper] liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1

Posted by GitBox <gi...@apache.org>.
liudezhi2098 commented on a change in pull request #2240: fix the problem that the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r375217551
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
 ##########
 @@ -85,4 +85,52 @@ public static String resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
         return rNames.get(0);
     }
 
+   public static String getLocalHost() throws UnknownHostException {
+        try {
+            String ip = InetAddress.getLocalHost().getHostAddress();
+            if (ip.equals("127.0.0.1")) {
+                return getAddress();
+            } else
+                return ip;
+        } catch (Throwable e) {
+            String ip = getAddress();
+            if (ip != null && !ip.isEmpty()) {
+                return ip;
+            }
+            throw new UnknownHostException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException,"
+                    + e.getMessage());
+        }
+    }
+    
+    private static boolean isboolIp(String ipAddress) {
+        String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
+        Pattern pattern = Pattern.compile(ip);
 
 Review comment:
   sorry, already change

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services