Skip to content

Backport "HBASE-23561 Look up of Region in Master by encoded region name is O(n)" to branch-2.5 #5070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,24 @@ public int compare(final RegionState l, final RegionState r) {
public final static RegionStateStampComparator REGION_STATE_STAMP_COMPARATOR =
new RegionStateStampComparator();

private final Object regionsMapLock = new Object();

// TODO: Replace the ConcurrentSkipListMaps
/**
* 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 +108,7 @@ public RegionStates() {
*/
public void clear() {
regionsMap.clear();
encodedRegionsMap.clear();
regionInTransition.clear();
regionOffline.clear();
serverMap.clear();
Expand All @@ -113,8 +123,12 @@ public boolean isRegionInRegionStates(final RegionInfo hri) {
// RegionStateNode helpers
// ==========================================================================
RegionStateNode createRegionStateNode(RegionInfo regionInfo) {
return regionsMap.computeIfAbsent(regionInfo.getRegionName(),
key -> new RegionStateNode(regionInfo, regionInTransition));
synchronized (regionsMapLock) {
RegionStateNode node = regionsMap.computeIfAbsent(regionInfo.getRegionName(),
key -> new RegionStateNode(regionInfo, regionInTransition));
encodedRegionsMap.putIfAbsent(regionInfo.getEncodedName(), node);
return node;
}
}

public RegionStateNode getOrCreateRegionStateNode(RegionInfo regionInfo) {
Expand All @@ -131,7 +145,10 @@ public RegionStateNode getRegionStateNode(RegionInfo regionInfo) {
}

public void deleteRegion(final RegionInfo regionInfo) {
regionsMap.remove(regionInfo.getRegionName());
synchronized (regionsMapLock) {
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 +216,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