Skip to content

Commit 49bc74c

Browse files
committed
new hbase request and result for multi-cf
1 parent a644aba commit 49bc74c

File tree

8 files changed

+452
-118
lines changed

8 files changed

+452
-118
lines changed

src/main/java/com/alipay/oceanbase/rpc/ObGlobal.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public static boolean isCellTTLSupport() {
121121
return OB_VERSION >= OB_VERSION_4_3_5_1;
122122
}
123123

124+
public static boolean isHBasePutPerfSupport() {
125+
return OB_VERSION >= OB_VERSION_4_4_1_0;
126+
}
127+
124128
public static final long OB_VERSION_4_2_3_0 = calcVersion(4, (short) 2, (byte) 3, (byte) 0);
125129

126130
public static final long OB_VERSION_4_2_5_2 = calcVersion(4, (short) 2, (byte) 5, (byte) 2);
@@ -139,5 +143,7 @@ public static boolean isCellTTLSupport() {
139143

140144
public static final long OB_VERSION_4_4_0_0 = calcVersion(4, (short) 4, (byte) 0, (byte) 0);
141145

146+
public static final long OB_VERSION_4_4_1_0 = calcVersion(4, (short) 4, (byte) 1, (byte) 0);
147+
142148
public static long OB_VERSION = calcVersion(0, (short) 0, (byte) 0, (byte) 0);
143149
}

