HBASE-23561 Look up of Region in Master by encoded region name is O(n) (#1193)

Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Minwoo Kang 2020-02-22 01:40:45 +09:00 committed by Nick Dimiduk
parent 9a23d4a3b2
commit 5f54d9cbad
1 changed files with 20 additions and 10 deletions

View File

@ -73,10 +73,17 @@ public class RegionStates {
* RegionName -- i.e. RegionInfo.getRegionName() -- as bytes to {@link RegionStateNode} * RegionName -- i.e. RegionInfo.getRegionName() -- as bytes to {@link RegionStateNode}
*/ */
private final ConcurrentSkipListMap<byte[], RegionStateNode> regionsMap = private final ConcurrentSkipListMap<byte[], RegionStateNode> regionsMap =
new ConcurrentSkipListMap<byte[], RegionStateNode>(Bytes.BYTES_COMPARATOR); new ConcurrentSkipListMap<>(Bytes.BYTES_COMPARATOR);
/**
* this map is a hack to lookup of region in master by encoded region name is O(n). must put and
* remove with regionsMap.
*/
private final ConcurrentSkipListMap<String, RegionStateNode> encodedRegionsMap =
new ConcurrentSkipListMap<>();
private final ConcurrentSkipListMap<RegionInfo, RegionStateNode> regionInTransition = private final ConcurrentSkipListMap<RegionInfo, RegionStateNode> regionInTransition =
new ConcurrentSkipListMap<RegionInfo, RegionStateNode>(RegionInfo.COMPARATOR); new ConcurrentSkipListMap<>(RegionInfo.COMPARATOR);
/** /**
* Regions marked as offline on a read of hbase:meta. Unused or at least, once offlined, regions * Regions marked as offline on a read of hbase:meta. Unused or at least, once offlined, regions
@ -99,6 +106,7 @@ public class RegionStates {
*/ */
public void clear() { public void clear() {
regionsMap.clear(); regionsMap.clear();
encodedRegionsMap.clear();
regionInTransition.clear(); regionInTransition.clear();
regionOffline.clear(); regionOffline.clear();
serverMap.clear(); serverMap.clear();
@ -113,8 +121,11 @@ public class RegionStates {
// RegionStateNode helpers // RegionStateNode helpers
// ========================================================================== // ==========================================================================
RegionStateNode createRegionStateNode(RegionInfo regionInfo) { RegionStateNode createRegionStateNode(RegionInfo regionInfo) {
return regionsMap.computeIfAbsent(regionInfo.getRegionName(), return regionsMap.computeIfAbsent(regionInfo.getRegionName(), key -> {
key -> new RegionStateNode(regionInfo, regionInTransition)); final RegionStateNode node = new RegionStateNode(regionInfo, regionInTransition);
encodedRegionsMap.putIfAbsent(regionInfo.getEncodedName(), node);
return node;
});
} }
public RegionStateNode getOrCreateRegionStateNode(RegionInfo regionInfo) { public RegionStateNode getOrCreateRegionStateNode(RegionInfo regionInfo) {
@ -132,6 +143,7 @@ public class RegionStates {
public void deleteRegion(final RegionInfo regionInfo) { public void deleteRegion(final RegionInfo regionInfo) {
regionsMap.remove(regionInfo.getRegionName()); regionsMap.remove(regionInfo.getRegionName());
encodedRegionsMap.remove(regionInfo.getEncodedName());
// See HBASE-20860 // See HBASE-20860
// After master restarts, merged regions' RIT state may not be cleaned, // After master restarts, merged regions' RIT state may not be cleaned,
// making sure they are cleaned here // making sure they are cleaned here
@ -199,14 +211,12 @@ public class RegionStates {
} }
public RegionState getRegionState(final String encodedRegionName) { public RegionState getRegionState(final String encodedRegionName) {
// TODO: Need a map <encodedName, ...> but it is just dispatch merge... final RegionStateNode node = encodedRegionsMap.get(encodedRegionName);
for (RegionStateNode node : regionsMap.values()) { if (node == null) {
if (node.getRegionInfo().getEncodedName().equals(encodedRegionName)) {
return node.toRegionState();
}
}
return null; return null;
} }
return node.toRegionState();
}
// ============================================================================================ // ============================================================================================
// TODO: helpers // TODO: helpers