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

improvement: add detailed information when operation has exception #106

Merged
merged 12 commits into from
May 19, 2020
15 changes: 10 additions & 5 deletions src/main/java/com/xiaomi/infra/pegasus/client/PException.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.xiaomi.infra.pegasus.client;

import com.xiaomi.infra.pegasus.base.error_code;
import com.xiaomi.infra.pegasus.client.PegasusTable.Request;
import com.xiaomi.infra.pegasus.rpc.ReplicationException;
import java.util.concurrent.TimeoutException;

Expand Down Expand Up @@ -33,20 +34,24 @@ public PException(Throwable cause) {
super(versionPrefix + cause.toString(), cause);
}

static PException threadInterrupted(String tableName, InterruptedException e) {
static PException threadInterrupted(
String metaList, String tableName, Request request, InterruptedException e) {
return new PException(
new ReplicationException(
error_code.error_types.ERR_THREAD_INTERRUPTED,
String.format("[table=%s] Thread was interrupted: %s", tableName, e.getMessage())));
String.format(
"[metaServer=%s, table=%s, request=%s] Thread was interrupted: %s",
metaList, tableName, request.toString(), e.getMessage())));
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
}

static PException timeout(String tableName, int timeout, TimeoutException e) {
static PException timeout(
String metaList, String tableName, Request request, int timeout, TimeoutException e) {
return new PException(
new ReplicationException(
error_code.error_types.ERR_TIMEOUT,
String.format(
"[table=%s, timeout=%dms] Timeout on Future await: %s",
tableName, timeout, e.getMessage())));
"[metaServer=%s, table=%s, request=%s, timeout=%dms] Timeout on Future await: %s",
metaList, tableName, request.toString(), timeout, e.getMessage())));
}

private static String loadVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class PegasusClient implements PegasusClientInterface {
private final Properties config;
private final ConcurrentHashMap<String, PegasusTable> tableMap;
private final Object tableMapLock;
private final String[] metaList;
private Cluster cluster;

private static class PegasusHasher implements KeyHasher {
Expand Down Expand Up @@ -88,6 +89,7 @@ public PegasusClient(Properties config) throws PException {
this.cluster = Cluster.createCluster(config);
this.tableMap = new ConcurrentHashMap<String, PegasusTable>();
this.tableMapLock = new Object();
this.metaList = cluster.getMetaList();
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
this.enableWriteLimit =
Boolean.parseBoolean(
config.getProperty(PEGASUS_ENABLE_WRITE_LIMIT, PEGASUS_ENABLE_WRITE_LIMIT_DEF));
Expand All @@ -98,6 +100,10 @@ public boolean isWriteLimitEnabled() {
return enableWriteLimit;
}

public String getMetaList() {
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
return Arrays.toString(metaList);
}

@Override
public void finalize() {
close();
Expand Down
Loading