Skip to content

Commit 6966c4f

Browse files
committed
HBase 1.x compatible
1 parent 70113f6 commit 6966c4f

File tree

7 files changed

+237
-70
lines changed

7 files changed

+237
-70
lines changed

pom.xml

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
<properties>
4848
<hadoop.version>1.2.1</hadoop.version>
49-
<hbase.version>0.98.24-hadoop1</hbase.version>
49+
<hbase.version>1.3.6</hbase.version>
5050
<java.source.version>1.8</java.source.version>
5151
<java.target.version>1.8</java.target.version>
5252
<junit.version>4.13.1</junit.version>
@@ -58,6 +58,58 @@
5858
</properties>
5959

6060
<dependencies>
61+
<dependency>
62+
<groupId>org.apache.hadoop</groupId>
63+
<artifactId>hadoop-core</artifactId>
64+
<version>${hadoop.version}</version>
65+
<exclusions>
66+
<exclusion>
67+
<artifactId>hsqldb</artifactId>
68+
<groupId>hsqldb</groupId>
69+
</exclusion>
70+
<exclusion>
71+
<artifactId>kfs</artifactId>
72+
<groupId>net.sf.kosmosfs</groupId>
73+
</exclusion>
74+
<exclusion>
75+
<artifactId>core</artifactId>
76+
<groupId>org.eclipse.jdt</groupId>
77+
</exclusion>
78+
<exclusion>
79+
<artifactId>jets3t</artifactId>
80+
<groupId>net.java.dev.jets3t</groupId>
81+
</exclusion>
82+
<exclusion>
83+
<artifactId>oro</artifactId>
84+
<groupId>oro</groupId>
85+
</exclusion>
86+
<exclusion>
87+
<artifactId>jasper-compiler</artifactId>
88+
<groupId>tomcat</groupId>
89+
</exclusion>
90+
<exclusion>
91+
<artifactId>jasper-runtime</artifactId>
92+
<groupId>tomcat</groupId>
93+
</exclusion>
94+
<exclusion>
95+
<artifactId>jackson-mapper-asl</artifactId>
96+
<groupId>org.codehaus.jackson</groupId>
97+
</exclusion>
98+
<exclusion>
99+
<artifactId>jettison</artifactId>
100+
<groupId>org.codehaus.jettison</groupId>
101+
</exclusion>
102+
<exclusion>
103+
<artifactId>commons-collections</artifactId>
104+
<groupId>commons-collections</groupId>
105+
</exclusion>
106+
</exclusions>
107+
</dependency>
108+
<dependency>
109+
<groupId>com.oceanbase</groupId>
110+
<artifactId>obkv-table-client</artifactId>
111+
<version>${table.client.version}</version>
112+
</dependency>
61113
<dependency>
62114
<groupId>org.apache.hbase</groupId>
63115
<artifactId>hbase-client</artifactId>
@@ -117,58 +169,6 @@
117169
</exclusion>
118170
</exclusions>
119171
</dependency>
120-
<dependency>
121-
<groupId>org.apache.hadoop</groupId>
122-
<artifactId>hadoop-core</artifactId>
123-
<version>${hadoop.version}</version>
124-
<exclusions>
125-
<exclusion>
126-
<artifactId>hsqldb</artifactId>
127-
<groupId>hsqldb</groupId>
128-
</exclusion>
129-
<exclusion>
130-
<artifactId>kfs</artifactId>
131-
<groupId>net.sf.kosmosfs</groupId>
132-
</exclusion>
133-
<exclusion>
134-
<artifactId>core</artifactId>
135-
<groupId>org.eclipse.jdt</groupId>
136-
</exclusion>
137-
<exclusion>
138-
<artifactId>jets3t</artifactId>
139-
<groupId>net.java.dev.jets3t</groupId>
140-
</exclusion>
141-
<exclusion>
142-
<artifactId>oro</artifactId>
143-
<groupId>oro</groupId>
144-
</exclusion>
145-
<exclusion>
146-
<artifactId>jasper-compiler</artifactId>
147-
<groupId>tomcat</groupId>
148-
</exclusion>
149-
<exclusion>
150-
<artifactId>jasper-runtime</artifactId>
151-
<groupId>tomcat</groupId>
152-
</exclusion>
153-
<exclusion>
154-
<artifactId>jackson-mapper-asl</artifactId>
155-
<groupId>org.codehaus.jackson</groupId>
156-
</exclusion>
157-
<exclusion>
158-
<artifactId>jettison</artifactId>
159-
<groupId>org.codehaus.jettison</groupId>
160-
</exclusion>
161-
<exclusion>
162-
<artifactId>commons-collections</artifactId>
163-
<groupId>commons-collections</groupId>
164-
</exclusion>
165-
</exclusions>
166-
</dependency>
167-
<dependency>
168-
<groupId>com.oceanbase</groupId>
169-
<artifactId>obkv-table-client</artifactId>
170-
<version>${table.client.version}</version>
171-
</dependency>
172172
<dependency>
173173
<groupId>org.slf4j</groupId>
174174
<artifactId>slf4j-api</artifactId>

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.alipay.oceanbase.rpc.ObTableClient;
2929
import com.alipay.oceanbase.rpc.mutation.BatchOperation;
3030
import com.alipay.oceanbase.rpc.mutation.result.BatchOperationResult;
31+
import com.alipay.oceanbase.rpc.property.Property;
3132
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
3233
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObRowKey;
3334
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.*;
@@ -39,7 +40,6 @@
3940
import com.alipay.oceanbase.rpc.stream.ObTableClientQueryAsyncStreamResult;
4041
import com.alipay.oceanbase.rpc.stream.ObTableClientQueryStreamResult;
4142
import com.alipay.sofa.common.thread.SofaThreadPoolExecutor;
42-
import com.alipay.oceanbase.hbase.exception.OperationTimeoutException;
4343

