You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by yu...@apache.org on 2022/08/23 09:18:30 UTC
[incubator-pegasus] branch master updated: refactor(java-client): add more detail message for error log (#1104)
This is an automated email from the ASF dual-hosted git repository.
yuchenhe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
The following commit(s) were added to refs/heads/master by this push:
new 207319d27 refactor(java-client): add more detail message for error log (#1104)
207319d27 is described below
commit 207319d27bb3dc3040d5ba091ad10b7162fa28b5
Author: ninsmiracle <11...@users.noreply.github.com>
AuthorDate: Tue Aug 23 09:18:25 2022 +0000
refactor(java-client): add more detail message for error log (#1104)
---
.../org/apache/pegasus/client/ClientOptions.java | 1 -
.../org/apache/pegasus/client/PegasusTable.java | 161 ++++++++++++++++-----
.../java/org/apache/pegasus/client/TestBasic.java | 104 ++++++++++++-
3 files changed, 231 insertions(+), 35 deletions(-)
diff --git a/java-client/src/main/java/org/apache/pegasus/client/ClientOptions.java b/java-client/src/main/java/org/apache/pegasus/client/ClientOptions.java
index 35ff22e57..38ec88eb9 100644
--- a/java-client/src/main/java/org/apache/pegasus/client/ClientOptions.java
+++ b/java-client/src/main/java/org/apache/pegasus/client/ClientOptions.java
@@ -233,7 +233,6 @@ public class ClientOptions {
result = 31 * result + Objects.hashCode(falconPushInterval.toMillis());
result = 31 * result + (enableWriteLimit ? 1 : 0);
result = 31 * result + Objects.hashCode(metaQueryTimeout.toMillis());
- result = 31 * result + authProtocol.hashCode();
result = 31 * result + credential.hashCode();
result = 31 * result + Objects.hashCode(sessionResetTimeWindowSecs);
return result;
diff --git a/java-client/src/main/java/org/apache/pegasus/client/PegasusTable.java b/java-client/src/main/java/org/apache/pegasus/client/PegasusTable.java
index d8de57eb8..c725fcb7d 100644
--- a/java-client/src/main/java/org/apache/pegasus/client/PegasusTable.java
+++ b/java-client/src/main/java/org/apache/pegasus/client/PegasusTable.java
@@ -47,6 +47,7 @@ import org.apache.pegasus.apps.key_value;
import org.apache.pegasus.apps.multi_get_request;
import org.apache.pegasus.apps.multi_put_request;
import org.apache.pegasus.apps.multi_remove_request;
+import org.apache.pegasus.apps.mutate;
import org.apache.pegasus.apps.update_request;
import org.apache.pegasus.base.blob;
import org.apache.pegasus.base.error_code;
@@ -219,7 +220,8 @@ public class PegasusTable implements PegasusTableInterface {
}
rrdb_put_operator gop = (rrdb_put_operator) clientOP;
if (gop.rpc_error.errno != error_code.error_types.ERR_OK) {
- handleReplicaException(new Request(hashKey, sortKey), promise, op, table, timeout);
+ handleReplicaException(
+ new Request(hashKey, sortKey, 1, value.length), promise, op, table, timeout);
} else if (gop.get_response().error != 0) {
promise.setFailure(new PException("rocksdb error: " + gop.get_response().error));
} else {
@@ -306,7 +308,11 @@ public class PegasusTable implements PegasusTableInterface {
rrdb_multi_get_operator gop = (rrdb_multi_get_operator) clientOP;
if (gop.rpc_error.errno != error_code.error_types.ERR_OK) {
handleReplicaException(
- new Request(hashKey, sortKeyBlobs.size()), promise, op, table, timeout);
+ new Request(hashKey, Request.EMPTY_BYTES, sortKeyBlobs.size(), -1),
+ promise,
+ op,
+ table,
+ timeout);
} else if (gop.get_response().error != 0 && gop.get_response().error != 7) {
// rocksdb::Status::kOk && rocksdb::Status::kIncomplete
promise.setFailure(new PException("rocksdb error: " + gop.get_response().error));
@@ -406,7 +412,11 @@ public class PegasusTable implements PegasusTableInterface {
rrdb_multi_get_operator gop = (rrdb_multi_get_operator) clientOP;
if (gop.rpc_error.errno != error_code.error_types.ERR_OK) {
handleReplicaException(
- new Request(hashKey, maxFetchCount), promise, op, table, timeout);
+ new Request(hashKey, Request.EMPTY_BYTES, maxFetchCount, -1),
+ promise,
+ op,
+ table,
+ timeout);
} else if (gop.get_response().error != 0 && gop.get_response().error != 7) {
// rocksdb::Status::kOk && rocksdb::Status::kIncomplete
promise.setFailure(new PException("rocksdb error: " + gop.get_response().error));
@@ -595,7 +605,15 @@ public class PegasusTable implements PegasusTableInterface {
rrdb_multi_put_operator op2 = (rrdb_multi_put_operator) clientOP;
if (op2.rpc_error.errno != error_code.error_types.ERR_OK) {
handleReplicaException(
- new Request(hashKey, values_blob.size()), promise, op, table, timeout);
+ new Request(
+ hashKey,
+ Request.EMPTY_BYTES,
+ values_blob.size(),
+ Request.getValueLength(values)),
+ promise,
+ op,
+ table,
+ timeout);
} else if (op2.get_response().error != 0) {
promise.setFailure(new PException("rocksdb error: " + op2.get_response().error));
} else {
@@ -690,7 +708,11 @@ public class PegasusTable implements PegasusTableInterface {
rrdb_multi_remove_operator op2 = (rrdb_multi_remove_operator) clientOP;
if (op2.rpc_error.errno != error_code.error_types.ERR_OK) {
handleReplicaException(
- new Request(hashKey, sortKeyBlobs.size()), promise, op, table, timeout);
+ new Request(hashKey, Request.EMPTY_BYTES, sortKeyBlobs.size(), -1),
+ promise,
+ op,
+ table,
+ timeout);
} else if (op2.get_response().error != 0) {
promise.setFailure(new PException("rocksdb error: " + op2.get_response().error));
} else {
@@ -824,7 +846,12 @@ public class PegasusTable implements PegasusTableInterface {
}
rrdb_check_and_set_operator op2 = (rrdb_check_and_set_operator) clientOP;
if (op2.rpc_error.errno != error_code.error_types.ERR_OK) {
- handleReplicaException(new Request(hashKey, setSortKey), promise, op, table, timeout);
+ handleReplicaException(
+ new Request(hashKey, setSortKey, 1, Request.getValueLength(setValue)),
+ promise,
+ op,
+ table,
+ timeout);
} else if (op2.get_response().error != 0
&& op2.get_response().error != 13) { // 13 : kTryAgain
promise.setFailure(new PException("rocksdb error: " + op2.get_response().error));
@@ -917,7 +944,11 @@ public class PegasusTable implements PegasusTableInterface {
rrdb_check_and_mutate_operator op2 = (rrdb_check_and_mutate_operator) clientOP;
if (op2.rpc_error.errno != error_code.error_types.ERR_OK) {
handleReplicaException(
- new Request(hashKey, mutations.getMutations().size()),
+ new Request(
+ hashKey,
+ checkSortKey,
+ mutations.getMutations().size(),
+ Request.getValueLength(mutations)),
promise,
op,
table,
@@ -1274,7 +1305,11 @@ public class PegasusTable implements PegasusTableInterface {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, count), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, Request.EMPTY_BYTES, maxFetchCount, -1),
+ timeout,
+ e);
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -1291,7 +1326,11 @@ public class PegasusTable implements PegasusTableInterface {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, count), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, Request.EMPTY_BYTES, count, -1),
+ timeout,
+ e);
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -1316,7 +1355,11 @@ public class PegasusTable implements PegasusTableInterface {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, maxFetchCount), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, Request.EMPTY_BYTES, maxFetchCount, -1),
+ timeout,
+ e);
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -1446,7 +1489,11 @@ public class PegasusTable implements PegasusTableInterface {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, sortKey), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, sortKey, 1, Request.getValueLength(value)),
+ timeout,
+ e);
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -1461,7 +1508,11 @@ public class PegasusTable implements PegasusTableInterface {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, sortKey), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, sortKey, 1, Request.getValueLength(value)),
+ timeout,
+ e);
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -1522,7 +1573,12 @@ public class PegasusTable implements PegasusTableInterface {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, count), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, Request.EMPTY_BYTES, count, Request.getValueLength(values)),
+ timeout,
+ e);
+
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -1539,7 +1595,11 @@ public class PegasusTable implements PegasusTableInterface {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, count), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, Request.EMPTY_BYTES, count, Request.getValueLength(values)),
+ timeout,
+ e);
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -1672,14 +1732,18 @@ public class PegasusTable implements PegasusTableInterface {
@Override
public void multiDel(byte[] hashKey, List<byte[]> sortKeys, int timeout) throws PException {
if (timeout <= 0) timeout = defaultTimeout;
- int count = sortKeys == null ? 0 : sortKeys.size();
+ int count = sortKeys == null ? -1 : sortKeys.size();
try {
asyncMultiDel(hashKey, sortKeys, timeout).get(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, count), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, Request.EMPTY_BYTES, count, -1),
+ timeout,
+ e);
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -1919,7 +1983,11 @@ public class PegasusTable implements PegasusTableInterface {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, count), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, checkSortKey, count, Request.getValueLength(mutations)),
+ timeout,
+ e);
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -1943,7 +2011,11 @@ public class PegasusTable implements PegasusTableInterface {
throw PException.threadInterrupted(table.getTableName(), e);
} catch (TimeoutException e) {
throw PException.timeout(
- metaList, table.getTableName(), new Request(hashKey, sortKey), timeout, e);
+ metaList,
+ table.getTableName(),
+ new Request(hashKey, sortKey, 1, Request.getValueLength(desiredValue)),
+ timeout,
+ e);
} catch (ExecutionException e) {
throw new PException(e);
}
@@ -2204,9 +2276,11 @@ public class PegasusTable implements PegasusTableInterface {
}
static class Request {
- byte[] hashKey = null;
- byte[] sortKey = null;
- int sortKeyCount = 0;
+ public static final byte[] EMPTY_BYTES = "".getBytes();
+ byte[] hashKey = EMPTY_BYTES;
+ byte[] sortKey = EMPTY_BYTES;
+ int sortKeyCount = 1;
+ int valueLength = -1;
Request(byte[] hashKey) {
this.hashKey = hashKey;
@@ -2214,12 +2288,14 @@ public class PegasusTable implements PegasusTableInterface {
Request(byte[] hashKey, byte[] sortKey) {
this.hashKey = hashKey;
- this.sortKey = sortKey;
+ this.sortKey = sortKey == null ? EMPTY_BYTES : sortKey;
}
- Request(byte[] hashKey, int sortKeyCount) {
+ Request(byte[] hashKey, byte[] sortKey, int sortKeyCount, int valueLength) {
this.hashKey = hashKey;
+ this.sortKey = sortKey == null ? EMPTY_BYTES : sortKey;
this.sortKeyCount = sortKeyCount;
+ this.valueLength = valueLength;
}
private String getSubstring(byte[] key) {
@@ -2227,20 +2303,39 @@ public class PegasusTable implements PegasusTableInterface {
return keyStr.length() < 32 ? keyStr : keyStr.substring(0, 32);
}
- @Override
- public String toString() {
- if (sortKey != null) {
- return String.format(
- "[hashKey[:32]=\"%s\",sortKey[:32]=\"%s\"]",
- getSubstring(hashKey), getSubstring(sortKey));
+ public static int getValueLength(byte[] value) {
+ return value == null ? 0 : value.length;
+ }
+
+ public static int getValueLength(List<Pair<byte[], byte[]>> values) {
+ if (values == null) {
+ return 0;
}
+ int valuesLength = 0;
+ for (Pair<byte[], byte[]> pair : values) {
+ byte[] multiValue = pair.getRight() == null ? EMPTY_BYTES : pair.getRight();
+ valuesLength += multiValue.length;
+ }
+ return valuesLength;
+ }
- if (sortKeyCount > 0) {
- return String.format(
- "[hashKey[:32]=\"%s\",sortKeyCount=%d]", getSubstring(hashKey), sortKeyCount);
+ public static int getValueLength(Mutations mutations) {
+ if (mutations == null) {
+ return 0;
+ }
+ int valuesLength = 0;
+ for (mutate mu : mutations.getMutations()) {
+ byte[] MutateValue = mu.value == null ? EMPTY_BYTES : mu.value.data;
+ valuesLength += MutateValue.length;
}
+ return valuesLength;
+ }
- return String.format("[hashKey[:32]=\"%s\"]", getSubstring(hashKey));
+ @Override
+ public String toString() {
+ return String.format(
+ "[hashKey[:32]=\"%s\",sortKey[:32]=\"%s\",sortKeyCount=%d,valueLength=%d]",
+ getSubstring(hashKey), getSubstring(sortKey), sortKeyCount, valueLength);
}
}
}
diff --git a/java-client/src/test/java/org/apache/pegasus/client/TestBasic.java b/java-client/src/test/java/org/apache/pegasus/client/TestBasic.java
index 6ef56ad0a..3faf06cba 100644
--- a/java-client/src/test/java/org/apache/pegasus/client/TestBasic.java
+++ b/java-client/src/test/java/org/apache/pegasus/client/TestBasic.java
@@ -20,6 +20,7 @@ package org.apache.pegasus.client;
/** @author qinzuoyan */
import io.netty.util.concurrent.Future;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -1939,7 +1940,7 @@ public class TestBasic {
System.out.println("Test set & ttl");
try {
Assert.assertNull(
- tb.asyncSet(key.getBytes(), key.getBytes(), key.getBytes(), 5, 0).await().getNow());
+ tb.asyncSet(key.getBytes(), key.getBytes(), key.getBytes(), 5, 1).await().getNow());
Assert.assertArrayEquals(
key.getBytes(), tb.asyncGet(key.getBytes(), key.getBytes(), 0).await().getNow());
@@ -2780,4 +2781,105 @@ public class TestBasic {
new String(actuallyRes.results.get(i - startIndex).getRight()));
}
}
+
+ @Test
+ public void testRequestDetail() throws PException {
+ Duration caseTimeout = Duration.ofMillis(1);
+ ClientOptions client_opt = ClientOptions.builder().operationTimeout(caseTimeout).build();
+
+ PegasusClientFactory.createClient(client_opt);
+ PegasusClientInterface client = PegasusClientFactory.createClient(client_opt);
+ String tableName = "temp";
+ PegasusTableInterface tb = client.openTable(tableName);
+
+ String HashPrefix = "TestHash";
+ String SortPrefix = "TestSort";
+ String hashKey = HashPrefix + "_0";
+ String sortKey = SortPrefix + "_0";
+
+ try {
+ // multiSet timeout
+ System.out.println("Test multiSet PException request");
+
+ String multiValue2 = RandomStringUtils.random(5, true, true);
+ List<Pair<byte[], byte[]>> multiValues2 = new ArrayList<Pair<byte[], byte[]>>();
+ int count2 = 500;
+ while (count2-- > 0) {
+ multiValues2.add(Pair.of(sortKey.getBytes(), multiValue2.getBytes()));
+ }
+
+ Throwable exception =
+ Assertions.assertThrows(
+ PException.class,
+ () -> {
+ client.multiSet(tableName, hashKey.getBytes(), multiValues2);
+ });
+ Assert.assertTrue(
+ exception
+ .getMessage()
+ .contains(
+ "request=[hashKey[:32]=\"TestHash_0\",sortKey[:32]=\"\",sortKeyCount=500,valueLength=2500]"));
+
+ // checkAndMutate timeout
+ System.out.println("Test checkAndMutate PException request");
+ Mutations mutations = new Mutations();
+ mutations.set(sortKey.getBytes(), "2".getBytes());
+
+ CheckAndMutateOptions options = new CheckAndMutateOptions();
+ options.returnCheckValue = true;
+ Throwable exception2 =
+ Assertions.assertThrows(
+ PException.class,
+ () -> {
+ client.checkAndMutate(
+ tableName,
+ hashKey.getBytes(),
+ "k5".getBytes(),
+ CheckType.CT_VALUE_INT_LESS,
+ "2".getBytes(),
+ mutations,
+ options);
+ });
+ Assert.assertTrue(
+ exception2
+ .getMessage()
+ .contains(
+ "request=[hashKey[:32]=\"TestHash_0\",sortKey[:32]=\"k5\",sortKeyCount=1,valueLength=1]"));
+
+ // multiDel timeout
+ System.out.println("Test multiDel PException request");
+ List<Pair<byte[], byte[]>> multiValues3 = new ArrayList<Pair<byte[], byte[]>>();
+ List<byte[]> sortKeys = new ArrayList<byte[]>();
+ multiValues3.add(
+ Pair.of("basic_test_sort_key_0".getBytes(), "basic_test_value_0".getBytes()));
+ multiValues3.add(
+ Pair.of("basic_test_sort_key_1".getBytes(), "basic_test_value_1".getBytes()));
+ multiValues3.add(
+ Pair.of("basic_test_sort_key_2".getBytes(), "basic_test_value_2".getBytes()));
+ sortKeys.add("basic_test_sort_key_0".getBytes());
+ sortKeys.add("basic_test_sort_key_1".getBytes());
+ sortKeys.add("basic_test_sort_key_2".getBytes());
+
+ tb.multiSet(hashKey.getBytes(), multiValues3, 5000);
+ Assertions.assertDoesNotThrow(
+ () -> {
+ tb.multiSet(hashKey.getBytes(), multiValues3, 5000);
+ });
+
+ Throwable exception3 =
+ Assertions.assertThrows(
+ PException.class,
+ () -> {
+ client.multiDel(tableName, hashKey.getBytes(), sortKeys);
+ });
+ Assert.assertTrue(
+ exception3
+ .getMessage()
+ .contains(
+ "request=[hashKey[:32]=\"TestHash_0\",sortKey[:32]=\"\",sortKeyCount=3,valueLength=-1]"));
+
+ } catch (Throwable e) {
+ Assert.fail();
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org