Skip to content

Commit 3c9e9fc

Browse files
committed
fix namespace not exsit
1 parent 53f8550 commit 3c9e9fc

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import com.alipay.oceanbase.rpc.ObTableClient;
44
import com.alipay.oceanbase.rpc.bolt.transport.TransportCodes;
55
import com.alipay.oceanbase.hbase.exception.FeatureNotSupportedException;
6+
import com.alipay.oceanbase.rpc.exception.ObTableException;
67
import com.alipay.oceanbase.rpc.exception.ObTableTransportException;
78
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
9+
import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes;
810
import org.apache.hadoop.conf.Configuration;
911
import org.apache.hadoop.hbase.*;
1012
import org.apache.hadoop.hbase.client.*;
@@ -63,10 +65,27 @@ public Connection getConnection() {
6365

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

7291
@Override

0 commit comments

Comments
 (0)