From a9ddb5f52cab94f809b2a17a39ba17d019eb4967 Mon Sep 17 00:00:00 2001 From: Shuo Date: Thu, 7 Nov 2019 15:52:24 +0800 Subject: [PATCH] fix: fix block bug of InetAddressValidator.getInstance() (#64) --- pom.xml | 6 +++--- .../xiaomi/infra/pegasus/rpc/async/HostNameResolver.java | 5 +++++ .../com/xiaomi/infra/pegasus/rpc/async/MetaSession.java | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index c6025866..fa72be8a 100755 --- a/pom.xml +++ b/pom.xml @@ -14,9 +14,9 @@ test - commons-validator - commons-validator - 1.6 + com.google.guava + guava + 28.1-jre org.mockito diff --git a/src/main/java/com/xiaomi/infra/pegasus/rpc/async/HostNameResolver.java b/src/main/java/com/xiaomi/infra/pegasus/rpc/async/HostNameResolver.java index 3e8ce2f3..f24b7a73 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/rpc/async/HostNameResolver.java +++ b/src/main/java/com/xiaomi/infra/pegasus/rpc/async/HostNameResolver.java @@ -15,6 +15,9 @@ */ public class HostNameResolver { + private static final org.slf4j.Logger logger = + org.slf4j.LoggerFactory.getLogger(HostNameResolver.class); + public rpc_address[] resolve(String hostPort) throws IllegalArgumentException { String[] pairs = hostPort.split(":"); if (pairs.length != 2) { @@ -23,6 +26,7 @@ public rpc_address[] resolve(String hostPort) throws IllegalArgumentException { try { Integer port = Integer.valueOf(pairs[1]); + logger.info("start to resolve hostname {} into ip addresses", pairs[0]); InetAddress[] resolvedAddresses = InetAddress.getAllByName(pairs[0]); rpc_address[] results = new rpc_address[resolvedAddresses.length]; int size = 0; @@ -30,6 +34,7 @@ public rpc_address[] resolve(String hostPort) throws IllegalArgumentException { rpc_address rpcAddr = new rpc_address(); int ip = ByteBuffer.wrap(addr.getAddress()).order(ByteOrder.BIG_ENDIAN).getInt(); rpcAddr.address = ((long) ip << 32) + ((long) port << 16) + 1; + logger.info("resolved ip address {} from host {}", rpcAddr, pairs[0]); results[size++] = rpcAddr; } return results; diff --git a/src/main/java/com/xiaomi/infra/pegasus/rpc/async/MetaSession.java b/src/main/java/com/xiaomi/infra/pegasus/rpc/async/MetaSession.java index 86c3d931..8df5cdb7 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/rpc/async/MetaSession.java +++ b/src/main/java/com/xiaomi/infra/pegasus/rpc/async/MetaSession.java @@ -3,6 +3,7 @@ // can be found in the LICENSE file in the root directory of this source tree. package com.xiaomi.infra.pegasus.rpc.async; +import com.google.common.net.InetAddresses; import com.xiaomi.infra.pegasus.base.error_code.error_types; import com.xiaomi.infra.pegasus.base.rpc_address; import com.xiaomi.infra.pegasus.operator.client_operator; @@ -14,7 +15,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; -import org.apache.commons.validator.routines.InetAddressValidator; public class MetaSession extends HostNameResolver { public MetaSession( @@ -27,7 +27,7 @@ public MetaSession( clusterManager = manager; metaList = new ArrayList(); - if (addrList.length == 1 && !InetAddressValidator.getInstance().isValid(addrList[0])) { + if (addrList.length == 1 && !InetAddresses.isInetAddress(addrList[0])) { // if the given string is not a valid ip address, // then take it as a hostname for a try. resolveHost(addrList[0]);