Skip to content

Commit 535aa1e

Browse files
maochongxinshenyunlong
authored andcommitted
cherry pick hbase_compat3_2.0 commits to master; fix cases
1 parent 7f059d0 commit 535aa1e

25 files changed

+4010
-449
lines changed

pom.xml

Lines changed: 1 addition & 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
<dependencyManagement>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,9 @@ public Configuration getConfiguration() {
427427
}
428428

429429
@Override
430-
public HTableDescriptor getTableDescriptor() {
431-
throw new FeatureNotSupportedException("not supported yet.");
430+
public HTableDescriptor getTableDescriptor() throws IOException {
431+
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableNameString, obTableClient);
432+
return executor.getTableDescriptor();
432433
}
433434

434435
/**

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

Lines changed: 13 additions & 9 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,32 +48,32 @@ 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",
@@ -109,6 +109,10 @@ public final class OHConstants {
109109
*/
110110
public static final String HBASE_HTABLE_POOL_OPERATION_TIMEOUT = "hbase.htable.pool.operation.timeout";
111111

112+
/**
113+
* use to specify whether to query only the data in hot storage when performing a query.
114+
*/
115+
public static final String HBASE_HTABLE_QUERY_HOT_ONLY = "hbase.htable.query.hot_only";
112116
/**
113117
* internal attribute of ohtable pool which enable the test load
114118
*/

src/main/java/com/alipay/oceanbase/hbase/util/OHAdmin.java

Lines changed: 132 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import com.alipay.oceanbase.hbase.exception.FeatureNotSupportedException;
44
import com.alipay.oceanbase.rpc.ObTableClient;
55
import com.alipay.oceanbase.rpc.bolt.transport.TransportCodes;
6+
import com.alipay.oceanbase.rpc.exception.ObTableException;
67
import com.alipay.oceanbase.rpc.exception.ObTableTransportException;
8+
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
9+
import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes;
710
import org.apache.hadoop.conf.Configuration;
811
import org.apache.hadoop.hbase.*;
912
import org.apache.hadoop.hbase.client.Admin;
@@ -25,16 +28,18 @@
2528
import org.apache.hadoop.hbase.util.Pair;
2629

2730
import java.io.IOException;
31+
import java.util.ArrayList;
2832
import java.util.Collections;
2933
import java.util.List;
3034
import java.util.Map;
3135
import java.util.concurrent.Future;
3236
import java.util.regex.Pattern;
37+
import java.util.stream.Collectors;
3338

