Skip to content

Commit 2cb58dd

Browse files
authored
Merge pull request #250 from oceanbase/fix-HRegionLocation-build-error
fix hregion location build error
2 parents 963c886 + 414972a commit 2cb58dd

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,33 +141,43 @@ private OHRegionLocator createRangePartitionLocator(
141141
throw new ObTableUnexpectedException(
142142
"The number of partitions should be an integer multiple of the number of tables");
143143
}
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
146144
final List<byte[]> startKeysList = new ArrayList<>();
147145
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) {
150157
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));
153160
}
161+
}
162+
// Note that the number of leaders per single table != (regionCountPerTable / replicaDict.size()).
163+
for (int i = 0; i < oneTableLeaders.size(); ++i) {
154164
if (i == 0) {
155165
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());
159169
endKeysList.add(HConstants.EMPTY_BYTE_ARRAY);
160170
} 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());
163173
}
164174
}
165175
final byte[][] startKeys = startKeysList.toArray(new byte[0][]);
166176
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)
169179
.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));
171181
final int replicationIdx = (int) partition.get(3);
172182
final List<Object> hostInfo = (List<Object>) replicaDict.get(replicationIdx);
173183

@@ -176,10 +186,11 @@ private OHRegionLocator createRangePartitionLocator(
176186
(int) hostInfo.get(1),
177187
i
178188
);
189+
int boundIndex = i / replicaDict.size();
179190
final HRegionInfo regionInfo = new HRegionInfo(
180191
TableName.valueOf(tableName),
181-
startKeys[i],
182-
endKeys[i]
192+
startKeys[boundIndex],
193+
endKeys[boundIndex]
183194
);
184195
return new HRegionLocation(regionInfo, serverName, i);
185196
})

0 commit comments

Comments
 (0)