Skip to content

Commit

Permalink
HBASE-24379 CatalogJanitor misreports region holes when there are act…
Browse files Browse the repository at this point in the history
…ually over laps.
  • Loading branch information
Huaxiang Sun committed May 19, 2020
1 parent 5fb9e51 commit cbedc44
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,23 @@ 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 {
TEST_UTIL.startMiniCluster();
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
Expand Down Expand Up @@ -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.
Expand All @@ -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<RegionInfo> 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());
}

/**
Expand Down

0 comments on commit cbedc44

Please sign in to comment.