Skip to content

cherry-pick mr #258 #265

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_2.0.0-alpha4
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

import com.alipay.oceanbase.hbase.execute.AbstractObTableMetaExecutor;
import com.alipay.oceanbase.rpc.ObTableClient;
import com.alipay.oceanbase.rpc.exception.ObTableUnexpectedException;
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.RegionLoad;

import java.io.IOException;
Expand Down Expand Up @@ -54,22 +56,29 @@ public Map<byte[], RegionLoad> parse(ObTableMetaResponse response) throws IOExce
JsonNode tableGroupNameNode = Optional.<JsonNode>ofNullable(jsonMap.get("tableName"))
.orElseThrow(() -> new IOException("tableName is null"));
String tableGroupName = tableGroupNameNode.asText();
JsonNode regionListNode = Optional.<JsonNode>ofNullable(jsonMap.get("regionList"))
.orElseThrow(() -> new IOException("regionList is null"));
List<Integer> regions = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(regionListNode.get("regions"), new TypeReference<List<Integer>>() {}))
List<Integer> regions = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(jsonMap.get("regions"), new TypeReference<List<Integer>>() {}))
.orElseThrow(() -> new IOException("regions is null"));
List<Integer> memTableSizeList = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(regionListNode.get("memTableSize"), new TypeReference<List<Integer>>() {}))
List<Long> memTableSizeList = Optional.<List<Long>>ofNullable(objectMapper.convertValue(jsonMap.get("memTableSize"), new TypeReference<List<Long>>() {}))
.orElseThrow(() -> new IOException("memTableSize is null"));
List<Integer> ssTableSizeList = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(regionListNode.get("ssTableSize"), new TypeReference<List<Integer>>() {}))
List<Long> ssTableSizeList = Optional.<List<Long>>ofNullable(objectMapper.convertValue(jsonMap.get("ssTableSize"), new TypeReference<List<Long>>() {}))
.orElseThrow(() -> new IOException("ssTableSize is null"));
if (regions.isEmpty() || regions.size() != memTableSizeList.size() || memTableSizeList.size() != ssTableSizeList.size()) {
throw new IOException("size length has to be the same");
List<String> boundaryList = Optional.<List<String>>ofNullable(objectMapper.convertValue(jsonMap.get("boundary"), new TypeReference<List<String>>() {}))
.orElseThrow(() -> new IOException("boundary is null"));
boolean isHashLikePartition = boundaryList.stream().allMatch(String::isEmpty);
boolean isRangeLikePartition = boundaryList.stream().noneMatch(String::isEmpty);
if (!isRangeLikePartition && !isHashLikePartition) {
// there are empty string and non-empty string in boundary, which is illegal for ADAPTIVE tablegroup
throw new ObTableUnexpectedException("tablegroup {" + tableGroupName + "} has tables with different partition types");
}
Map<byte[], RegionLoad> regionLoadMap = new HashMap<>();
if (regions.isEmpty() || regions.size() != memTableSizeList.size()
|| memTableSizeList.size() != ssTableSizeList.size()) {
throw new IOException("size length has to be the same");
}
for (int i = 0; i < regions.size(); ++i) {
String name_str = Integer.toString(regions.get(i));
byte[] name = name_str.getBytes();
OHRegionLoad load = new OHRegionLoad(name, ssTableSizeList.get(i) / (1024 * 1024), memTableSizeList.get(i) / (1024 * 1024));
OHRegionLoad load = new OHRegionLoad(name, (int) (ssTableSizeList.get(i) / (1024 * 1024)), (int) (memTableSizeList.get(i) / (1024 * 1024)));
regionLoadMap.put(name, load);
}
return regionLoadMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private OHRegionLocator createRangePartitionLocator(
// Similarly, for OBKV-HBase, multiple CFs corresponding to related tablets also reside on the same machine.
// Therefore, here we maintain the same behavior by returning all partitions from just one table.
final int regionCountPerTable = partitions.size() / tableIdDict.size();

List<Object> oneTableLeaders = new ArrayList<>();
for (int i = 0; i < regionCountPerTable; ++i) {
boolean isLeader = ((int) ((List<Object>) partitions.get(i)).get(4) == 1);
Expand Down Expand Up @@ -188,10 +188,13 @@ private OHRegionLocator createRangePartitionLocator(
i
);
int boundIndex = i / replicaDict.size();
long tabletId = Integer.toUnsignedLong((Integer) partition.get(1));
final HRegionInfo regionInfo = new HRegionInfo(
TableName.valueOf(tableName),
startKeys[boundIndex],
endKeys[boundIndex]
endKeys[boundIndex],
false,
tabletId
);
HRegionLocation location = new HRegionLocation(regionInfo, serverName, i);
Boolean role = (int) partition.get(4) == 1;
Expand Down Expand Up @@ -230,17 +233,20 @@ private OHRegionLocator createHashPartitionLocator(
(int) hostInfo.get(1),
i
);
long tabletId = Integer.toUnsignedLong((Integer) partition.get(1));
final HRegionInfo regionInfo = new HRegionInfo(
TableName.valueOf(tableName),
startKeys[0],
endKeys[0]
endKeys[0],
false,
tabletId
);
HRegionLocation location = new HRegionLocation(regionInfo, serverName, i);
Boolean role = (int) partition.get(4) == 1;
return new Pair(location, role);
})
.collect(Collectors.toList());

return new OHRegionLocator(startKeys, endKeys, regionLocations, TableName.valueOf(tableName), client);
}

Expand All @@ -255,4 +261,4 @@ public OHRegionLocator getRegionLocator(final String tableName) throws IOExcepti

return execute(client, request);
}
}
}
Loading