Skip to content

Commit b5d0f42

Browse files
committed
skip entity serialize when hbase batch get
1 parent 74ecc7c commit b5d0f42

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/main/java/com/alipay/oceanbase/rpc/protocol/payload/impl/execute/ObTableSingleOp.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ public byte[] encode() {
6464
}
6565

6666
// 4. encode entities
67-
len = Serialization.getNeedBytes(entities.size());
68-
System.arraycopy(Serialization.encodeVi64(entities.size()), 0, bytes, idx, len);
69-
idx += len;
70-
for (ObTableSingleOpEntity entity : entities) {
71-
len = (int) entity.getPayloadSize();
72-
System.arraycopy(entity.encode(), 0, bytes, idx, len);
67+
if (!((singleOpType == ObTableOperationType.SCAN) && query.isHbaseQuery())) {
68+
len = Serialization.getNeedBytes(entities.size());
69+
System.arraycopy(Serialization.encodeVi64(entities.size()), 0, bytes, idx, len);
7370
idx += len;
71+
for (ObTableSingleOpEntity entity : entities) {
72+
len = (int) entity.getPayloadSize();
73+
System.arraycopy(entity.encode(), 0, bytes, idx, len);
74+
idx += len;
75+
}
7476
}
7577

7678
return bytes;
@@ -109,9 +111,11 @@ public long getPayloadContentSize() {
109111
if (ObTableOperationType.needEncodeQuery(singleOpType)) {
110112
payloadContentSize += query.getPayloadSize();
111113
}
112-
payloadContentSize += Serialization.getNeedBytes(entities.size());
113-
for (ObTableSingleOpEntity entity : entities) {
114-
payloadContentSize += entity.getPayloadSize();
114+
if (!((singleOpType == ObTableOperationType.SCAN) && query.isHbaseQuery())) {
115+
payloadContentSize += Serialization.getNeedBytes(entities.size());
116+
for (ObTableSingleOpEntity entity : entities) {
117+
payloadContentSize += entity.getPayloadSize();
118+
}
115119
}
116120
this.payLoadContentSize = payloadContentSize;
117121
}

src/main/java/com/alipay/oceanbase/rpc/util/Serialization.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,13 @@ public static void encodeFloat(ObByteBuf buf, float f) {
442442
*/
443443
public static int getNeedBytes(long l) {
444444
if (l < 0) {
445-
return 10; // 负数固定返回10字节
445+
return 10;
446446
}
447-
// 计算最高位的位置,然后除以8(一个字节8位)向上取整
448-
return (Long.SIZE - Long.numberOfLeadingZeros(l) + 7) >>> 3;
447+
if (l == 0) {
448+
return 1;
449+
}
450+
// 计算有效位数,然后除以7向上取整
451+
return (Long.SIZE - Long.numberOfLeadingZeros(l) + 6) / 7;
449452
}
450453

451454
/**
@@ -455,10 +458,13 @@ public static int getNeedBytes(long l) {
455458
*/
456459
public static int getNeedBytes(int l) {
457460
if (l < 0) {
458-
return 5; // 负数固定返回5字节
461+
return 5;
462+
}
463+
if (l == 0) {
464+
return 1;
459465
}
460-
// 计算最高位的位置,然后除以8(一个字节8位)向上取整
461-
return (Integer.SIZE - Integer.numberOfLeadingZeros(l) + 7) >>> 3;
466+
// 计算有效位数,然后除以7向上取整
467+
return (Integer.SIZE - Integer.numberOfLeadingZeros(l) + 6) / 7;
462468
}
463469

464470
/**

0 commit comments

Comments
 (0)