Skip to content

Commit

Permalink
HBASE-23561 acquire lock before update regionsMap (#1263)
Browse files Browse the repository at this point in the history
Addendum: tie add and delete of regionMap and encodedRegionsMap

Signed-off-by: stack <[email protected]>
  • Loading branch information
mwkang authored and ndimiduk committed Mar 1, 2023
1 parent 5f54d9c commit 13e06c7
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ 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}
Expand Down Expand Up @@ -121,11 +123,12 @@ public boolean isRegionInRegionStates(final RegionInfo hri) {
// RegionStateNode helpers
// ==========================================================================
RegionStateNode createRegionStateNode(RegionInfo regionInfo) {
return regionsMap.computeIfAbsent(regionInfo.getRegionName(), key -> {
final RegionStateNode node = 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 @@ -142,8 +145,10 @@ public RegionStateNode getRegionStateNode(RegionInfo regionInfo) {
}

public void deleteRegion(final RegionInfo regionInfo) {
regionsMap.remove(regionInfo.getRegionName());
encodedRegionsMap.remove(regionInfo.getEncodedName());
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

0 comments on commit 13e06c7

Please sign in to comment.