From a3324a22342e7437fe9c99f1e367047b5f7bcc20 Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Thu, 7 Nov 2019 15:12:54 +0800 Subject: [PATCH 1/2] fix bug --- pom.xml | 6 +++--- .../xiaomi/infra/pegasus/rpc/async/HostNameResolver.java | 5 +++++ .../com/xiaomi/infra/pegasus/rpc/async/MetaSession.java | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 887f3476..20efe87a 100644 --- 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..f8daf6a7 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) { @@ -26,10 +29,12 @@ public rpc_address[] resolve(String hostPort) throws IllegalArgumentException { InetAddress[] resolvedAddresses = InetAddress.getAllByName(pairs[0]); rpc_address[] results = new rpc_address[resolvedAddresses.length]; int size = 0; + logger.info("get all ip from the host {}", pairs[0]); for (InetAddress addr : resolvedAddresses) { 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("ip:{}", rpcAddr); 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..63b88a6b 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]); @@ -279,6 +279,7 @@ void resolveHost(String hostPort) throws IllegalArgumentException { metaList.add(clusterManager.getReplicaSession(addr)); logger.info("add {} as meta server", addr); } + logger.info("resolve host completed!"); } // Only for test. From 93a82633da303b3be400efc101ee2f49dd561e38 Mon Sep 17 00:00:00 2001 From: JiaShuo Date: Thu, 7 Nov 2019 15:36:20 +0800 Subject: [PATCH 2/2] change log info --- .../com/xiaomi/infra/pegasus/rpc/async/HostNameResolver.java | 4 ++-- .../java/com/xiaomi/infra/pegasus/rpc/async/MetaSession.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) 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 f8daf6a7..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 @@ -26,15 +26,15 @@ 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; - logger.info("get all ip from the host {}", pairs[0]); for (InetAddress addr : resolvedAddresses) { 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("ip:{}", rpcAddr); + 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 63b88a6b..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 @@ -279,7 +279,6 @@ void resolveHost(String hostPort) throws IllegalArgumentException { metaList.add(clusterManager.getReplicaSession(addr)); logger.info("add {} as meta server", addr); } - logger.info("resolve host completed!"); } // Only for test.