src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,11 +2394,13 @@ public ObPayload execute(final ObHbaseRequest request) throws Exception {
23942394
return getOdpTable().execute(request);
23952395
} else {
23962396
Row row = new Row();
2397-
row.add("K", request.getKeys().get(0).getValue());
2398-
row.add("Q", request.getCells().get(0).getQ().getValue());
2399-
row.add("T", request.getCells().get(0).getT().getValue());
2400-
row.add("V", request.getCells().get(0).getV().getValue());
2401-
ObTableParam tableParam = tableRoute.getTableParam(request.getTableName(), row);
2397+
// get the first cell from the first cfRows to route
2398+
String realTableName = request.getCfRows().get(0).getRealTableName();
2399+
int keyIdx = request.getCfRows().get(0).getKeyIndex(0);
2400+
row.add("K", request.getKeys().get(keyIdx).getValue());
2401+
row.add("Q", request.getCfRows().get(0).getCells().get(0).getQ().getValue());
2402+
row.add("T", request.getCfRows().get(0).getCells().get(0).getT().getValue());
2403+
ObTableParam tableParam = tableRoute.getTableParam(realTableName, row);
24022404
ObTable obTable = tableParam.getObTable();
24032405
return executeWithRetry(obTable, request, request.getTableName());
24042406
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*-
2+
* #%L
3+
* OBKV Table Client Framework
4+
* %%
5+
* Copyright (C) 2021 OceanBase
6+
* %%
7+
* OBKV Table Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
18+
package com.alipay.oceanbase.rpc.protocol.payload.impl.execute;
19+
20+
import com.alipay.oceanbase.rpc.protocol.payload.AbstractPayload;
21+
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
22+
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObTableSerialUtil;
23+
import com.alipay.oceanbase.rpc.util.ObByteBuf;
24+
import com.alipay.oceanbase.rpc.util.Serialization;
25+
26+
public class ObHbaseCell extends AbstractPayload {
27+
// if there are more elements in the future
28+
// add new constructor to create new array
29+
// cannot List because its size cannot be initialized and is dynamic
30+
private ObObj[] propertiesValue = null; // Q T V (TTL)
31+
32+
public ObHbaseCell(boolean isCellTTL) {
33+
propertiesValue = isCellTTL ? new ObObj[4] : new ObObj[3];
34+
}
35+
36+
public void encode(ObByteBuf buf) {
37+
// 0. encode header
38+
encodeHeader(buf);
39+
40+
// 1. encode properties value
41+
Serialization.encodeVi64(buf, propertiesValue.length);
42+
for (ObObj obj : propertiesValue) {
43+
ObTableSerialUtil.encode(buf, obj);
44+
}
45+
}
46+
47+
@Override
48+
public byte[] encode() {
49+
byte[] bytes = new byte[(int) getPayloadSize()];
50+
int idx = 0;
51+
52+
// 0. encode header
53+
idx = encodeHeader(bytes, idx);
54+
55+
// 1. encode properties value
56+
int len = Serialization.getNeedBytes(propertiesValue.length);
57+
System.arraycopy(Serialization.encodeVi64(propertiesValue.length), 0, bytes, idx, len);
58+
idx += len;
59+
for (ObObj obj : propertiesValue) {
60+
len = ObTableSerialUtil.getEncodedSize(obj);
61+
System.arraycopy(ObTableSerialUtil.encode(obj), 0, bytes, idx, len);
62+
idx += len;
63+
}
64+
return bytes;
65+
}
66+
67+
@Override
68+
public long getPayloadContentSize() {
69+
if (this.payLoadContentSize == INVALID_PAYLOAD_CONTENT_SIZE) {
70+
long payloadContentSize = 0;
71+
// add properties value array size and value
72+
payloadContentSize += Serialization.getNeedBytes(propertiesValue.length);
73+
for (ObObj obj : propertiesValue) {
74+
payloadContentSize += ObTableSerialUtil.getEncodedSize(obj);
75+
}
76+
this.payLoadContentSize = payloadContentSize;
77+
}
78+
return this.payLoadContentSize;
79+
}
80+
81+
public ObObj getQ() {
82+
return propertiesValue[0];
83+
}
84+
85+
public ObObj getT() {
86+
return propertiesValue[1];
87+
}
88+
89+
public ObObj getV() {
90+
return propertiesValue[2];
91+
}
92+
93+
public ObObj getTTL() {
94+
if (propertiesValue.length == 3) {
95+
throw new IllegalArgumentException("table schema has no cell TTL");
96+
}
97+
return propertiesValue[3];
98+
}
99+
100+
public void setQ(ObObj Q) {
101+
propertiesValue[0] = Q;
102+
}
103+
104+
public void setT(ObObj T) {
105+
propertiesValue[1] = T;
106+
}
107+
108+
public void setV(ObObj V) {
109+
propertiesValue[2] = V;
110+
}
111+
112+
public void setTTL(ObObj TTL) {
113+
if (propertiesValue.length == 3) {
114+
throw new IllegalArgumentException("table schema has no cell TTL");
115+
}
116+
propertiesValue[3] = TTL;
117+
}
118+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-table-client
4+
* %%
5+
* Copyright (C) 2021 - 2025 OceanBase
6+
* %%
7+
* OBKV Table Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
18+
package com.alipay.oceanbase.rpc.protocol.payload.impl.execute;
19+
20+
import com.alipay.oceanbase.rpc.protocol.payload.AbstractPayload;
21+
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
22+
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObTableSerialUtil;
23+
import com.alipay.oceanbase.rpc.util.Serialization;
24+
import io.netty.buffer.ByteBuf;
25+
26+
import java.util.ArrayList;
27+
import java.util.List;
28+
29+
public class ObHbaseCellResult extends AbstractPayload {
30+
private long keyIndex; // mapping to the right HBase operation
31+
private List<ObObj> propertiesValues = new ArrayList<>(); // HBase Get result
32+
33+
public ObHbaseCellResult() {
34+
keyIndex = -1;
35+
}
36+
37+
public ObHbaseCellResult(long keyIndex) {
38+
this.keyIndex = keyIndex;
39+
}
40+
41+
public long getKeyIndex() {
42+
return keyIndex;
43+
}
44+
45+
public List<ObObj> getPropertiesValues() {
46+
return propertiesValues;
47+
}
48+
49+
@Override
50+
public byte[] encode() {
51+
return new byte[0];
52+
}
53+
54+
@Override
55+
public Object decode(ByteBuf buf) {
56+
// 0. decode version
57+
super.decode(buf);
58+
59+
// 1. decode key index
60+
keyIndex = Serialization.decodeVi64(buf);
61+
62+
// 2. decode properties values
63+
int len = (int) Serialization.decodeVi64(buf);
64+
for (int i = 0; i < len; ++i) {
65+
ObObj obj = new ObObj();
66+
ObTableSerialUtil.decode(buf, obj);
67+
this.propertiesValues.add(obj);
68+
}
69+
return this;
70+
}
71+
72+
@Override
73+
public long getPayloadContentSize() {
74+
return 0;
75+
}
76+
}

0 commit comments

Comments
 (0)