Skip to content

Align obkv-hbase enable/disable exception handling with HBase #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: hbase_compat_3_2.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.alibaba.fastjson.JSON;
import com.alipay.oceanbase.hbase.execute.AbstractObTableMetaExecutor;
import com.alipay.oceanbase.rpc.ObTableClient;
import com.alipay.oceanbase.rpc.exception.ObTableException;
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes;
import org.apache.hadoop.hbase.TableNotDisabledException;
import org.apache.hadoop.hbase.TableNotEnabledException;
import org.apache.hadoop.hbase.TableNotFoundException;
Expand Down Expand Up @@ -33,23 +35,51 @@ public Void parse(ObTableMetaResponse response) throws IOException {
return null;
}

public void enableTable(String tableName) throws IOException, TableNotFoundException, TableNotEnabledException {
public Void enableTable(String tableName) throws IOException, TableNotFoundException, TableNotEnabledException {
ObTableMetaRequest request = new ObTableMetaRequest();
request.setMetaType(getMetaType());
Map<String, Object> requestData = new HashMap<>();
requestData.put("table_name", tableName);
String jsonData = JSON.toJSONString(requestData);
request.setData(jsonData);
execute(tableClient, request);
try {
return execute(tableClient, request);
} catch (IOException e) {
Throwable cause = e.getCause();
if (cause instanceof ObTableException) {
ObTableException obEx = (ObTableException) cause;
int errCode = obEx.getErrorCode();
if(ResultCodes.OB_KV_TABLE_NOT_ENABLED.errorCode == errCode) {
throw new TableNotEnabledException("Table is not enabled: " + tableName + obEx);
} else if (ResultCodes.OB_TABLEGROUP_NOT_EXIST.errorCode == errCode) {
throw new TableNotFoundException("Table not found: " + tableName + obEx);
}
}
throw e;
}
}

public void disableTable(String tableName) throws IOException, TableNotFoundException, TableNotDisabledException {
public Void disableTable(String tableName) throws IOException, TableNotFoundException, TableNotDisabledException {
ObTableMetaRequest request = new ObTableMetaRequest();
request.setMetaType(getMetaType());
Map<String, Object> requestData = new HashMap<>();
requestData.put("table_name", tableName);
String jsonData = JSON.toJSONString(requestData);
request.setData(jsonData);
execute(tableClient, request);
try {
return execute(tableClient, request);
} catch (IOException e) {
Throwable cause = e.getCause();
if (cause instanceof ObTableException) {
ObTableException obEx = (ObTableException) cause;
int errCode = obEx.getErrorCode();
if(ResultCodes.OB_KV_TABLE_NOT_DISABLED.errorCode == errCode) {
throw new TableNotDisabledException("Table is not disabled: " + tableName + obEx);
} else if (ResultCodes.OB_TABLEGROUP_NOT_EXIST.errorCode == errCode) {
throw new TableNotFoundException("Table not found: " + tableName + obEx);
}
}
throw e;
}
}
}