Skip to content

Commit f234813

Browse files
committed
Align obkv-hbase enable/disable exception handling with HBase
fix syntax errors Align obkv-hbase enable/disable exception handling with HBase
1 parent 976f008 commit f234813

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.alibaba.fastjson.JSON;
44
import com.alipay.oceanbase.hbase.execute.AbstractObTableMetaExecutor;
5+
import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes;
56
import com.alipay.oceanbase.rpc.ObTableClient;
7+
import com.alipay.oceanbase.rpc.exception.ObTableException;
68
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
79
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
810
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
@@ -40,7 +42,21 @@ public Void enableTable(String tableName) throws IOException, TableNotFoundExcep
4042
requestData.put("table_name", tableName);
4143
String jsonData = JSON.toJSONString(requestData);
4244
request.setData(jsonData);
43-
return execute(tableClient, request);
45+
try {
46+
return execute(tableClient, request);
47+
} catch (IOException e) {
48+
Throwable cause = e.getCause();
49+
if (cause instanceof ObTableException) {
50+
ObTableException obEx = (ObTableException) cause;
51+
int errCode = obEx.getErrorCode();
52+
if(ResultCodes.OB_KV_TABLE_NOT_ENABLED.errorCode == errCode) {
53+
throw new TableNotEnabledException("Table is not enabled: " + tableName + obEx);
54+
} else if (ResultCodes.OB_TABLEGROUP_NOT_EXIST.errorCode == errCode) {
55+
throw new TableNotFoundException("Table not found: " + tableName + obEx);
56+
}
57+
}
58+
throw e;
59+
}
4460
}
4561

4662
public Void disableTable(String tableName) throws IOException, TableNotFoundException, TableNotDisabledException {
@@ -50,6 +66,20 @@ public Void disableTable(String tableName) throws IOException, TableNotFoundExce
5066
requestData.put("table_name", tableName);
5167
String jsonData = JSON.toJSONString(requestData);
5268
request.setData(jsonData);
53-
return execute(tableClient, request);
69+
try {
70+
return execute(tableClient, request);
71+
} catch (IOException e) {
72+
Throwable cause = e.getCause();
73+
if (cause instanceof ObTableException) {
74+
ObTableException obEx = (ObTableException) cause;
75+
int errCode = obEx.getErrorCode();
76+
if(ResultCodes.OB_KV_TABLE_NOT_DISABLED.errorCode == errCode) {
77+
throw new TableNotDisabledException("Table is not disabled: " + tableName + obEx);
78+
} else if (ResultCodes.OB_TABLEGROUP_NOT_EXIST.errorCode == errCode) {
79+
throw new TableNotFoundException("Table not found: " + tableName + obEx);
80+
}
81+
}
82+
throw e;
83+
}
5484
}
5585
}

src/test/java/com/alipay/oceanbase/hbase/OHTableAdminInterfaceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public void testAdminEnDisableTable() throws Exception {
355355
// enable an enabled table
356356
thrown = assertThrows(IOException.class,
357357
() -> {
358-
admin.disableTable(TableName.valueOf("n1", "test");
358+
admin.disableTable(TableName.valueOf("n1", "test"));
359359
});
360360
assertTrue(thrown.getCause() instanceof ObTableException);
361361
Assert.assertEquals(ResultCodes.OB_KV_TABLE_NOT_ENABLED.errorCode, ((ObTableException) thrown.getCause()).getErrorCode());

0 commit comments

Comments
 (0)