28
28
import com .alipay .oceanbase .rpc .meta .ObTableMetaResponse ;
29
29
import com .alipay .oceanbase .rpc .meta .ObTableRpcMetaType ;
30
30
import org .apache .hadoop .hbase .*;
31
+ import org .apache .hadoop .hbase .util .Pair ;
31
32
32
33
import java .io .IOException ;
33
34
import java .util .*;
@@ -72,25 +73,25 @@ public OHRegionLocator parse(ObTableMetaResponse response) throws IOException {
72
73
"partitions": [
73
74
// 表1001的3个分区,每个分区3副本
74
75
[0, 50001, "rowkey_1", 0, 1], // leader
75
- [0, 50001, "rowkey_1", 1, 0 ], // follower
76
- [0, 50001, "rowkey_1", 2, 0 ], // follower
76
+ [0, 50001, "rowkey_1", 1, 2 ], // follower
77
+ [0, 50001, "rowkey_1", 2, 2 ], // follower
77
78
[0, 50002, "rowkey_2", 0, 1],
78
- [0, 50002, "rowkey_2", 1, 0 ],
79
- [0, 50002, "rowkey_2", 2, 0 ],
79
+ [0, 50002, "rowkey_2", 1, 2 ],
80
+ [0, 50002, "rowkey_2", 2, 2 ],
80
81
[0, 50003, "rowkey_3", 0, 1],
81
- [0, 50003, "rowkey_3", 1, 0 ],
82
- [0, 50003, "rowkey_3", 2, 0 ],
82
+ [0, 50003, "rowkey_3", 1, 2 ],
83
+ [0, 50003, "rowkey_3", 2, 2 ],
83
84
84
85
// 表1002的3个分区,每个分区3副本
85
86
[1, 50004, "rowkey_1", 0, 1],
86
- [1, 50004, "rowkey_1", 1, 0 ],
87
- [1, 50004, "rowkey_1", 2, 0 ],
87
+ [1, 50004, "rowkey_1", 1, 2 ],
88
+ [1, 50004, "rowkey_1", 2, 2 ],
88
89
[1, 50005, "rowkey_2", 0, 1],
89
- [1, 50005, "rowkey_2", 1, 0 ],
90
- [1, 50005, "rowkey_2", 2, 0 ],
90
+ [1, 50005, "rowkey_2", 1, 2 ],
91
+ [1, 50005, "rowkey_2", 2, 2 ],
91
92
[1, 50006, "rowkey_3", 0, 1],
92
- [1, 50006, "rowkey_3", 1, 0 ],
93
- [1, 50006, "rowkey_3", 2, 0 ]
93
+ [1, 50006, "rowkey_3", 1, 2 ],
94
+ [1, 50006, "rowkey_3", 2, 2 ]
94
95
]
95
96
}
96
97
*/
@@ -175,7 +176,7 @@ private OHRegionLocator createRangePartitionLocator(
175
176
final byte [][] startKeys = startKeysList .toArray (new byte [0 ][]);
176
177
final byte [][] endKeys = endKeysList .toArray (new byte [0 ][]);
177
178
// Create region locations for all regions in one table
178
- final List < HRegionLocation > regionLocations = IntStream .range (0 , regionCountPerTable )
179
+ final List regionLocations = IntStream .range (0 , regionCountPerTable )
179
180
.mapToObj (i -> {
180
181
final List <Object > partition = (List <Object >) partitions .get (Math .min (i , regionCountPerTable - 1 ));
181
182
final int replicationIdx = (int ) partition .get (3 );
@@ -192,7 +193,9 @@ private OHRegionLocator createRangePartitionLocator(
192
193
startKeys [boundIndex ],
193
194
endKeys [boundIndex ]
194
195
);
195
- return new HRegionLocation (regionInfo , serverName , i );
196
+ HRegionLocation location = new HRegionLocation (regionInfo , serverName , i );
197
+ Boolean role = (int ) partition .get (4 ) == 1 ;
198
+ return new Pair (location , role );
196
199
})
197
200
.collect (Collectors .toList ());
198
201
@@ -215,8 +218,8 @@ private OHRegionLocator createHashPartitionLocator(
215
218
final byte [][] endKeys = new byte [1 ][];
216
219
startKeys [0 ] = HConstants .EMPTY_BYTE_ARRAY ;
217
220
endKeys [0 ] = HConstants .EMPTY_BYTE_ARRAY ;
218
-
219
- final List < HRegionLocation > regionLocations = IntStream .range (0 , partitions . size () )
221
+ final int regionCountPerTable = partitions . size () / tableIdDict . size ();
222
+ final List regionLocations = IntStream .range (0 , regionCountPerTable )
220
223
.mapToObj (i -> {
221
224
final List <Object > partition = (List <Object >) partitions .get (i );
222
225
final int replicationIdx = (int ) partition .get (3 );
@@ -232,10 +235,12 @@ private OHRegionLocator createHashPartitionLocator(
232
235
startKeys [0 ],
233
236
endKeys [0 ]
234
237
);
235
- return new HRegionLocation (regionInfo , serverName , i );
238
+ HRegionLocation location = new HRegionLocation (regionInfo , serverName , i );
239
+ Boolean role = (int ) partition .get (4 ) == 1 ;
240
+ return new Pair (location , role );
236
241
})
237
242
.collect (Collectors .toList ());
238
-
243
+
239
244
return new OHRegionLocator (startKeys , endKeys , regionLocations , TableName .valueOf (tableName ), client );
240
245
}
241
246
0 commit comments