diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java index 69a8d536dcf..e2c4008b70c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java @@ -31,6 +31,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.client.TableState; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.HbckRegionInfo; @@ -146,6 +147,12 @@ public class HbckChore extends ScheduledChore { master.getAssignmentManager().getRegionStates().getRegionStates(); for (RegionState regionState : regionStates) { RegionInfo regionInfo = regionState.getRegion(); + // Because the inconsistent regions are not absolutely right, only skip the offline regions + // which belong to disabled table. + if (master.getTableStateManager() + .isTableState(regionInfo.getTable(), TableState.State.DISABLED)) { + continue; + } HbckRegionInfo.MetaEntry metaEntry = new HbckRegionInfo.MetaEntry(regionInfo, regionState.getServerName(), regionState.getStamp()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java index 7dfe9790e2c..eba2fe25350 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestHbckChore.java @@ -33,7 +33,9 @@ import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfoBuilder; +import org.apache.hadoop.hbase.client.TableState; import org.apache.hadoop.hbase.master.HbckChore; +import org.apache.hadoop.hbase.master.TableStateManager; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -43,6 +45,7 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -139,13 +142,44 @@ public class TestHbckChore extends TestAssignmentManagerBase { assertTrue(reportedRegionServers.contains(locationInMeta)); assertTrue(reportedRegionServers.contains(anotherServer)); - // Reported right region location. Then not in problematic regions. + // Reported right region location, then not in inconsistent regions. am.reportOnlineRegions(anotherServer, Collections.EMPTY_SET); hbckChore.choreForTesting(); inconsistentRegions = hbckChore.getInconsistentRegions(); assertFalse(inconsistentRegions.containsKey(regionName)); } + @Test + public void testForDisabledTable() throws Exception { + TableName tableName = TableName.valueOf("testForDisabledTable"); + RegionInfo hri = createRegionInfo(tableName, 1); + String regionName = hri.getEncodedName(); + rsDispatcher.setMockRsExecutor(new GoodRsExecutor()); + Future future = submitProcedure(am.createAssignProcedure(hri)); + waitOnFuture(future); + + List serverNames = master.getServerManager().getOnlineServersList(); + assertEquals(NSERVERS, serverNames.size()); + + hbckChore.choreForTesting(); + Map>> inconsistentRegions = + hbckChore.getInconsistentRegions(); + assertTrue(inconsistentRegions.containsKey(regionName)); + Pair> pair = inconsistentRegions.get(regionName); + ServerName locationInMeta = pair.getFirst(); + List reportedRegionServers = pair.getSecond(); + assertTrue(serverNames.contains(locationInMeta)); + assertEquals(0, reportedRegionServers.size()); + + // Set table state to disabled, then not in inconsistent regions. + TableStateManager tableStateManager = master.getTableStateManager(); + Mockito.when(tableStateManager.isTableState(tableName, TableState.State.DISABLED)). + thenReturn(true); + hbckChore.choreForTesting(); + inconsistentRegions = hbckChore.getInconsistentRegions(); + assertFalse(inconsistentRegions.containsKey(regionName)); + } + @Test public void testOrphanRegionsOnFS() throws Exception { TableName tableName = TableName.valueOf("testOrphanRegionsOnFS");