HBASE-23294 ReplicationBarrierCleaner should delete all the barriers for a removed region which does not belong to any serial replication peer (#827)

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Duo Zhang 2019-11-15 18:59:51 +08:00
parent f5db86ca8f
commit e69431ae8c
2 changed files with 38 additions and 6 deletions

View File

@ -99,13 +99,22 @@ public class ReplicationBarrierCleaner extends ScheduledChore {
peerIds = peerManager.getSerialPeerIdsBelongsTo(tableName); peerIds = peerManager.getSerialPeerIdsBelongsTo(tableName);
} }
if (peerIds.isEmpty()) { if (peerIds.isEmpty()) {
// no serial replication, only keep the newest barrier // no serial replication
// check if the region has already been removed, i.e, no catalog family
if (metaTable.exists(new Get(regionName).addFamily(HConstants.CATALOG_FAMILY))) {
// exists, then only keep the newest barrier
Cell cell = result.getColumnLatestCell(HConstants.REPLICATION_BARRIER_FAMILY, Cell cell = result.getColumnLatestCell(HConstants.REPLICATION_BARRIER_FAMILY,
HConstants.SEQNUM_QUALIFIER); HConstants.SEQNUM_QUALIFIER);
metaTable.delete(new Delete(regionName).addFamily(HConstants.REPLICATION_BARRIER_FAMILY, metaTable.delete(new Delete(regionName).addFamily(HConstants.REPLICATION_BARRIER_FAMILY,
cell.getTimestamp() - 1)); cell.getTimestamp() - 1));
cleanedRows++;
deletedBarriers += barriers.length - 1; deletedBarriers += barriers.length - 1;
} else {
// not exists, delete all the barriers
metaTable
.delete(new Delete(regionName).addFamily(HConstants.REPLICATION_BARRIER_FAMILY));
deletedBarriers += barriers.length;
}
cleanedRows++;
continue; continue;
} }
String encodedRegionName = RegionInfo.encodeRegionName(regionName); String encodedRegionName = RegionInfo.encodeRegionName(regionName);

View File

@ -181,17 +181,21 @@ public class TestReplicationBarrierCleaner {
RegionInfo region11 = RegionInfo region11 =
RegionInfoBuilder.newBuilder(tableName1).setEndKey(Bytes.toBytes(1)).build(); RegionInfoBuilder.newBuilder(tableName1).setEndKey(Bytes.toBytes(1)).build();
addBarrier(region11, 10, 20, 30, 40, 50, 60); addBarrier(region11, 10, 20, 30, 40, 50, 60);
fillCatalogFamily(region11);
RegionInfo region12 = RegionInfo region12 =
RegionInfoBuilder.newBuilder(tableName1).setStartKey(Bytes.toBytes(1)).build(); RegionInfoBuilder.newBuilder(tableName1).setStartKey(Bytes.toBytes(1)).build();
addBarrier(region12, 20, 30, 40, 50, 60, 70); addBarrier(region12, 20, 30, 40, 50, 60, 70);
fillCatalogFamily(region12);
TableName tableName2 = TableName.valueOf(name.getMethodName() + "_2"); TableName tableName2 = TableName.valueOf(name.getMethodName() + "_2");
RegionInfo region21 = RegionInfo region21 =
RegionInfoBuilder.newBuilder(tableName2).setEndKey(Bytes.toBytes(1)).build(); RegionInfoBuilder.newBuilder(tableName2).setEndKey(Bytes.toBytes(1)).build();
addBarrier(region21, 100, 200, 300, 400); addBarrier(region21, 100, 200, 300, 400);
fillCatalogFamily(region21);
RegionInfo region22 = RegionInfo region22 =
RegionInfoBuilder.newBuilder(tableName2).setStartKey(Bytes.toBytes(1)).build(); RegionInfoBuilder.newBuilder(tableName2).setStartKey(Bytes.toBytes(1)).build();
addBarrier(region22, 200, 300, 400, 500, 600); addBarrier(region22, 200, 300, 400, 500, 600);
fillCatalogFamily(region22);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ReplicationPeerManager peerManager = ReplicationPeerManager peerManager =
@ -285,6 +289,25 @@ public class TestReplicationBarrierCleaner {
Arrays.asList(region.getEncodedName())); Arrays.asList(region.getEncodedName()));
} }
@Test
public void testDeleteRowForDeletedRegionNoPeers() throws IOException {
TableName tableName = TableName.valueOf(name.getMethodName());
RegionInfo region = RegionInfoBuilder.newBuilder(tableName).build();
addBarrier(region, 40, 50, 60);
ReplicationPeerManager peerManager = mock(ReplicationPeerManager.class);
ReplicationBarrierCleaner cleaner = create(peerManager);
cleaner.chore();
verify(peerManager, times(1)).getSerialPeerIdsBelongsTo(tableName);
// There are no peers, and no catalog family for this region either, so we should remove the
// barriers. And since there is no catalog family, after we delete the barrier family, the whole
// row is deleted.
try (Table table = UTIL.getConnection().getTable(TableName.META_TABLE_NAME)) {
assertFalse(table.exists(new Get(region.getRegionName())));
}
}
private static class WarnOnlyStoppable implements Stoppable { private static class WarnOnlyStoppable implements Stoppable {
@Override @Override
public void stop(String why) { public void stop(String why) {