diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java index 0b42561c64e4..b06bc420b0d0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java @@ -648,7 +648,12 @@ private RegionInfo metaTableConsistencyCheck(Result metaTableRow) { } else if (ri.isOverlap(this.highestEndKeyRegionInfo)) { // We may have seen a region a few rows back that overlaps this one. addOverlap(this.highestEndKeyRegionInfo, ri); - } else { + } else if (!this.highestEndKeyRegionInfo.isNext(ri)) { + // Need to check the case that this.highestEndKeyRegionInfo.isNext(ri). If no, + // report a hole, otherwise, it is ok. For an example, + // previous: [aa, bb), ri: [cc, dd), highestEndKeyRegionInfo: [a, cc) + // In this case, it should not report a hole, as highestEndKeyRegionInfo covers + // the hole between previous and ri. addHole(this.previous, ri); } } else if (ri.isOverlap(this.highestEndKeyRegionInfo)) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorCluster.java index 5d5e81da8c9f..abc7ce955087 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorCluster.java @@ -60,6 +60,7 @@ public class TestCatalogJanitorCluster { private static final TableName T1 = TableName.valueOf("t1"); private static final TableName T2 = TableName.valueOf("t2"); private static final TableName T3 = TableName.valueOf("t3"); + private static final TableName T4 = TableName.valueOf("t4"); @Before public void before() throws Exception { @@ -67,6 +68,15 @@ public void before() throws Exception { TEST_UTIL.createMultiRegionTable(T1, new byte [][] {HConstants.CATALOG_FAMILY}); TEST_UTIL.createMultiRegionTable(T2, new byte [][] {HConstants.CATALOG_FAMILY}); TEST_UTIL.createMultiRegionTable(T3, new byte [][] {HConstants.CATALOG_FAMILY}); + + final byte[][] keys = { + Bytes.toBytes("aa"), + Bytes.toBytes("bb"), + Bytes.toBytes("cc"), + Bytes.toBytes("dd") + }; + + TEST_UTIL.createTable(T4, HConstants.CATALOG_FAMILY, keys); } @After @@ -141,7 +151,7 @@ public void testConsistency() throws IOException { emptyInfoServerPut.addColumn(MetaTableAccessor.getCatalogFamily(), MetaTableAccessor.getServerColumn(0), Bytes.toBytes("")); MetaTableAccessor.putsToMetaTable(TEST_UTIL.getConnection(), Arrays.asList(emptyInfoServerPut)); - gc = janitor.scan(); + janitor.scan(); report = janitor.getLastReport(); assertEquals(0, report.getUnknownServers().size()); // Mke an empty regioninfo in t1. @@ -150,9 +160,32 @@ public void testConsistency() throws IOException { pEmptyRI.addColumn(MetaTableAccessor.getCatalogFamily(), MetaTableAccessor.getRegionInfoColumn(), HConstants.EMPTY_BYTE_ARRAY); MetaTableAccessor.putsToMetaTable(TEST_UTIL.getConnection(), Arrays.asList(pEmptyRI)); - gc = janitor.scan(); + janitor.scan(); report = janitor.getLastReport(); assertEquals(1, report.getEmptyRegionInfo().size()); + + int holesReported = report.getHoles().size(); + int overlapsReported = report.getOverlaps().size(); + + // Test the case for + // r1: [aa, bb), r2: [cc, dd), r3: [a, cc) + // Make sure only overlaps and no holes are reported. + List t4Ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), T4); + // delete the region [bb, cc) + MetaTableAccessor.deleteRegionInfo(TEST_UTIL.getConnection(), t4Ris.get(2)); + + // add a new region [a, cc) + RegionInfo newRiT4 = RegionInfoBuilder.newBuilder(T4). + setStartKey("a".getBytes()). + setEndKey("cc".getBytes()).build(); + Put putForT4 = MetaTableAccessor.makePutFromRegionInfo(newRiT4, System.currentTimeMillis()); + MetaTableAccessor.putsToMetaTable(TEST_UTIL.getConnection(), Arrays.asList(putForT4)); + + janitor.scan(); + report = janitor.getLastReport(); + // there is no new hole reported, 2 more overLaps added. + assertEquals(holesReported, report.getHoles().size()); + assertEquals(overlapsReported + 2, report.getOverlaps().size()); } /**