Search in sources :

Example 1 with ReplicationPeerManager

use of org.apache.hadoop.hbase.master.replication.ReplicationPeerManager in project hbase by apache.

the class TestReplicationBarrierCleaner method testCleanNoPeers.

@Test
public void testCleanNoPeers() throws IOException {
    TableName tableName1 = TableName.valueOf(name.getMethodName() + "_1");
    RegionInfo region11 = RegionInfoBuilder.newBuilder(tableName1).setEndKey(Bytes.toBytes(1)).build();
    addBarrier(region11, 10, 20, 30, 40, 50, 60);
    fillCatalogFamily(region11);
    RegionInfo region12 = RegionInfoBuilder.newBuilder(tableName1).setStartKey(Bytes.toBytes(1)).build();
    addBarrier(region12, 20, 30, 40, 50, 60, 70);
    fillCatalogFamily(region12);
    TableName tableName2 = TableName.valueOf(name.getMethodName() + "_2");
    RegionInfo region21 = RegionInfoBuilder.newBuilder(tableName2).setEndKey(Bytes.toBytes(1)).build();
    addBarrier(region21, 100, 200, 300, 400);
    fillCatalogFamily(region21);
    RegionInfo region22 = RegionInfoBuilder.newBuilder(tableName2).setStartKey(Bytes.toBytes(1)).build();
    addBarrier(region22, 200, 300, 400, 500, 600);
    fillCatalogFamily(region22);
    @SuppressWarnings("unchecked") ReplicationPeerManager peerManager = create(null, Collections.emptyList(), Collections.emptyList());
    ReplicationBarrierCleaner cleaner = create(peerManager);
    cleaner.chore();
    // should never call this method
    verify(peerManager, never()).getQueueStorage();
    // should only be called twice although we have 4 regions to clean
    verify(peerManager, times(2)).getSerialPeerIdsBelongsTo(any(TableName.class));
    assertArrayEquals(new long[] { 60 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region11.getRegionName()));
    assertArrayEquals(new long[] { 70 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region12.getRegionName()));
    assertArrayEquals(new long[] { 400 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region21.getRegionName()));
    assertArrayEquals(new long[] { 600 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region22.getRegionName()));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerManager(org.apache.hadoop.hbase.master.replication.ReplicationPeerManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Example 2 with ReplicationPeerManager

use of org.apache.hadoop.hbase.master.replication.ReplicationPeerManager in project hbase by apache.

the class TestReplicationBarrierCleaner method testDeleteBarriers.

@Test
public void testDeleteBarriers() throws IOException, ReplicationException {
    TableName tableName = TableName.valueOf(name.getMethodName());
    RegionInfo region = RegionInfoBuilder.newBuilder(tableName).build();
    addBarrier(region, 10, 20, 30, 40, 50, 60);
    // two peers
    ReplicationQueueStorage queueStorage = create(-1L, 2L, 15L, 25L, 20L, 25L, 65L, 55L, 70L, 70L);
    List<String> peerIds = Lists.newArrayList("1", "2");
    @SuppressWarnings("unchecked") ReplicationPeerManager peerManager = create(queueStorage, peerIds, peerIds, peerIds, peerIds, peerIds);
    ReplicationBarrierCleaner cleaner = create(peerManager);
    // beyond the first barrier, no deletion
    cleaner.chore();
    assertArrayEquals(new long[] { 10, 20, 30, 40, 50, 60 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region.getRegionName()));
    // in the first range, still no deletion
    cleaner.chore();
    assertArrayEquals(new long[] { 10, 20, 30, 40, 50, 60 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region.getRegionName()));
    // in the second range, 10 is deleted
    cleaner.chore();
    assertArrayEquals(new long[] { 20, 30, 40, 50, 60 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region.getRegionName()));
    // between 50 and 60, so the barriers before 50 will be deleted
    cleaner.chore();
    assertArrayEquals(new long[] { 50, 60 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region.getRegionName()));
    // in the last open range, 50 is deleted
    cleaner.chore();
    assertArrayEquals(new long[] { 60 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region.getRegionName()));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerManager(org.apache.hadoop.hbase.master.replication.ReplicationPeerManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage) Test(org.junit.Test)

Example 3 with ReplicationPeerManager

use of org.apache.hadoop.hbase.master.replication.ReplicationPeerManager in project hbase by apache.

the class TestReplicationBarrierCleaner method testNothing.

@Test
public void testNothing() throws IOException {
    ReplicationPeerManager peerManager = mock(ReplicationPeerManager.class);
    ReplicationBarrierCleaner cleaner = create(peerManager);
    cleaner.chore();
    verify(peerManager, never()).getSerialPeerIdsBelongsTo(any(TableName.class));
    verify(peerManager, never()).getQueueStorage();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ReplicationPeerManager(org.apache.hadoop.hbase.master.replication.ReplicationPeerManager) Test(org.junit.Test)

Example 4 with ReplicationPeerManager

use of org.apache.hadoop.hbase.master.replication.ReplicationPeerManager in project hbase by apache.

the class TestReplicationBarrierCleaner method testDeleteRowForDeletedRegionNoPeers.

@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);
    // row is deleted.
    try (Table table = UTIL.getConnection().getTable(TableName.META_TABLE_NAME)) {
        assertFalse(table.exists(new Get(region.getRegionName())));
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) ReplicationPeerManager(org.apache.hadoop.hbase.master.replication.ReplicationPeerManager) Get(org.apache.hadoop.hbase.client.Get) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Example 5 with ReplicationPeerManager

use of org.apache.hadoop.hbase.master.replication.ReplicationPeerManager in project hbase by apache.

the class TestReplicationBarrierCleaner method testDeleteRowForDeletedRegion.

@Test
public void testDeleteRowForDeletedRegion() throws IOException, ReplicationException {
    TableName tableName = TableName.valueOf(name.getMethodName());
    RegionInfo region = RegionInfoBuilder.newBuilder(tableName).build();
    addBarrier(region, 40, 50, 60);
    fillCatalogFamily(region);
    String peerId = "1";
    ReplicationQueueStorage queueStorage = create(59L);
    @SuppressWarnings("unchecked") ReplicationPeerManager peerManager = create(queueStorage, Lists.newArrayList(peerId));
    ReplicationBarrierCleaner cleaner = create(peerManager);
    // we have something in catalog family, so only delete 40
    cleaner.chore();
    assertArrayEquals(new long[] { 50, 60 }, ReplicationBarrierFamilyFormat.getReplicationBarriers(UTIL.getConnection(), region.getRegionName()));
    verify(queueStorage, never()).removeLastSequenceIds(anyString(), anyList());
    // No catalog family, then we should remove the whole row
    clearCatalogFamily(region);
    cleaner.chore();
    try (Table table = UTIL.getConnection().getTable(TableName.META_TABLE_NAME)) {
        assertFalse(table.exists(new Get(region.getRegionName()).addFamily(HConstants.REPLICATION_BARRIER_FAMILY)));
    }
    verify(queueStorage, times(1)).removeLastSequenceIds(peerId, Arrays.asList(region.getEncodedName()));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) ReplicationPeerManager(org.apache.hadoop.hbase.master.replication.ReplicationPeerManager) Get(org.apache.hadoop.hbase.client.Get) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage) Test(org.junit.Test)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)5 ReplicationPeerManager (org.apache.hadoop.hbase.master.replication.ReplicationPeerManager)5 Test (org.junit.Test)5 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)4 Get (org.apache.hadoop.hbase.client.Get)2 Table (org.apache.hadoop.hbase.client.Table)2 ReplicationQueueStorage (org.apache.hadoop.hbase.replication.ReplicationQueueStorage)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2