From 7fbde179753fede6d9c55fd59164611ced414278 Mon Sep 17 00:00:00 2001 From: qinzuoyan Date: Wed, 28 Mar 2018 11:06:01 +0800 Subject: [PATCH] fix logging Summary: Ref T10114 Test Plan: N/A Reviewers: sunweijie, cailiuyang, laiyingchun Reviewed By: laiyingchun Subscribers: #pegasus Maniphest Tasks: T10114 Differential Revision: https://phabricator.d.xiaomi.net/D88948 --- .../xiaomi/infra/pegasus/client/PegasusClient.java | 4 ++++ .../java/com/xiaomi/infra/pegasus/rpc/Cluster.java | 1 + .../infra/pegasus/rpc/async/ClusterManager.java | 11 +++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClient.java b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClient.java index d47006f3..0c5862b0 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClient.java +++ b/src/main/java/com/xiaomi/infra/pegasus/client/PegasusClient.java @@ -7,6 +7,7 @@ import com.xiaomi.infra.pegasus.rpc.KeyHasher; import com.xiaomi.infra.pegasus.tools.tools; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -181,8 +182,11 @@ public String getConfigurationString() { public void close() { synchronized (this) { if (cluster != null) { + String metaList = StringUtils.join(cluster.getMetaList(), ","); + LOGGER.info("start to close pegasus client for [{}]", metaList); cluster.close(); cluster = null; + LOGGER.info("finish to close pegasus client for [{}]", metaList); } } } diff --git a/src/main/java/com/xiaomi/infra/pegasus/rpc/Cluster.java b/src/main/java/com/xiaomi/infra/pegasus/rpc/Cluster.java index 76080c2c..a290b0e6 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/rpc/Cluster.java +++ b/src/main/java/com/xiaomi/infra/pegasus/rpc/Cluster.java @@ -60,6 +60,7 @@ public static Cluster createCluster(Properties config) throws IllegalArgumentExc address); } + public abstract String[] getMetaList(); public abstract Table openTable(String name, KeyHasher function) throws ReplicationException, TException; public abstract void close(); } diff --git a/src/main/java/com/xiaomi/infra/pegasus/rpc/async/ClusterManager.java b/src/main/java/com/xiaomi/infra/pegasus/rpc/async/ClusterManager.java index b70f3c33..05f1b9b5 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/rpc/async/ClusterManager.java +++ b/src/main/java/com/xiaomi/infra/pegasus/rpc/async/ClusterManager.java @@ -25,6 +25,8 @@ * Created by sunweijie@xiaomi.com on 16-11-11. */ public class ClusterManager extends Cluster { + private static final Logger logger = org.slf4j.LoggerFactory.getLogger(ClusterManager.class); + private int operationTimeout; private int retryDelay; private boolean enableCounter; @@ -33,13 +35,12 @@ public class ClusterManager extends Cluster { private EventLoopGroup metaGroup; // group used for handle meta logic private EventLoopGroup replicaGroup; // group used for handle io with replica servers private EventLoopGroup tableGroup; // group used for handle table logic + private String[] metaList; private MetaSession metaSession; - private static final Logger logger; private static final String osName; private static final String Linux = "Linux"; static { - logger = org.slf4j.LoggerFactory.getLogger(ClusterManager.class); Properties p = System.getProperties(); osName = p.getProperty("os.name"); logger.info("operating system name: {}", osName); @@ -63,6 +64,7 @@ public ClusterManager( metaGroup = getEventLoopGroupInstance(1); tableGroup = getEventLoopGroupInstance(1); + metaList = address_list; // the constructor of meta session is depend on the replicaSessions, // so the replicaSessions should be initialized earlier metaSession = new MetaSession(this, address_list, timeout, 10, metaGroup); @@ -125,6 +127,9 @@ public static Class getSocketChannelClass() { return NioSocketChannel.class; } + @Override + public String[] getMetaList() { return metaList; } + @Override public TableHandler openTable(String name, KeyHasher h) throws ReplicationException { return new TableHandler(this, name, h); @@ -165,5 +170,7 @@ public void close() { } catch (Exception ex) { logger.warn("close table group failed: ", ex); } + + logger.info("cluster manager has closed"); } }