3439
public class OHAdmin implements Admin {
35-
private boolean aborted = false;
36-
private final OHConnectionImpl connection;
37-
private final Configuration conf;
40+
private boolean aborted = false;
41+
private final OHConnectionImpl connection;
42+
private final Configuration conf;
3843
OHAdmin(OHConnectionImpl connection) {
3944
this.connection = connection;
4045
this.conf = connection.getConfiguration();
@@ -64,10 +69,27 @@ public Connection getConnection() {
6469

6570
@Override
6671
public boolean tableExists(TableName tableName) throws IOException {
67-
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
68-
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
69-
OHTableExistsExecutor executor = new OHTableExistsExecutor(tableClient);
70-
return executor.tableExists(tableName.getNameAsString());
72+
try {
73+
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
74+
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
75+
OHTableExistsExecutor executor = new OHTableExistsExecutor(tableClient);
76+
return executor.tableExists(tableName.getNameAsString());
77+
} catch (Exception e) {
78+
// try to get the original cause
79+
Throwable cause = e.getCause();
80+
while(cause != null && cause.getCause() != null) {
81+
cause = cause.getCause();
82+
}
83+
if (cause instanceof ObTableException) {
84+
int errCode = ((ObTableException) cause).getErrorCode();
85+
// if the original cause is database_not_exist, means namespace in tableName does not exist
86+
// for HBase, namespace not exist will not throw exceptions but will return false
87+
if (errCode == ResultCodes.OB_ERR_BAD_DATABASE.errorCode) {
88+
return false;
89+
}
90+
}
91+
throw e;
92+
}
7193
}
7294

7395
@Override
@@ -122,16 +144,44 @@ public TableName[] listTableNames(String s, boolean b) throws IOException {
122144

123145
@Override
124146
public HTableDescriptor getTableDescriptor(TableName tableName) throws TableNotFoundException, IOException {
125-
throw new FeatureNotSupportedException("does not support yet");
147+
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
148+
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
149+
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableName.getNameAsString(), tableClient);
150+
try {
151+
return executor.getTableDescriptor();
152+
} catch (IOException e) {
153+
if (e.getCause() instanceof ObTableTransportException
154+
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
155+
throw new TimeoutIOException(e.getCause());
156+
} else if (e.getCause().getMessage().contains("OB_TABLEGROUP_NOT_EXIST")) {
157+
throw new TableNotFoundException(tableName);
158+
} else {
159+
throw e;
160+
}
161+
}
126162
}
127163

128164
@Override
129-
public void createTable(HTableDescriptor hTableDescriptor) throws IOException {
130-
throw new FeatureNotSupportedException("does not support yet");
165+
public void createTable(HTableDescriptor tableDescriptor) throws IOException {
166+
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
167+
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableDescriptor.getTableName(), connectionConf);
168+
OHCreateTableExecutor executor = new OHCreateTableExecutor(tableClient);
169+
try {
170+
executor.createTable(tableDescriptor, null);
171+
} catch (IOException e) {
172+
if (e.getCause() instanceof ObTableTransportException
173+
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
174+
throw new TimeoutIOException(e.getCause());
175+
} else if (e.getCause().getMessage().contains("already exist")) {
176+
throw new TableExistsException(e.getCause().getMessage());
177+
} else {
178+
throw e;
179+
}
180+
}
131181
}
132182

133183
@Override
134-
public void createTable(HTableDescriptor hTableDescriptor, byte[] bytes, byte[] bytes1, int i) throws IOException {
184+
public void createTable(HTableDescriptor tableDescriptor, byte[] bytes, byte[] bytes1, int i) throws IOException {
135185
throw new FeatureNotSupportedException("does not support yet");
136186
}
137187

@@ -156,8 +206,8 @@ public void deleteTable(TableName tableName) throws IOException {
156206
if (e.getCause() instanceof ObTableTransportException
157207
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
158208
throw new TimeoutIOException(e.getCause());
159-
} else {
160-
throw e;
209+
} else if (e.getCause().getMessage().contains("not found")) {
210+
throw new TableNotFoundException(tableName);
161211
}
162212
}
163213
}
@@ -179,7 +229,23 @@ public void truncateTable(TableName tableName, boolean b) throws IOException {
179229

180230
@Override
181231
public void enableTable(TableName tableName) throws IOException {
182-
throw new FeatureNotSupportedException("does not support yet");
232+
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
233+
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
234+
OHTableAccessControlExecutor executor = new OHTableAccessControlExecutor(tableClient, ObTableRpcMetaType.HTABLE_ENABLE_TABLE);
235+
try {
236+
executor.enableTable(tableName.getNameAsString());
237+
} catch (IOException e) {
238+
if (e.getCause() instanceof ObTableTransportException
239+
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
240+
throw new TimeoutIOException(e.getCause());
241+
} else if (e.getCause().getMessage().contains("not exist")) {
242+
throw new TableNotFoundException(tableName);
243+
} else if (e.getCause().getMessage().contains("not enabled")) {
244+
throw new TableNotDisabledException(e.getCause().getMessage());
245+
} else {
246+
throw e;
247+
}
248+
}
183249
}
184250

185251
@Override
@@ -204,7 +270,23 @@ public void disableTableAsync(TableName tableName) throws IOException {
204270

205271
@Override
206272
public void disableTable(TableName tableName) throws IOException {
207-
throw new FeatureNotSupportedException("does not support yet");
273+
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
274+
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
275+
OHTableAccessControlExecutor executor = new OHTableAccessControlExecutor(tableClient, ObTableRpcMetaType.HTABLE_DISABLE_TABLE);
276+
try {
277+
executor.disableTable(tableName.getNameAsString());
278+
} catch (IOException e) {
279+
if (e.getCause() instanceof ObTableTransportException
280+
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
281+
throw new TimeoutIOException(e.getCause());
282+
} else if (e.getCause().getMessage().contains("not exist")) {
283+
throw new TableNotFoundException(tableName);
284+
} else if (e.getCause().getMessage().contains("not disabled")) {
285+
throw new TableNotEnabledException(e.getCause().getMessage());
286+
} else {
287+
throw e;
288+
}
289+
}
208290
}
209291

210292
@Override
@@ -219,12 +301,19 @@ public HTableDescriptor[] disableTables(Pattern pattern) throws IOException {
219301

220302
@Override
221303
public boolean isTableEnabled(TableName tableName) throws IOException {
222-
throw new FeatureNotSupportedException("does not support yet");
304+
return !isDisabled(tableName);
223305
}
224306

225307
@Override
226308
public boolean isTableDisabled(TableName tableName) throws IOException {
227-
throw new FeatureNotSupportedException("does not support yet");
309+
return isDisabled(tableName);
310+
}
311+
312+
private boolean isDisabled(TableName tableName) throws IOException {
313+
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
314+
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
315+
OHTableDescriptorExecutor tableDescriptor = new OHTableDescriptorExecutor(tableName.getNameAsString(), tableClient);
316+
return tableDescriptor.isDisable();
228317
}
229318

230319
@Override
@@ -513,13 +602,35 @@ public synchronized void close() throws IOException {
513602
}
514603

515604
@Override
516-
public HTableDescriptor[] getTableDescriptorsByTableName(List<TableName> list) throws IOException {
517-
throw new FeatureNotSupportedException("does not support yet");
605+
public HTableDescriptor[] getTableDescriptorsByTableName(List<TableName> tableNames) throws IOException {
606+
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
607+
List<HTableDescriptor> tableDescriptors = new ArrayList<>();
608+
for (TableName tableName : tableNames) {
609+
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
610+
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableName.getNameAsString(), tableClient);
611+
try {
612+
tableDescriptors.add(executor.getTableDescriptor());
613+
} catch (IOException e) {
614+
if (e.getCause() instanceof ObTableTransportException
615+
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
616+
throw new TimeoutIOException(e.getCause());
617+
} else if (e.getCause().getMessage().contains("OB_TABLEGROUP_NOT_EXIST")) {
618+
throw new TableNotFoundException(tableName);
619+
} else {
620+
throw e;
621+
}
622+
}
623+
}
624+
return tableDescriptors.toArray(new HTableDescriptor[0]);
518625
}
519626

520627
@Override
521-
public HTableDescriptor[] getTableDescriptors(List<String> list) throws IOException {
522-
throw new FeatureNotSupportedException("does not support yet");
628+
public HTableDescriptor[] getTableDescriptors(List<String> tableNames) throws IOException {
629+
List<TableName> tableNameList = new ArrayList<>();
630+
for (String tableName : tableNames) {
631+
tableNameList.add(TableName.valueOf(tableName));
632+
}
633+
return getTableDescriptorsByTableName(tableNameList);
523634
}
524635

525636
@Override
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*-
2+
* #%L
3+
* OBKV HBase Client Framework
4+
* %%
5+
* Copyright (C) 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.util;
19+
20+
import com.alipay.oceanbase.rpc.exception.ObTableException;
21+
import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes;
22+
import org.apache.hadoop.hbase.*;
23+
24+
import java.io.IOException;
25+
26+
public class OHBaseExceptionUtil {
27+
public static IOException convertTableException(Exception e) {
28+
if (e instanceof ObTableException) {
29+
final int errCode = ((ObTableException) e).getErrorCode();
30+
if (errCode == ResultCodes.OB_KV_HBASE_TABLE_NOT_EXISTS.errorCode) {
31+
return (TableNotFoundException) new TableNotFoundException(e.getMessage()).initCause(e);
32+
} else if (errCode == ResultCodes.OB_KV_HBASE_TABLE_EXISTS.errorCode) {
33+
return (TableExistsException) new TableExistsException(e.getMessage()).initCause(e);
34+
} else if (errCode == ResultCodes.OB_KV_HBASE_NAMESPACE_NOT_FOUND.errorCode) {
35+
return (NamespaceNotFoundException) new NamespaceNotFoundException(e.getMessage()).initCause(e);
36+
} else if (errCode == ResultCodes.OB_KV_TABLE_NOT_ENABLED.errorCode) {
37+
return (TableNotEnabledException) new TableNotEnabledException(e.getMessage()).initCause(e);
38+
} else if (errCode == ResultCodes.OB_KV_TABLE_NOT_DISABLED.errorCode) {
39+
return (TableNotDisabledException) new TableNotDisabledException(e.getMessage()).initCause(e);
40+
}
41+
}
42+
return new IOException("Failed to execute request", e);
43+
}
44+
}

src/main/java/com/alipay/oceanbase/hbase/util/OHConnectionImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,11 @@ public BufferedMutator getBufferedMutator(BufferedMutatorParams params, OHTable
148148
}
149149

150150
@Override
151-
public RegionLocator getRegionLocator(TableName tableName) throws IOException {
152-
// need to use new connection configuration
151+
public RegionLocator getRegionLocator(TableName tableName) throws IOException { // need to use new connection configuration
153152
// to avoid change the database in original param url by namespace in tableName
154153
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
155154
ObTableClient obTableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
156-
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(obTableClient);
155+
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(tableName.toString(), obTableClient);
157156
return executor.getRegionLocator(String.valueOf(tableName));
158157
}
159158

0 commit comments

Comments
 (0)