Skip to content

Commit 350df08

Browse files
authored
Merge pull request #255 from oceanbase/hbase_compat_3_2.0
feat: HBase Compatibility Phase 3 - Ecosystem Integration and DDL Support
2 parents 4b563a8 + 9566d42 commit 350df08

33 files changed

+5499
-58
lines changed

example/simple-hbase-demo/src/main/java/com/oceanbase/example/SimpleHBaseClientDemo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import com.alipay.oceanbase.hbase.OHTableClient;
2121
import org.apache.hadoop.conf.Configuration;
22+
import org.apache.hadoop.hbase.Cell;
23+
import org.apache.hadoop.hbase.CellUtil;
2224
import org.apache.hadoop.hbase.client.Get;
2325
import org.apache.hadoop.hbase.client.Put;
2426
import org.apache.hadoop.hbase.client.Result;
@@ -49,7 +51,7 @@ public static void simpleTest() throws Exception {
4951
byte[] rowKey = toBytes("rowKey1");
5052
byte[] column = toBytes("column1");
5153
Put put = new Put(rowKey);
52-
put.add(family, column, System.currentTimeMillis(), toBytes("value1"));
54+
put.addColumn(family, column, System.currentTimeMillis(), toBytes("value1"));
5355
hTable.put(put);
5456

5557
// 3. get data like hbase
@@ -58,7 +60,7 @@ public static void simpleTest() throws Exception {
5860
Result r = hTable.get(get);
5961
if (!r.isEmpty()) {
6062
Cell cell = r.rawCells()[0];
61-
System.out.printf("column1: " + CellUtil.cloneQualifier(r));
63+
System.out.printf("column1: " + CellUtil.cloneQualifier(cell));
6264
}
6365

6466
// 4. close

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<project.build.sourceEncoding>${project.encoding}</project.build.sourceEncoding>
5555
<project.encoding>UTF-8</project.encoding>
5656
<slf4j.version>1.7.21</slf4j.version>
57-
<table.client.version>2.0.0</table.client.version>
57+
<table.client.version>2.0.1-SNAPSHOT</table.client.version>
5858
</properties>
5959

6060
<dependencies>
@@ -167,6 +167,10 @@
167167
<artifactId>jersey-json</artifactId>
168168
<groupId>com.sun.jersey</groupId>
169169
</exclusion>
170+
<exclusion>
171+
<artifactId>jackson-databind</artifactId>
172+
<groupId>com.fasterxml.jackson.core</groupId>
173+
</exclusion>
170174
</exclusions>
171175
</dependency>
172176
<dependency>

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ public OHTable(Configuration configuration, String tableName) throws IOException
220220
DEFAULT_HBASE_HTABLE_THREAD_KEEP_ALIVE_TIME);
221221
this.executePool = createDefaultThreadPoolExecutor(1, maxThreads, keepAliveTime);
222222
OHConnectionConfiguration ohConnectionConf = new OHConnectionConfiguration(configuration);
223-
int numRetries = configuration.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
224-
HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
223+
int numRetries = ohConnectionConf.getNumRetries();
225224
this.obTableClient = ObTableClientManager.getOrCreateObTableClient(setUserDefinedNamespace(
226225
this.tableNameString, ohConnectionConf));
227226
this.obTableClient.setRpcExecuteTimeout(ohConnectionConf.getRpcTimeout());
@@ -273,8 +272,7 @@ public OHTable(Configuration configuration, final byte[] tableName,
273272
this.executePool = executePool;
274273
this.cleanupPoolOnClose = false;
275274
OHConnectionConfiguration ohConnectionConf = new OHConnectionConfiguration(configuration);
276-
int numRetries = configuration.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
277-
HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
275+
int numRetries = ohConnectionConf.getNumRetries();
278276
this.obTableClient = ObTableClientManager.getOrCreateObTableClient(setUserDefinedNamespace(
279277
this.tableNameString, ohConnectionConf));
280278
this.obTableClient.setRpcExecuteTimeout(ohConnectionConf.getRpcTimeout());
@@ -345,8 +343,7 @@ public OHTable(TableName tableName, Connection connection,
345343
DEFAULT_HBASE_HTABLE_PUT_WRITE_BUFFER_CHECK);
346344
this.writeBufferSize = connectionConfig.getWriteBufferSize();
347345
this.tableName = tableName.getName();
348-
int numRetries = configuration.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
349-
HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
346+
int numRetries = connectionConfig.getNumRetries();
350347
this.obTableClient = ObTableClientManager.getOrCreateObTableClient(setUserDefinedNamespace(
351348
this.tableNameString, connectionConfig));
352349
this.obTableClient.setRpcExecuteTimeout(rpcTimeout);
@@ -389,8 +386,7 @@ public OHTable(Connection connection, ObTableBuilderBase builder,
389386
this.putWriteBufferCheck = this.configuration.getInt(HBASE_HTABLE_PUT_WRITE_BUFFER_CHECK,
390387
DEFAULT_HBASE_HTABLE_PUT_WRITE_BUFFER_CHECK);
391388
this.writeBufferSize = connectionConfig.getWriteBufferSize();
392-
int numRetries = configuration.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
393-
HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
389+
int numRetries = connectionConfig.getNumRetries();
394390
this.obTableClient = ObTableClientManager.getOrCreateObTableClient(setUserDefinedNamespace(
395391
this.tableNameString, connectionConfig));
396392
this.obTableClient.setRpcExecuteTimeout(rpcTimeout);
@@ -462,7 +458,7 @@ private void finishSetUp() {
462458
WRITE_BUFFER_SIZE_DEFAULT);
463459
}
464460

465-
private OHConnectionConfiguration setUserDefinedNamespace(String tableNameString,
461+
public static OHConnectionConfiguration setUserDefinedNamespace(String tableNameString,
466462
OHConnectionConfiguration ohConnectionConf)
467463
throws IllegalArgumentException {
468464
if (tableNameString.indexOf(':') != -1) {
@@ -503,13 +499,15 @@ public Configuration getConfiguration() {
503499
}
504500

505501
@Override
506-
public HTableDescriptor getTableDescriptor() {
507-
throw new FeatureNotSupportedException("not supported yet.");
502+
public HTableDescriptor getTableDescriptor() throws IOException {
503+
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableNameString, obTableClient);
504+
return executor.getTableDescriptor();
508505
}
509506

510507
@Override
511508
public TableDescriptor getDescriptor() throws IOException {
512-
throw new FeatureNotSupportedException("not supported yet.");
509+
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableNameString, obTableClient);
510+
return executor.getTableDescriptor();
513511
}
514512

515513
/**
@@ -1950,6 +1948,8 @@ private ObTableQuery buildObTableQuery(ObHTableFilter filter, final Scan scan) {
19501948
HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE));
19511949
obTableQuery.setObKVParams(buildOBKVParams(scan));
19521950
obTableQuery.setScanRangeColumns("K", "Q", "T");
1951+
byte[] hotOnly = scan.getAttribute(HBASE_HTABLE_QUERY_HOT_ONLY);
1952+
obTableQuery.setHotOnly(hotOnly != null && Arrays.equals(hotOnly, "true".getBytes()));
19531953
return obTableQuery;
19541954
}
19551955

@@ -1967,6 +1967,8 @@ private ObTableQuery buildObTableQuery(final Get get, Collection<byte[]> columnQ
19671967
}
19681968
obTableQuery.setObKVParams(buildOBKVParams(get));
19691969
obTableQuery.setScanRangeColumns("K", "Q", "T");
1970+
byte[] hotOnly = get.getAttribute(HBASE_HTABLE_QUERY_HOT_ONLY);
1971+
obTableQuery.setHotOnly(hotOnly != null && Arrays.equals(hotOnly, "true".getBytes()));
19701972
return obTableQuery;
19711973
}
19721974

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ public HTableDescriptor getTableDescriptor() throws IOException {
223223

224224
@Override
225225
public TableDescriptor getDescriptor() throws IOException {
226-
return null;
226+
checkStatus();
227+
return ohTable.getDescriptor();
227228
}
228229

229230
@Override

src/main/java/com/alipay/oceanbase/hbase/constants/OHConstants.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
public final class OHConstants {
2424

2525
/**
26-
* ocenbase hbase root server http url
26+
* oceanbase hbase root server http url
2727
*/
2828
public static final String HBASE_OCEANBASE_PARAM_URL = "hbase.oceanbase.paramURL";
2929

3030
/**
31-
* ocenbase hbase connect server username
31+
* oceanbase hbase connect server username
3232
*/
3333
public static final String HBASE_OCEANBASE_FULL_USER_NAME = "hbase.oceanbase.fullUserName";
3434

3535
/**
36-
* ocenbase hbase connect server password
36+
* oceanbase hbase connect server password
3737
*/
3838
public static final String HBASE_OCEANBASE_PASSWORD = "hbase.oceanbase.password";
3939

@@ -48,39 +48,39 @@ public final class OHConstants {
4848
public static final String HBASE_OCEANBASE_SYS_PASSWORD = "hbase.oceanbase.sysPassword";
4949

5050
/**
51-
* ocenbase hbase connect server password
51+
* oceanbase hbase connect server password
5252
*/
5353
public static final String HBASE_OCEANBASE_BATCH_EXECUTOR = "hbase.oceanbase.batch.executor";
5454

5555
/**
56-
* ocenbase hbase connect server ODP address
56+
* oceanbase hbase connect server ODP address
5757
*/
5858
public static final String HBASE_OCEANBASE_ODP_ADDR = "hbase.oceanbase.odpAddr";
5959

6060
/**
61-
* ocenbase hbase connect server ODP port
61+
* oceanbase hbase connect server ODP port
6262
*/
6363
public static final String HBASE_OCEANBASE_ODP_PORT = "hbase.oceanbase.odpPort";
6464

6565
/**
66-
* ocenbase hbase connect server ODP mode
66+
* oceanbase hbase connect server ODP mode
6767
*/
6868
public static final String HBASE_OCEANBASE_ODP_MODE = "hbase.oceanbase.odpMode";
6969

7070
/**
71-
* ocenbase hbase connect server database
71+
* oceanbase hbase connect server database
7272
*/
7373
public static final String HBASE_OCEANBASE_DATABASE = "hbase.oceanbase.database";
7474

7575
/**
76-
* ocenbase hbase model rowkey column is consist of following column
76+
* oceanbase hbase model rowkey column is consist of following column
7777
* K, Q, T hbase value
7878
*/
7979
public static final String[] ROW_KEY_COLUMNS = new String[] { "K",
8080
"Q", "T" };
8181

8282
/**
83-
* ocenbase hbase model value column is consist of following column
83+
* oceanbase hbase model value column is consist of following column
8484
* V hbase value
8585
*/
8686
public static final String[] V_COLUMNS = new String[] { "V" };
@@ -124,6 +124,11 @@ public final class OHConstants {
124124
*/
125125
public static final String DEFAULT_HBASE_HTABLE_TEST_LOAD_SUFFIX = "_t";
126126

127+
/**
128+
* use to specify whether to query only the data in hot storage when performing a query.
129+
*/
130+
public static final String HBASE_HTABLE_QUERY_HOT_ONLY = "hbase.htable.query.hot_only";
131+
127132
/*-------------------------------------------------------------------------------------------------------------*/
128133

129134
/**
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-hbase-client
4+
* %%
5+
* Copyright (C) 2022 - 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase 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.hbase.execute;
19+
20+
import com.alipay.oceanbase.hbase.util.OHBaseExceptionUtil;
21+
import com.alipay.oceanbase.rpc.ObTableClient;
22+
import com.alipay.oceanbase.rpc.exception.ObTableException;
23+
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
24+
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
25+
import com.alipay.oceanbase.rpc.table.ObTable;
26+
27+
import java.io.IOException;
28+
29+
public abstract class AbstractObTableMetaExecutor<T> implements ObTableMetaExecutor<T> {
30+
31+
@Override
32+
public T execute(ObTableClient client, ObTableMetaRequest request) throws IOException {
33+
if (request.getMetaType() != getMetaType()) {
34+
throw new IOException("Invalid meta type, expected " + getMetaType());
35+
}
36+
ObTable table = client.getRandomTable();
37+
ObTableMetaResponse response;
38+
try {
39+
response = (ObTableMetaResponse) client.executeWithRetry(
40+
table,
41+
request,
42+
null /*tableName*/
43+
);
44+
} catch (Exception e) {
45+
throw OHBaseExceptionUtil.convertTableException(e);
46+
}
47+
return parse(response);
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*-
2+
* #%L
3+
* com.oceanbase:obkv-hbase-client
4+
* %%
5+
* Copyright (C) 2022 - 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase 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.hbase.execute;
19+
20+
import com.alipay.oceanbase.rpc.ObTableClient;
21+
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
22+
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
23+
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
24+
25+
import java.io.IOException;
26+
27+
public interface ObTableMetaExecutor<T> {
28+
/**
29+
* 执行元数据请求
30+
* @param request 元数据请求
31+
* @return 解析后的元数据对象
32+
* @throws IOException 如果执行失败或解析失败
33+
*/
34+
T execute(ObTableClient client, ObTableMetaRequest request) throws IOException;
35+
36+
/**
37+
* 解析元数据响应, 用户需要重写
38+
* @param response 元数据响应
39+
* @return 解析后的元数据对象
40+
* @throws IOException 如果解析失败
41+
*/
42+
T parse(ObTableMetaResponse response) throws IOException;
43+
44+
/**
45+
* 获取元信息类型, 用户需要重写
46+
* @return 元信息类型
47+
*/
48+
ObTableRpcMetaType getMetaType() throws IOException;
49+
}

0 commit comments

Comments
 (0)