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

Commit

Permalink
fix: fix bug where timeout in exception info is 0 (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
foreverneverer committed Nov 7, 2019
1 parent a9ddb5f commit a0ed820
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1730,8 +1730,9 @@ public List<PegasusScannerInterface> getUnorderedScanners(int maxSplitCount, Sca
return ret;
}

static void handleReplicaException(
public void handleReplicaException(
DefaultPromise promise, client_operator op, Table table, int timeout) {
if (timeout <= 0) timeout = defaultTimeout;
gpid gPid = op.get_gpid();
ReplicaConfiguration replicaConfiguration =
((TableHandler) table).getReplicaConfig(gPid.get_pidx());
Expand Down Expand Up @@ -1761,7 +1762,7 @@ static void handleReplicaException(
message = " Disconnected from the replica-server due to internal error!";
break;
case ERR_TIMEOUT:
message = " The operationTimeout is " + timeout + "ms!";
message = " The operation timeout is " + timeout + "ms!";
break;
case ERR_OBJECT_NOT_FOUND:
message = " The replica server doesn't serve this partition!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.xiaomi.infra.pegasus.apps.update_request;
import com.xiaomi.infra.pegasus.base.blob;
import com.xiaomi.infra.pegasus.base.error_code;
import com.xiaomi.infra.pegasus.base.error_code.error_types;
import com.xiaomi.infra.pegasus.base.gpid;
import com.xiaomi.infra.pegasus.operator.rrdb_put_operator;
import com.xiaomi.infra.pegasus.rpc.KeyHasher;
Expand Down Expand Up @@ -58,7 +59,8 @@ public void testHandleReplicationException() throws Exception {
op.rpc_error.errno = error_code.error_types.ERR_OBJECT_NOT_FOUND;

// set failure in promise, the exception is thrown as ExecutionException.
PegasusTable.handleReplicaException(promise, op, table, 1000);
PegasusTable pegasusTable = new PegasusTable(null, table);
pegasusTable.handleReplicaException(promise, op, table, 1000);
try {
promise.get();
} catch (ExecutionException e) {
Expand All @@ -76,4 +78,33 @@ public void testHandleReplicationException() throws Exception {
}
Assert.fail();
}

@Test
public void testTimeOutIsZero() throws Exception {
// ensure "PException ERR_TIMEOUT" is thrown with the real timeout value, when user given
// timeout is 0.
String[] metaList = {"127.0.0.1:34601", "127.0.0.1:34602", "127.0.0.1:34603"};
ClusterManager manager = new ClusterManager(1000, 1, false, null, 60, metaList);
TableHandler table = manager.openTable("temp", KeyHasher.DEFAULT);
DefaultPromise<Void> promise = table.newPromise();
update_request req = new update_request(new blob(), new blob(), 100);
gpid gpid = table.getGpidByHash(1);
rrdb_put_operator op = new rrdb_put_operator(gpid, table.getTableName(), req, 0);
op.rpc_error.errno = error_types.ERR_TIMEOUT;

PegasusTable pegasusTable = new PegasusTable(null, table);
pegasusTable.handleReplicaException(promise, op, table, 0);
try {
promise.get();
} catch (Exception e) {
TableHandler.ReplicaConfiguration replicaConfig = table.getReplicaConfig(gpid.get_pidx());
String server = replicaConfig.primary.get_ip() + ":" + replicaConfig.primary.get_port();

String msg =
String.format(
"com.xiaomi.infra.pegasus.client.PException: {version}: com.xiaomi.infra.pegasus.rpc.ReplicationException: ERR_TIMEOUT: [table=temp,operation=put,replicaServer=%s,gpid=(%s)] The operation timeout is 1000ms!",
server, gpid.toString());
Assert.assertEquals(e.getMessage(), msg);
}
}
}

0 comments on commit a0ed820

Please sign in to comment.