Skip to content

Commit cbedc44

Browse files
author
Huaxiang Sun
committed
HBASE-24379 CatalogJanitor misreports region holes when there are actually over laps.
1 parent 5fb9e51 commit cbedc44

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/CatalogJanitor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,12 @@ private RegionInfo metaTableConsistencyCheck(Result metaTableRow) {
648648
} else if (ri.isOverlap(this.highestEndKeyRegionInfo)) {
649649
// We may have seen a region a few rows back that overlaps this one.
650650
addOverlap(this.highestEndKeyRegionInfo, ri);
651-
} else {
651+
} else if (!this.highestEndKeyRegionInfo.isNext(ri)) {
652+
// Need to check the case that this.highestEndKeyRegionInfo.isNext(ri). If no,
653+
// report a hole, otherwise, it is ok. For an example,
654+
// previous: [aa, bb), ri: [cc, dd), highestEndKeyRegionInfo: [a, cc)
655+
// In this case, it should not report a hole, as highestEndKeyRegionInfo covers
656+
// the hole between previous and ri.
652657
addHole(this.previous, ri);
653658
}
654659
} else if (ri.isOverlap(this.highestEndKeyRegionInfo)) {

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorCluster.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ public class TestCatalogJanitorCluster {
6060
private static final TableName T1 = TableName.valueOf("t1");
6161
private static final TableName T2 = TableName.valueOf("t2");
6262
private static final TableName T3 = TableName.valueOf("t3");
63+
private static final TableName T4 = TableName.valueOf("t4");
6364

6465
@Before
6566
public void before() throws Exception {
6667
TEST_UTIL.startMiniCluster();
6768
TEST_UTIL.createMultiRegionTable(T1, new byte [][] {HConstants.CATALOG_FAMILY});
6869
TEST_UTIL.createMultiRegionTable(T2, new byte [][] {HConstants.CATALOG_FAMILY});
6970
TEST_UTIL.createMultiRegionTable(T3, new byte [][] {HConstants.CATALOG_FAMILY});
71+
72+
final byte[][] keys = {
73+
Bytes.toBytes("aa"),
74+
Bytes.toBytes("bb"),
75+
Bytes.toBytes("cc"),
76+
Bytes.toBytes("dd")
77+
};
78+
79+
TEST_UTIL.createTable(T4, HConstants.CATALOG_FAMILY, keys);
7080
}
7181

7282
@After
@@ -141,7 +151,7 @@ public void testConsistency() throws IOException {
141151
emptyInfoServerPut.addColumn(MetaTableAccessor.getCatalogFamily(),
142152
MetaTableAccessor.getServerColumn(0), Bytes.toBytes(""));
143153
MetaTableAccessor.putsToMetaTable(TEST_UTIL.getConnection(), Arrays.asList(emptyInfoServerPut));
144-
gc = janitor.scan();
154+
janitor.scan();
145155
report = janitor.getLastReport();
146156
assertEquals(0, report.getUnknownServers().size());
147157
// Mke an empty regioninfo in t1.
@@ -150,9 +160,32 @@ public void testConsistency() throws IOException {
150160
pEmptyRI.addColumn(MetaTableAccessor.getCatalogFamily(),
151161
MetaTableAccessor.getRegionInfoColumn(), HConstants.EMPTY_BYTE_ARRAY);
152162
MetaTableAccessor.putsToMetaTable(TEST_UTIL.getConnection(), Arrays.asList(pEmptyRI));
153-
gc = janitor.scan();
163+
janitor.scan();
154164
report = janitor.getLastReport();
155165
assertEquals(1, report.getEmptyRegionInfo().size());
166+
167+
int holesReported = report.getHoles().size();
168+
int overlapsReported = report.getOverlaps().size();
169+
170+
// Test the case for
171+
// r1: [aa, bb), r2: [cc, dd), r3: [a, cc)
172+
// Make sure only overlaps and no holes are reported.
173+
List<RegionInfo> t4Ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), T4);
174+
// delete the region [bb, cc)
175+
MetaTableAccessor.deleteRegionInfo(TEST_UTIL.getConnection(), t4Ris.get(2));
176+
177+
// add a new region [a, cc)
178+
RegionInfo newRiT4 = RegionInfoBuilder.newBuilder(T4).
179+
setStartKey("a".getBytes()).
180+
setEndKey("cc".getBytes()).build();
181+
Put putForT4 = MetaTableAccessor.makePutFromRegionInfo(newRiT4, System.currentTimeMillis());
182+
MetaTableAccessor.putsToMetaTable(TEST_UTIL.getConnection(), Arrays.asList(putForT4));
183+
184+
janitor.scan();
185+
report = janitor.getLastReport();
186+
// there is no new hole reported, 2 more overLaps added.
187+
assertEquals(holesReported, report.getHoles().size());
188+
assertEquals(overlapsReported + 2, report.getOverlaps().size());
156189
}
157190

158191
/**

0 commit comments

Comments
 (0)