Skip to content

Commit a03e342

Browse files
committed
change region metrics json, keep region name the same with region locator
1 parent f0382cf commit a03e342

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,13 @@ private OHRegionLocator createRangePartitionLocator(
188188
i
189189
);
190190
int boundIndex = i / replicaDict.size();
191+
long tabletId = Integer.toUnsignedLong((Integer) partition.get(1));
191192
final HRegionInfo regionInfo = new HRegionInfo(
192193
TableName.valueOf(tableName),
193194
startKeys[boundIndex],
194-
endKeys[boundIndex]
195+
endKeys[boundIndex],
196+
false,
197+
tabletId
195198
);
196199
HRegionLocation location = new HRegionLocation(regionInfo, serverName, i);
197200
Boolean role = (int) partition.get(4) == 1;
@@ -230,10 +233,11 @@ private OHRegionLocator createHashPartitionLocator(
230233
(int) hostInfo.get(1),
231234
i
232235
);
233-
long tabletId = (long) partition.get(1);
236+
long tabletId = Integer.toUnsignedLong((Integer) partition.get(1));
234237
final HRegionInfo regionInfo = new HRegionInfo(
235238
TableName.valueOf(tableName),
236-
null, null,
239+
startKeys[0],
240+
endKeys[0],
237241
false,
238242
tabletId
239243
);

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

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.alipay.oceanbase.hbase.util;
1919

20+
import com.alipay.oceanbase.rpc.exception.ObTableUnexpectedException;
2021
import com.fasterxml.jackson.core.type.TypeReference;
2122
import com.fasterxml.jackson.databind.JsonNode;
2223
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -25,10 +26,7 @@
2526
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
2627
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
2728
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
28-
import org.apache.hadoop.hbase.HRegionInfo;
29-
import org.apache.hadoop.hbase.RegionMetrics;
30-
import org.apache.hadoop.hbase.Size;
31-
import org.apache.hadoop.hbase.TableName;
29+
import org.apache.hadoop.hbase.*;
3230
import org.apache.hadoop.hbase.client.Table;
3331

3432
import java.io.IOException;
@@ -49,11 +47,10 @@ public ObTableRpcMetaType getMetaType() throws IOException {
4947
/*
5048
* {
5149
tableName: "tablegroup_name",
52-
regionList:{
53-
"regions": [200051, 200052, 200053, 200191, 200192, 200193, ...],
54-
"memTableSize":[123, 321, 321, 123, 321, 321, ...],
55-
"ssTableSize":[5122, 4111, 5661, 5122, 4111, 5661, ...]
56-
}
50+
"regions": [200051, 200052, 200053, 200191, 200192, 200193, ...],
51+
"memTableSize":[123, 321, 321, 123, 321, 321, ...],
52+
"ssTableSize":[5122, 4111, 5661, 5122, 4111, 5661, ...],
53+
"boundary":["rowkey1", "rowkey2", "rowkey3", ..., "rowkey100", "rowkey101", "rowkey102", ...]
5754
}
5855
* */
5956
@Override
@@ -64,22 +61,53 @@ public List<RegionMetrics> parse(ObTableMetaResponse response) throws IOExceptio
6461
JsonNode tableGroupNameNode = Optional.<JsonNode>ofNullable(jsonMap.get("tableName"))
6562
.orElseThrow(() -> new IOException("tableName is null"));
6663
String tableGroupName = tableGroupNameNode.asText();
67-
JsonNode regionListNode = Optional.<JsonNode>ofNullable(jsonMap.get("regionList"))
68-
.orElseThrow(() -> new IOException("regionList is null"));
69-
List<Integer> regions = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(regionListNode.get("regions"), new TypeReference<List<Integer>>() {}))
64+
List<Integer> regions = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(jsonMap.get("regions"), new TypeReference<List<Integer>>() {}))
7065
.orElseThrow(() -> new IOException("regions is null"));
71-
List<Integer> memTableSizeList = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(regionListNode.get("memTableSize"), new TypeReference<List<Integer>>() {}))
66+
List<Long> memTableSizeList = Optional.<List<Long>>ofNullable(objectMapper.convertValue(jsonMap.get("memTableSize"), new TypeReference<List<Long>>() {}))
7267
.orElseThrow(() -> new IOException("memTableSize is null"));
73-
List<Integer> ssTableSizeList = Optional.<List<Integer>>ofNullable(objectMapper.convertValue(regionListNode.get("ssTableSize"), new TypeReference<List<Integer>>() {}))
68+
List<Long> ssTableSizeList = Optional.<List<Long>>ofNullable(objectMapper.convertValue(jsonMap.get("ssTableSize"), new TypeReference<List<Long>>() {}))
7469
.orElseThrow(() -> new IOException("ssTableSize is null"));
70+
List<String> boundaryList = Optional.<List<String>>ofNullable(objectMapper.convertValue(jsonMap.get("boundary"), new TypeReference<List<String>>() {}))
71+
.orElseThrow(() -> new IOException("boundary is null"));
72+
boolean isHashLikePartition = boundaryList.stream().allMatch(String::isEmpty);
73+
boolean isRangeLikePartition = boundaryList.stream().noneMatch(String::isEmpty);
74+
if (!isRangeLikePartition && !isHashLikePartition) {
75+
// there are empty string and non-empty string in boundary, which is illegal for ADAPTIVE tablegroup
76+
throw new ObTableUnexpectedException("tablegroup {" + tableGroupName + "} has tables with different partition types");
77+
}
78+
byte[][] startKeys = new byte[regions.size()][];
79+
byte[][] endKeys = new byte[regions.size()][];
80+
if (isHashLikePartition) {
81+
startKeys[0] = HConstants.EMPTY_BYTE_ARRAY;
82+
endKeys[0] = HConstants.EMPTY_BYTE_ARRAY;
83+
} else {
84+
final List<byte[]> startKeysList = new ArrayList<>();
85+
final List<byte[]> endKeysList = new ArrayList<>();
86+
for (int i = 0; i < boundaryList.size(); ++i) {
87+
if (i == 0) {
88+
startKeysList.add(HConstants.EMPTY_BYTE_ARRAY);
89+
endKeysList.add(boundaryList.get(i).getBytes());
90+
} else if (i == boundaryList.size() - 1) {
91+
startKeysList.add(boundaryList.get(i - 1).getBytes());
92+
endKeysList.add(HConstants.EMPTY_BYTE_ARRAY);
93+
} else {
94+
startKeysList.add(boundaryList.get(i - 1).getBytes());
95+
endKeysList.add(boundaryList.get(i).getBytes());
96+
}
97+
}
98+
startKeys = startKeysList.toArray(new byte[0][]);
99+
}
75100
List<RegionMetrics> metricsList = new ArrayList<>();
76-
if (regions.isEmpty() || regions.size() != memTableSizeList.size() || memTableSizeList.size() != ssTableSizeList.size()) {
101+
if (regions.isEmpty() || regions.size() != memTableSizeList.size()
102+
|| memTableSizeList.size() != ssTableSizeList.size()
103+
|| ssTableSizeList.size() != startKeys.length) {
77104
throw new IOException("size length has to be the same");
78105
}
79106
for (int i = 0; i < regions.size(); ++i) {
107+
byte[] startKey = isHashLikePartition ? startKeys[0] : startKeys[i];
80108
byte[] name = HRegionInfo.createRegionName(
81109
TableName.valueOf(tableGroupName),
82-
null,
110+
startKey,
83111
regions.get(i),
84112
HRegionInfo.DEFAULT_REPLICA_ID, true
85113
);

0 commit comments

Comments
 (0)