HBASE-23561 acquire lock before update regionsMap (#1263)
Addendum: tie add and delete of regionMap and encodedRegionsMap Signed-off-by: stack <stack@apache.org>
This commit is contained in:
parent
0b18a7dc26
commit
6f1e8abc30
|
@ -71,6 +71,8 @@ public class RegionStates {
|
||||||
public final static RegionStateStampComparator REGION_STATE_STAMP_COMPARATOR =
|
public final static RegionStateStampComparator REGION_STATE_STAMP_COMPARATOR =
|
||||||
new RegionStateStampComparator();
|
new RegionStateStampComparator();
|
||||||
|
|
||||||
|
private final Object regionsMapLock = new Object();
|
||||||
|
|
||||||
// TODO: Replace the ConcurrentSkipListMaps
|
// TODO: Replace the ConcurrentSkipListMaps
|
||||||
/**
|
/**
|
||||||
* RegionName -- i.e. RegionInfo.getRegionName() -- as bytes to {@link RegionStateNode}
|
* RegionName -- i.e. RegionInfo.getRegionName() -- as bytes to {@link RegionStateNode}
|
||||||
|
@ -125,11 +127,12 @@ public class RegionStates {
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
RegionStateNode createRegionStateNode(RegionInfo regionInfo) {
|
RegionStateNode createRegionStateNode(RegionInfo regionInfo) {
|
||||||
return regionsMap.computeIfAbsent(regionInfo.getRegionName(), key -> {
|
synchronized (regionsMapLock) {
|
||||||
final RegionStateNode node = new RegionStateNode(regionInfo, regionInTransition);
|
RegionStateNode node = regionsMap.computeIfAbsent(regionInfo.getRegionName(),
|
||||||
|
key -> new RegionStateNode(regionInfo, regionInTransition));
|
||||||
encodedRegionsMap.putIfAbsent(regionInfo.getEncodedName(), node);
|
encodedRegionsMap.putIfAbsent(regionInfo.getEncodedName(), node);
|
||||||
return node;
|
return node;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegionStateNode getOrCreateRegionStateNode(RegionInfo regionInfo) {
|
public RegionStateNode getOrCreateRegionStateNode(RegionInfo regionInfo) {
|
||||||
|
@ -146,8 +149,10 @@ public class RegionStates {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteRegion(final RegionInfo regionInfo) {
|
public void deleteRegion(final RegionInfo regionInfo) {
|
||||||
|
synchronized (regionsMapLock) {
|
||||||
regionsMap.remove(regionInfo.getRegionName());
|
regionsMap.remove(regionInfo.getRegionName());
|
||||||
encodedRegionsMap.remove(regionInfo.getEncodedName());
|
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
|
||||||
|
|
Loading…
Reference in New Issue