From 13e06c7184e717443d5a134172216d65bddadee9 Mon Sep 17 00:00:00 2001 From: Minwoo Kang Date: Thu, 12 Mar 2020 08:57:21 +0900 Subject: [PATCH] HBASE-23561 acquire lock before update regionsMap (#1263) Addendum: tie add and delete of regionMap and encodedRegionsMap Signed-off-by: stack --- .../hbase/master/assignment/RegionStates.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStates.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStates.java index f6c77dd39ec..3ad61d426b7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStates.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStates.java @@ -68,6 +68,8 @@ public class RegionStates { 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} @@ -121,11 +123,12 @@ public class RegionStates { // 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) { @@ -142,8 +145,10 @@ public class RegionStates { } 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