Skip to content

Commit

Permalink
HBASE-23561 Look up of Region in Master by encoded region name is O(n) (
Browse files Browse the repository at this point in the history
#1193)

Signed-off-by: Wellington Chevreuil <[email protected]>
Signed-off-by: Viraj Jasani <[email protected]>
  • Loading branch information
mwkang authored and ndimiduk committed Feb 27, 2023
1 parent 3b6d8c3 commit 574a76e
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@ public int compare(final RegionState l, final RegionState r) {
* RegionName -- i.e. RegionInfo.getRegionName() -- as bytes to {@link RegionStateNode}
*/
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 =
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
Expand All @@ -99,6 +106,7 @@ public RegionStates() {
*/
public void clear() {
regionsMap.clear();
encodedRegionsMap.clear();
regionInTransition.clear();
regionOffline.clear();
serverMap.clear();
Expand All @@ -113,8 +121,11 @@ public boolean isRegionInRegionStates(final RegionInfo hri) {
// RegionStateNode helpers
// ==========================================================================
RegionStateNode createRegionStateNode(RegionInfo regionInfo) {
return regionsMap.computeIfAbsent(regionInfo.getRegionName(),
key -> new RegionStateNode(regionInfo, regionInTransition));
return regionsMap.computeIfAbsent(regionInfo.getRegionName(), key -> {
final RegionStateNode node = new RegionStateNode(regionInfo, regionInTransition);
encodedRegionsMap.putIfAbsent(regionInfo.getEncodedName(), node);
return node;
});
}

public RegionStateNode getOrCreateRegionStateNode(RegionInfo regionInfo) {
Expand All @@ -132,6 +143,7 @@ public RegionStateNode getRegionStateNode(RegionInfo regionInfo) {

public void deleteRegion(final RegionInfo regionInfo) {
regionsMap.remove(regionInfo.getRegionName());
encodedRegionsMap.remove(regionInfo.getEncodedName());
// See HBASE-20860
// After master restarts, merged regions' RIT state may not be cleaned,
// making sure they are cleaned here
Expand Down Expand Up @@ -199,13 +211,11 @@ public RegionState getRegionState(final RegionInfo regionInfo) {
}

public RegionState getRegionState(final String encodedRegionName) {
// TODO: Need a map <encodedName, ...> but it is just dispatch merge...
for (RegionStateNode node : regionsMap.values()) {
if (node.getRegionInfo().getEncodedName().equals(encodedRegionName)) {
return node.toRegionState();
}
final RegionStateNode node = encodedRegionsMap.get(encodedRegionName);
if (node == null) {
return null;
}
return null;
return node.toRegionState();
}

// ============================================================================================
Expand Down

0 comments on commit 574a76e

Please sign in to comment.