Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Commit

Permalink
fix logging
Browse files Browse the repository at this point in the history
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
  • Loading branch information
qinzuoyan committed Mar 28, 2018
1 parent cdba5e4 commit 7fbde17
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/xiaomi/infra/pegasus/rpc/Cluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* Created by [email protected] 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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -165,5 +170,7 @@ public void close() {
} catch (Exception ex) {
logger.warn("close table group failed: ", ex);
}

logger.info("cluster manager has closed");
}
}

0 comments on commit 7fbde17

Please sign in to comment.