17
17
18
18
package com .alipay .oceanbase .hbase .util ;
19
19
20
+ import com .alipay .oceanbase .rpc .exception .ObTableUnexpectedException ;
20
21
import com .fasterxml .jackson .core .type .TypeReference ;
21
22
import com .fasterxml .jackson .databind .JsonNode ;
22
23
import com .fasterxml .jackson .databind .ObjectMapper ;
25
26
import com .alipay .oceanbase .rpc .meta .ObTableMetaRequest ;
26
27
import com .alipay .oceanbase .rpc .meta .ObTableMetaResponse ;
27
28
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 .*;
32
30
import org .apache .hadoop .hbase .client .Table ;
33
31
34
32
import java .io .IOException ;
@@ -49,11 +47,10 @@ public ObTableRpcMetaType getMetaType() throws IOException {
49
47
/*
50
48
* {
51
49
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", ...]
57
54
}
58
55
* */
59
56
@ Override
@@ -64,22 +61,53 @@ public List<RegionMetrics> parse(ObTableMetaResponse response) throws IOExceptio
64
61
JsonNode tableGroupNameNode = Optional .<JsonNode >ofNullable (jsonMap .get ("tableName" ))
65
62
.orElseThrow (() -> new IOException ("tableName is null" ));
66
63
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 >>() {}))
70
65
.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 >>() {}))
72
67
.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 >>() {}))
74
69
.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
+ }
75
100
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 ) {
77
104
throw new IOException ("size length has to be the same" );
78
105
}
79
106
for (int i = 0 ; i < regions .size (); ++i ) {
107
+ byte [] startKey = isHashLikePartition ? startKeys [0 ] : startKeys [i ];
80
108
byte [] name = HRegionInfo .createRegionName (
81
109
TableName .valueOf (tableGroupName ),
82
- null ,
110
+ startKey ,
83
111
regions .get (i ),
84
112
HRegionInfo .DEFAULT_REPLICA_ID , true
85
113
);
0 commit comments