Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions src/main/java/com/alipay/oceanbase/hbase/OHTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,15 @@ public Configuration getConfiguration() {
}

@Override
public HTableDescriptor getTableDescriptor() {
throw new FeatureNotSupportedException("not supported yet.");
public HTableDescriptor getTableDescriptor() throws IOException {
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableNameString, obTableClient);
return executor.getTableDescriptor();
}

@Override
public TableDescriptor getDescriptor() throws IOException {
throw new FeatureNotSupportedException("not supported yet.");
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableNameString, obTableClient);
return executor.getTableDescriptor();
}

/**
Expand Down
42 changes: 39 additions & 3 deletions src/main/java/com/alipay/oceanbase/hbase/util/OHAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,53 @@ public TableName[] listTableNames(String s, boolean b) throws IOException {

@Override
public HTableDescriptor getTableDescriptor(TableName tableName) throws TableNotFoundException, IOException {
throw new FeatureNotSupportedException("does not support yet");
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableName.getNameAsString(), tableClient);
try {
return executor.getTableDescriptor();
} catch (IOException e) {
if (e.getCause() instanceof ObTableTransportException
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
throw new TimeoutIOException(e.getCause());
} else {
throw e;
}
}
}

@Override
public TableDescriptor getDescriptor(TableName tableName) throws TableNotFoundException, IOException {
throw new FeatureNotSupportedException("does not support yet");
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
OHTableDescriptorExecutor executor = new OHTableDescriptorExecutor(tableName.getNameAsString(), tableClient);
try {
return executor.getTableDescriptor();
} catch (IOException e) {
if (e.getCause() instanceof ObTableTransportException
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
throw new TimeoutIOException(e.getCause());
} else {
throw e;
}
}
}

@Override
public void createTable(TableDescriptor tableDescriptor) throws IOException {
throw new FeatureNotSupportedException("does not support yet");
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
ObTableClient tableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableDescriptor.getTableName(), connectionConf);
OHCreateTableExecutor executor = new OHCreateTableExecutor(tableClient);
try {
executor.createTable(tableDescriptor, null);
} catch (IOException e) {
if (e.getCause() instanceof ObTableTransportException
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
throw new TimeoutIOException(e.getCause());
} else {
throw e;
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public RegionLocator getRegionLocator(TableName tableName) throws IOException {
// to avoid change the database in original param url by namespace in tableName
OHConnectionConfiguration connectionConf = new OHConnectionConfiguration(conf);
ObTableClient obTableClient = ObTableClientManager.getOrCreateObTableClientByTableName(tableName, connectionConf);
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(obTableClient);
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(tableName.toString(), obTableClient);
return executor.getRegionLocator(String.valueOf(tableName));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*-
* #%L
* OBKV HBase Client Framework
* %%
* Copyright (C) 2025 OceanBase Group
* %%
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* #L%
*/

package com.alipay.oceanbase.hbase.util;

import com.alibaba.fastjson.JSON;
import com.alipay.oceanbase.hbase.execute.AbstractObTableMetaExecutor;
import com.alipay.oceanbase.rpc.ObTableClient;
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptor;

import java.io.IOException;
import java.util.*;

public class OHCreateTableExecutor extends AbstractObTableMetaExecutor<Void> {
private final ObTableClient client;

OHCreateTableExecutor(ObTableClient client) {
this.client = client;
}

@Override
public ObTableRpcMetaType getMetaType() {
return ObTableRpcMetaType.HTABLE_CREATE_TABLE;
}

@Override
public Void parse(ObTableMetaResponse response) throws IOException {
// success, do nothing
return null;
}

public void createTable(TableDescriptor tableDescriptor, byte[][] splitKeys) throws IOException {
final ObTableMetaRequest request = new ObTableMetaRequest();
request.setMetaType(getMetaType());
Map<String, Object> requestData = new HashMap<>();
requestData.put("htable_name", tableDescriptor.getTableName().getName());
Map<String, Map<String, Integer>> columnFamilies = new HashMap<>();
for (ColumnFamilyDescriptor columnDescriptor : tableDescriptor.getColumnFamilies()) {
Map<String, Integer> columnFamily = new HashMap<>();
columnFamily.put("ttl", columnDescriptor.getTimeToLive());
columnFamily.put("max_version", columnDescriptor.getMaxVersions());
columnFamilies.put(columnDescriptor.getNameAsString(), columnFamily);
}
requestData.put("column_families", columnFamilies);
String jsonData = JSON.toJSONString(requestData);
request.setData(jsonData);
execute(client, request);
}
}
51 changes: 42 additions & 9 deletions src/main/java/com/alipay/oceanbase/hbase/util/OHRegionLocator.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,66 @@
package com.alipay.oceanbase.hbase.util;

import com.alipay.oceanbase.rpc.ObTableClient;
import com.alipay.oceanbase.rpc.bolt.transport.TransportCodes;
import com.alipay.oceanbase.rpc.exception.ObTableTransportException;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.exceptions.TimeoutIOException;
import org.apache.hadoop.hbase.util.Pair;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

public class OHRegionLocator implements RegionLocator {
public OHRegionLocator(byte[][] startKeys, byte[][] endKeys) {

private byte[][] startKeys;
private byte[][] endKeys;
private TableName tableName;

private List<HRegionLocation> regionLocations;

public OHRegionLocator(byte[][] startKeys, byte[][] endKeys, List<HRegionLocation> regionLocations) {
this.startKeys = startKeys;
this.endKeys = endKeys;
this.regionLocations = regionLocations;
}

@Override
public HRegionLocation getRegionLocation(byte[] bytes) throws IOException {
// check if bytes is in the range of startKeys and endKeys
for (HRegionLocation regionLocation : regionLocations) {
if (regionLocation.getRegionInfo().containsRow(bytes)) {
return regionLocation;
}
}
return null;
}

@Override
public HRegionLocation getRegionLocation(byte[] bytes, boolean b) throws IOException {
return null;
if (b) {
OHRegionLocatorExecutor executor = new OHRegionLocatorExecutor(tableName.toString(), tableClient);
try {
RegionLocator location = executor.getRegionLocator(tableName.toString());
this.startKeys = location.getStartKeys();
this.endKeys = location.getEndKeys();
this.regionLocations = location.getAllRegionLocations();
} catch (IOException e) {
if (e.getCause() instanceof ObTableTransportException
&& ((ObTableTransportException) e.getCause()).getErrorCode() == TransportCodes.BOLT_TIMEOUT) {
throw new TimeoutIOException(e.getCause());
} else {
throw e;
}
}
}
return getRegionLocation(bytes);
}

@Override
public List<HRegionLocation> getAllRegionLocations() throws IOException {
return Collections.emptyList();
return regionLocations;
}

/**
Expand All @@ -40,7 +73,7 @@ public List<HRegionLocation> getAllRegionLocations() throws IOException {
*/
@Override
public byte[][] getStartKeys() throws IOException {
return null;
return startKeys;
}

/**
Expand All @@ -53,7 +86,7 @@ public byte[][] getStartKeys() throws IOException {
*/
@Override
public byte[][] getEndKeys() throws IOException {
return null;
return endKeys;
}

/**
Expand All @@ -67,18 +100,18 @@ public byte[][] getEndKeys() throws IOException {
*/
@Override
public Pair<byte[][], byte[][]> getStartEndKeys() throws IOException {
return null;
return Pair.newPair(startKeys, endKeys);
}

@Override
public TableName getName() {
return null;
return tableName;
}

private ObTableClient tableClient;

@Override
public void close() throws IOException {

return;
}
}
Loading