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
29 changes: 19 additions & 10 deletions src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,8 @@ private String refreshTableNameByTableGroup(String physicalTableName, String tab
"failed to get table name key=%s original tableName=%s ", tableEntryKey,
physicalTableName), e);
}
if (!TableGroupInverted.isEmpty() && TableGroupInverted.containsKey(oldTableName)) {
if (!TableGroupInverted.isEmpty() && oldTableName != null
&& TableGroupInverted.containsKey(oldTableName)) {
TableGroupInverted.remove(oldTableName, tableGroupName);
}
TableGroupCache.put(tableGroupName, physicalTableName);
Expand Down Expand Up @@ -2731,22 +2732,16 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
} else if (request instanceof ObTableQueryRequest) {
// TableGroup -> TableName
String tableName = request.getTableName();
if (((ObTableQueryRequest) request).getTableQuery().isHbaseQuery()
&& isTableGroupName(tableName)) {
tableName = tryGetTableNameFromTableGroupCache(tableName, false);
}
tableName = getPhyTableNameFromTableGroup(((ObTableQueryRequest) request), tableName);
ObTableClientQueryImpl tableQuery = new ObTableClientQueryImpl(tableName,
((ObTableQueryRequest) request).getTableQuery(), this);
tableQuery.setEntityType(request.getEntityType());
return new ObClusterTableQuery(tableQuery).executeInternal();
} else if (request instanceof ObTableQueryAsyncRequest) {
// TableGroup -> TableName
String tableName = request.getTableName();
if (((ObTableQueryAsyncRequest) request).getObTableQueryRequest().getTableQuery()
.isHbaseQuery()
&& isTableGroupName(tableName)) {
tableName = tryGetTableNameFromTableGroupCache(tableName, false);
}
tableName = getPhyTableNameFromTableGroup(
((ObTableQueryAsyncRequest) request).getObTableQueryRequest(), tableName);
ObTableClientQueryImpl tableQuery = new ObTableClientQueryImpl(tableName,
((ObTableQueryAsyncRequest) request).getObTableQueryRequest().getTableQuery(), this);
tableQuery.setEntityType(request.getEntityType());
Expand Down Expand Up @@ -3282,4 +3277,18 @@ public boolean isTableGroupName(String tabName) {
return !tabName.contains("$");
}

/*
* get phy table name form table group
* if odp mode then do nothing
*/
public String getPhyTableNameFromTableGroup(ObTableQueryRequest request, String tableName)
throws Exception {
if (odpMode) {
// do nothing
} else if (request.getTableQuery().isHbaseQuery() && isTableGroupName(tableName)) {
tableName = tryGetTableNameFromTableGroupCache(tableName, false);
}
return tableName;
}

}
24 changes: 12 additions & 12 deletions src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public class LocationUtil {
private static final int TEMPLATE_PART_ID = -1;

// limit the size of get tableEntry location from remote each time
private static final int MAX_TABLET_NUMS_EPOCH = 300;
private static final int MAX_TABLET_NUMS_EPOCH = 300;

private abstract static class TableEntryRefreshWithPriorityCallback<T> {
abstract T execute(ObServerAddr obServerAddr) throws ObTableEntryRefreshException;
Expand Down Expand Up @@ -715,15 +715,16 @@ private static String genLocationSQLByOffset(TableEntry tableEntry, int offset,
long endOffset = -1;
long allPartNum = tableEntry.getPartitionNum();
if (offset < 0 || offset >= allPartNum || size < 0) {
throw new IllegalArgumentException("Illegal arguement: offset: "+offset+", size: "+size);
throw new IllegalArgumentException("Illegal arguement: offset: " + offset + ", size: "
+ size);
} else {
endOffset = Math.min(offset + size, allPartNum);
}

if (ObGlobal.obVsnMajor() >= 4) {
if (tableEntry.isPartitionTable()) {
Map<Long, Long> partTabletIdMap = tableEntry.getPartitionInfo()
.getPartTabletIdMap();
.getPartTabletIdMap();
Long[] tabletIds = partTabletIdMap.values().toArray(new Long[0]);
for (int i = offset; i < endOffset; i++) {
if (i > offset) {
Expand All @@ -742,7 +743,7 @@ private static String genLocationSQLByOffset(TableEntry tableEntry, int offset,
sql = MessageFormat.format(PROXY_LOCATION_SQL_PARTITION_V4, sb.toString());
} else {
if (tableEntry.isPartitionTable()
&& null != tableEntry.getPartitionInfo().getSubPartDesc()) {
&& null != tableEntry.getPartitionInfo().getSubPartDesc()) {
long subPartNum = tableEntry.getPartitionInfo().getSubPartDesc().getPartNum();
for (long i = offset; i < endOffset; ++i) {
if (i > offset) {
Expand Down Expand Up @@ -790,11 +791,9 @@ public static TableEntry getTableEntryLocationFromRemote(Connection connection,
partitionEntry = getPartitionLocationFromResultSet(tableEntry, rs, partitionEntry);
} catch (Exception e) {
RUNTIME.error(LCD.convert("01-00010"), key, partitionNum, tableEntry, e);
throw new ObTablePartitionLocationRefreshException(
format(
"fail to get partition location entry from remote entryKey = %s partNum = %d tableEntry =%s " +
"offset =%d epoch =%d",
key, partitionNum, tableEntry, i, epoch), e);
throw new ObTablePartitionLocationRefreshException(format(
"fail to get partition location entry from remote entryKey = %s partNum = %d tableEntry =%s "
+ "offset =%d epoch =%d", key, partitionNum, tableEntry, i, epoch), e);
} finally {
try {
if (null != rs) {
Expand Down Expand Up @@ -1069,10 +1068,11 @@ private static TableEntry getTableEntryFromResultSet(TableEntryKey key, ResultSe
private static ObPartitionEntry getPartitionLocationFromResultSet(TableEntry tableEntry,
ResultSet rs,
ObPartitionEntry partitionEntry)
throws SQLException,
ObTablePartitionLocationRefreshException {
throws SQLException,
ObTablePartitionLocationRefreshException {
if (partitionEntry == null || tableEntry == null) {
throw new IllegalArgumentException("partitionEntry: " + partitionEntry + " tableEntry: "+tableEntry);
throw new IllegalArgumentException("partitionEntry: " + partitionEntry
+ " tableEntry: " + tableEntry);
}
Map<Long, ObPartitionLocation> partitionLocation = partitionEntry.getPartitionLocation();
Map<Long, Long> tabletLsIdMap = partitionEntry.getTabletLsIdMap();
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/com/alipay/oceanbase/rpc/hbase/ObHTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,47 @@ PRIMARY KEY (`K`, `Q`, `T`)

}

@Test
public void hbaseDiffTableGroupTest() throws Exception {
/*
CREATE TABLEGROUP test SHARDING = 'ADAPTIVE';
CREATE TABLE `test$family1` (
`K` varbinary(1024) NOT NULL,
`Q` varbinary(256) NOT NULL,
`T` bigint(20) NOT NULL,
`V` varbinary(1024) DEFAULT NULL,
PRIMARY KEY (`K`, `Q`, `T`)
) TABLEGROUP = test;
CREATE TABLEGROUP test2 SHARDING = 'ADAPTIVE';
CREATE TABLE `test2$family1` (
`K` varbinary(1024) NOT NULL,
`Q` varbinary(256) NOT NULL,
`T` bigint(20) NOT NULL,
`V` varbinary(1024) DEFAULT NULL,
PRIMARY KEY (`K`, `Q`, `T`)
) TABLEGROUP = test2;
*/
byte[] family = new byte[] {};
ObHTableOperationRequest hTableOperationRequestGet = new ObHTableOperationRequest();
hTableOperationRequestGet.setOperationType(ObTableOperationType.GET);
hTableOperationRequestGet.setTableName("test");
hTableOperationRequestGet.setRowKey("putKey".getBytes());

ObTableQueryRequest requestGet = (ObTableQueryRequest) hTableOperationRequestGet
.obTableGroupOperationRequest();
ObTableClientQueryStreamResult clientQueryStreamResultGet = (ObTableClientQueryStreamResult) obTableClient
.execute(requestGet);

// Thread.currentThread().sleep(30000);
ObHTableOperationRequest hTableOperationRequestScan = new ObHTableOperationRequest();
hTableOperationRequestScan.setOperationType(ObTableOperationType.SCAN);
hTableOperationRequestScan.setTableName("test2");
hTableOperationRequestScan.setRowKey("putKey".getBytes());

ObTableQueryRequest requestScan = (ObTableQueryRequest) hTableOperationRequestScan
.obTableGroupOperationRequest();
ObTableClientQueryStreamResult clientQueryStreamResultScan = (ObTableClientQueryStreamResult) obTableClient
.execute(requestScan);
}

}