foreverneverer commented on code in PR #1104:
URL: https://github.com/apache/incubator-pegasus/pull/1104#discussion_r940828338
##########
java-client/src/main/java/org/apache/pegasus/client/PegasusTable.java:
##########
@@ -260,7 +261,11 @@ public void onCompletion(client_operator clientOP) {
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, "".getBytes(), sortKeyBlobs.size(), -1),
Review Comment:
`"".getBytes()` is used frequently, you can define it as const static
variable
##########
java-client/src/main/java/org/apache/pegasus/client/PegasusTable.java:
##########
@@ -740,7 +758,12 @@ public Future<CheckAndSetResult> asyncCheckAndSet(
public void onCompletion(client_operator clientOP) {
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, setValue == null ? 0 :
setValue.length),
Review Comment:
`setValue == null ? 0 : setValue.length` is also refactor as one method
##########
java-client/src/main/java/org/apache/pegasus/client/PegasusTable.java:
##########
@@ -2109,43 +2177,68 @@ private void handleWriteLimiterException(DefaultPromise
promise, String message)
}
static class Request {
- byte[] hashKey = null;
- byte[] sortKey = null;
- int sortKeyCount = 0;
+ byte[] hashKey = "".getBytes();
+ byte[] sortKey = "".getBytes();
+ int sortKeyCount = 1;
+
+ int valueLength = -1;
Request(byte[] hashKey) {
this.hashKey = hashKey;
}
Request(byte[] hashKey, byte[] sortKey) {
this.hashKey = hashKey;
- this.sortKey = sortKey;
+ this.sortKey = sortKey == null ? "".getBytes() : sortKey;
}
- Request(byte[] hashKey, int sortKeyCount) {
+ Request(byte[] hashKey, byte[] sortKey, int sortKeyCount, int valueLength)
{
this.hashKey = hashKey;
+ this.sortKey = sortKey == null ? "".getBytes() : sortKey;
this.sortKeyCount = sortKeyCount;
+ this.valueLength = valueLength;
}
private String getSubstring(byte[] key) {
String keyStr = key == null ? "" : new String(key);
return keyStr.length() < 32 ? keyStr : keyStr.substring(0, 32);
}
+ 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 ? "".getBytes() :
pair.getRight();
+ valuesLength += multiValue.length;
+ }
+ return valuesLength;
+ }
+
+ public static int getValueLength(Mutations mutations) {
+ if (mutations == null) {
+ return 0;
+ }
+ int valuesLength = 0;
+ for (mutate mu : mutations.getMutations()) {
+ byte[] MutateValue = mu.value == null ? "".getBytes() : mu.value.data;
+ valuesLength += MutateValue.length;
+ }
+ return valuesLength;
+ }
+
@Override
public String toString() {
if (sortKey != null) {
return String.format(
- "[hashKey[:32]=\"%s\",sortKey[:32]=\"%s\"]",
- getSubstring(hashKey), getSubstring(sortKey));
- }
-
- if (sortKeyCount > 0) {
- return String.format(
- "[hashKey[:32]=\"%s\",sortKeyCount=%d]", getSubstring(hashKey),
sortKeyCount);
+
"[hashKey[:32]=\"%s\",sortKey[:32]=\"%s\",sortKeyCount=%d,valueLength=%d]",
Review Comment:
`sortKey` has been assign `no-null`, the code is invalid
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]