4444
import com.google.protobuf.Descriptors;
4545
import com.google.protobuf.Message;
@@ -368,8 +368,31 @@ public boolean exists(Get get) throws IOException {
368368
return !r.isEmpty();
369369
}
370370

371+
@Override
372+
public boolean[] existsAll(List<Get> list) throws IOException {
373+
if (list.isEmpty()) {
374+
return new boolean[]{};
375+
}
376+
if (list.size() == 1) {
377+
return new boolean[]{exists(list.get(0))};
378+
}
379+
380+
// todo: Optimize after CheckExistenceOnly is finished
381+
Result[] r = get(list);
382+
boolean[] ret = new boolean[r.length];
383+
for (int i = 0; i < r.length; ++i){
384+
ret[i] = !r[i].isEmpty();
385+
}
386+
return ret;
387+
}
388+
371389
public Boolean[] exists(List<Get> gets) throws IOException {
372-
throw new FeatureNotSupportedException("not supported yet'");
390+
Boolean[] result = new Boolean[gets.size()];
391+
boolean[] exists = existsAll(gets);
392+
for (int i = 0; i < gets.size(); ++i) {
393+
result[i] = exists[i];
394+
}
395+
return result;
373396
}
374397

375398
public void batch(List<? extends Row> actions, Object[] results) {
@@ -460,9 +483,14 @@ public Result call() throws IOException {
460483

461484
filter = buildObHTableFilter(get.getFilter(), get.getTimeRange(),
462485
get.getMaxVersions(), entry.getValue());
463-
464-
obTableQuery = buildObTableQuery(filter, get.getRow(), true,
465-
get.getRow(), true, -1);
486+
if (get.isClosestRowBefore()) {
487+
obTableQuery = buildObTableQuery(filter, null, false,
488+
get.getRow(), true, 1);
489+
obTableQuery.setScanOrder(ObScanOrder.Reverse);
490+
} else {
491+
obTableQuery = buildObTableQuery(filter, get.getRow(), true,
492+
get.getRow(), true, -1);
493+
}
466494

467495
request = buildObTableQueryRequest(obTableQuery,
468496
getTargetTableName(tableNameString, Bytes.toString(family)));
@@ -535,6 +563,9 @@ public ResultScanner call() throws IOException {
535563
if (scan.isReversed()) { // reverse scan 时设置为逆序
536564
obTableQuery.setScanOrder(ObScanOrder.Reverse);
537565
}
566+
obTableQuery.setMaxResultSize(scan.getMaxResultSize() > 0 ? scan.getMaxResultSize() : conf.getLong(
567+
HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY,
568+
HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE));
538569
request = buildObTableQueryAsyncRequest(obTableQuery, getTargetTableName(tableNameString));
539570
clientQueryAsyncStreamResult = (ObTableClientQueryAsyncStreamResult) obTableClient
540571
.execute(request);
@@ -558,7 +589,9 @@ public ResultScanner call() throws IOException {
558589
}
559590

560591
// no support set maxResultSize.
561-
// obTableQuery.setMaxResultSize(scan.getMaxResultSize());
592+
obTableQuery.setMaxResultSize(scan.getMaxResultSize() > 0 ? scan.getMaxResultSize() : conf.getLong(
593+
HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY,
594+
HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE));
562595

563596
request = buildObTableQueryAsyncRequest(obTableQuery,
564597
getTargetTableName(tableNameString, Bytes.toString(family)));
@@ -655,7 +688,12 @@ private void validatePut(Put put) {
655688
*/
656689
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put)
657690
throws IOException {
658-
return checkAndMutation(row, family, qualifier, value, put);
691+
return checkAndPut(row, family, qualifier, CompareFilter.CompareOp.EQUAL, value, put);
692+
}
693+
694+
@Override
695+
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Put put) throws IOException {
696+
return checkAndMutation(row, family, qualifier, compareOp, value, put);
659697
}
660698

661699
private void innerDelete(Delete delete) throws IOException {
@@ -708,10 +746,15 @@ public void delete(List<Delete> deletes) throws IOException {
708746
*/
709747
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, byte[] value,
710748
Delete delete) throws IOException {
711-
return checkAndMutation(row, family, qualifier, value, delete);
749+
return checkAndDelete(row, family, qualifier, CompareFilter.CompareOp.EQUAL, value, delete);
712750
}
713751

714-
private boolean checkAndMutation(byte[] row, byte[] family, byte[] qualifier, byte[] value,
752+
@Override
753+
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Delete delete) throws IOException {
754+
return checkAndMutation(row, family, qualifier, compareOp, value, delete);
755+
}
756+
757+
private boolean checkAndMutation(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value,
715758
Mutation mutation) throws IOException {
716759
try {
717760
checkArgument(row != null, "row is null");
@@ -721,7 +764,7 @@ private boolean checkAndMutation(byte[] row, byte[] family, byte[] qualifier, by
721764

722765
checkArgument(!mutation.isEmpty(), "mutation is empty");
723766

724-
String filterString = buildCheckAndMutateFilterString(family, qualifier, value);
767+
String filterString = buildCheckAndMutateFilterString(family, qualifier, compareOp, value);
725768

726769
ObHTableFilter filter = buildObHTableFilter(filterString, null, 1, qualifier);
727770

@@ -1120,13 +1163,30 @@ public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
11201163
throw new FeatureNotSupportedException("not supported yet'");
11211164
}
11221165

1166+
// operationTimeout means operation max wait time in client
1167+
@Override
11231168
public void setOperationTimeout(int operationTimeout) {
11241169
this.operationTimeout = operationTimeout;
11251170
this.operationExecuteInPool = this.configuration.getBoolean(
11261171
HBASE_CLIENT_OPERATION_EXECUTE_IN_POOL,
11271172
(this.operationTimeout != HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT));
11281173
}
11291174

1175+
@Override
1176+
public int getOperationTimeout() {
1177+
return operationTimeout;
1178+
}
1179+
1180+
// rpcTimeout means server max execute time, equal Table API rpc_execute_time, it must be set before OHTable init; please pass this parameter through conf
1181+
@Override
1182+
public void setRpcTimeout(int rpcTimeout) {
1183+
}
1184+
1185+
@Override
1186+
public int getRpcTimeout() {
1187+
return Integer.parseInt(configuration.get(Property.RPC_EXECUTE_TIMEOUT.getKey()));
1188+
}
1189+
11301190
public void setRuntimeBatchExecutor(ExecutorService runtimeBatchExecutor) {
11311191
this.obTableClient.setRuntimeBatchExecutor(runtimeBatchExecutor);
11321192
}
@@ -1215,13 +1275,13 @@ private ObHTableFilter buildObHTableFilter(Filter filter, TimeRange timeRange, i
12151275
return obHTableFilter;
12161276
}
12171277

1218-
private String buildCheckAndMutateFilterString(byte[] family, byte[] qualifier, byte[] value) {
1278+
private String buildCheckAndMutateFilterString(byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value) {
12191279
if (value != null) {
1220-
return ("CheckAndMutateFilter(=, 'binary:" + Bytes.toString(value) + "', '"
1280+
return ("CheckAndMutateFilter("+ HBaseFilterUtils.toParseableString(compareOp) +", 'binary:" + Bytes.toString(value) + "', '"
12211281
+ Bytes.toString(family) + "', '"
12221282
+ (qualifier == null ? "" : Bytes.toString(qualifier)) + "', false)");
12231283
} else {
1224-
return ("CheckAndMutateFilter(=, 'binary:', '" + Bytes.toString(family) + "', '"
1284+
return ("CheckAndMutateFilter("+ HBaseFilterUtils.toParseableString(compareOp) +", 'binary:', '" + Bytes.toString(family) + "', '"
12251285
+ (qualifier == null ? "" : Bytes.toString(qualifier)) + "', true)");
12261286
}
12271287
}

src/main/java/com/alipay/oceanbase/hbase/OHTableClient.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.alipay.oceanbase.hbase.core.Lifecycle;
2121
import com.alipay.oceanbase.hbase.exception.FeatureNotSupportedException;
22+
import com.alipay.oceanbase.rpc.property.Property;
2223
import com.google.protobuf.Descriptors;
2324
import com.google.protobuf.Message;
2425
import com.google.protobuf.Service;
@@ -195,6 +196,28 @@ public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
195196
throw new FeatureNotSupportedException("not supported yet'");
196197
}
197198

199+
@Override
200+
public void setOperationTimeout(int operationTimeout) {
201+
checkStatus();
202+
ohTable.setOperationTimeout(operationTimeout);
203+
}
204+
205+
@Override
206+
public int getOperationTimeout() {
207+
checkStatus();
208+
return ohTable.getOperationTimeout();
209+
}
210+
211+
@Override
212+
public void setRpcTimeout(int rpcTimeout) {
213+
conf.set(Property.RPC_EXECUTE_TIMEOUT.getKey(), String.valueOf(rpcTimeout));
214+
}
215+
216+
@Override
217+
public int getRpcTimeout() {
218+
return Integer.parseInt(conf.get(Property.RPC_EXECUTE_TIMEOUT.getKey()));
219+
}
220+
198221
@Override
199222
public byte[] getTableName() {
200223
return tableName;
@@ -224,9 +247,15 @@ public boolean exists(Get get) throws IOException {
224247
return ohTable.exists(get);
225248
}
226249

250+
@Override
251+
public boolean[] existsAll(List<Get> list) throws IOException {
252+
checkStatus();
253+
return ohTable.existsAll(list);
254+
}
255+
227256
@Override
228257
public Boolean[] exists(List<Get> gets) throws IOException {
229-
throw new FeatureNotSupportedException("not supported yet'");
258+
return ohTable.exists(gets);
230259
}
231260

232261
// Not support.
@@ -314,6 +343,12 @@ public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] v
314343
return ohTable.checkAndPut(row, family, qualifier, value, put);
315344
}
316345

346+
@Override
347+
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Put put) throws IOException {
348+
checkStatus();
349+
return ohTable.checkAndPut(row, family, qualifier, compareOp, value, put);
350+
}
351+
317352
@Override
318353
public void delete(Delete delete) throws IOException {
319354
checkStatus();
@@ -333,6 +368,12 @@ public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, byte[
333368
return ohTable.checkAndDelete(row, family, qualifier, value, delete);
334369
}
335370

371+
@Override
372+
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Delete delete) throws IOException {
373+
checkStatus();
374+
return ohTable.checkAndDelete(row, family, qualifier, compareOp, value, delete);
375+
}
376+
336377
// Not support.
337378
@Override
338379
public void mutateRow(RowMutations rm) throws IOException {

0 commit comments

Comments
 (0)