@@ -141,33 +141,43 @@ private OHRegionLocator createRangePartitionLocator(
141
141
throw new ObTableUnexpectedException (
142
142
"The number of partitions should be an integer multiple of the number of tables" );
143
143
}
144
- // the size of partitions the multiple of the number of zones, the number of tablets and the number of tables
145
- final int regionCount = partitions .size () / tableIdDict .size (); // get tablet boundaries of leaders and followers
146
144
final List <byte []> startKeysList = new ArrayList <>();
147
145
final List <byte []> endKeysList = new ArrayList <>();
148
-
149
- for (int i = 0 ; i < regionCount ; ++i ) {
146
+ // Currently based on SHARDING = 'ADAPTIVE' Table Group implementation for multi-CF,
147
+ // where one constraint is that Tables within the same Table Group have the same partitioning method,
148
+ // thus their associated partition boundaries are consistent.
149
+ //
150
+ // In native HBase, a Region can contain multiple CFs.
151
+ // Similarly, for OBKV-HBase, multiple CFs corresponding to related tablets also reside on the same machine.
152
+ // Therefore, here we maintain the same behavior by returning all partitions from just one table.
153
+ final int regionCountPerTable = partitions .size () / tableIdDict .size ();
154
+
155
+ List <Object > oneTableLeaders = new ArrayList <>();
156
+ for (int i = 0 ; i < regionCountPerTable ; ++i ) {
150
157
boolean isLeader = ((int ) ((List <Object >) partitions .get (i )).get (4 ) == 1 );
151
- if (! isLeader ) { // only record leader's boundary
152
- continue ;
158
+ if (isLeader ) {
159
+ oneTableLeaders . add ( partitions . get ( i )) ;
153
160
}
161
+ }
162
+ // Note that the number of leaders per single table != (regionCountPerTable / replicaDict.size()).
163
+ for (int i = 0 ; i < oneTableLeaders .size (); ++i ) {
154
164
if (i == 0 ) {
155
165
startKeysList .add (HConstants .EMPTY_BYTE_ARRAY );
156
- endKeysList .add (((List <Object >) partitions .get (i )).get (2 ).toString ().getBytes ());
157
- } else if (i == regionCount - 1 ) {
158
- startKeysList .add (((List <Object >) partitions .get (i - 1 )).get (2 ).toString ().getBytes ());
166
+ endKeysList .add (((List <Object >) oneTableLeaders .get (i )).get (2 ).toString ().getBytes ());
167
+ } else if (i == oneTableLeaders . size () - 1 ) {
168
+ startKeysList .add (((List <Object >) oneTableLeaders .get (i - 1 )).get (2 ).toString ().getBytes ());
159
169
endKeysList .add (HConstants .EMPTY_BYTE_ARRAY );
160
170
} else {
161
- startKeysList .add (((List <Object >) partitions .get (i - 1 )).get (2 ).toString ().getBytes ());
162
- endKeysList .add (((List <Object >) partitions .get (i )).get (2 ).toString ().getBytes ());
171
+ startKeysList .add (((List <Object >) oneTableLeaders .get (i - 1 )).get (2 ).toString ().getBytes ());
172
+ endKeysList .add (((List <Object >) oneTableLeaders .get (i )).get (2 ).toString ().getBytes ());
163
173
}
164
174
}
165
175
final byte [][] startKeys = startKeysList .toArray (new byte [0 ][]);
166
176
final byte [][] endKeys = endKeysList .toArray (new byte [0 ][]);
167
- // Create region locations for all regions
168
- final List <HRegionLocation > regionLocations = IntStream .range (0 , regionCount )
177
+ // Create region locations for all regions in one table
178
+ final List <HRegionLocation > regionLocations = IntStream .range (0 , regionCountPerTable )
169
179
.mapToObj (i -> {
170
- final List <Object > partition = (List <Object >) partitions .get (Math .min (i , regionCount - 1 ));
180
+ final List <Object > partition = (List <Object >) partitions .get (Math .min (i , regionCountPerTable - 1 ));
171
181
final int replicationIdx = (int ) partition .get (3 );
172
182
final List <Object > hostInfo = (List <Object >) replicaDict .get (replicationIdx );
173
183
@@ -176,10 +186,11 @@ private OHRegionLocator createRangePartitionLocator(
176
186
(int ) hostInfo .get (1 ),
177
187
i
178
188
);
189
+ int boundIndex = i / replicaDict .size ();
179
190
final HRegionInfo regionInfo = new HRegionInfo (
180
191
TableName .valueOf (tableName ),
181
- startKeys [i ],
182
- endKeys [i ]
192
+ startKeys [boundIndex ],
193
+ endKeys [boundIndex ]
183
194
);
184
195
return new HRegionLocation (regionInfo , serverName , i );
185
196
})
0 commit comments