Search in sources :

Example 1 with ERROR_CODE

use of org.apache.hadoop.hbase.util.HbckErrorReporter.ERROR_CODE in project hbase by apache.

the class TestHBaseFsckReplication method test.

@Test
public void test() throws Exception {
    ReplicationPeerStorage peerStorage = ReplicationStorageFactory.getReplicationPeerStorage(UTIL.getZooKeeperWatcher(), UTIL.getConfiguration());
    ReplicationQueueStorage queueStorage = ReplicationStorageFactory.getReplicationQueueStorage(UTIL.getZooKeeperWatcher(), UTIL.getConfiguration());
    String peerId1 = "1";
    String peerId2 = "2";
    peerStorage.addPeer(peerId1, ReplicationPeerConfig.newBuilder().setClusterKey("key").build(), true, SyncReplicationState.NONE);
    peerStorage.addPeer(peerId2, ReplicationPeerConfig.newBuilder().setClusterKey("key").build(), true, SyncReplicationState.NONE);
    for (int i = 0; i < 10; i++) {
        queueStorage.addWAL(ServerName.valueOf("localhost", 10000 + i, 100000 + i), peerId1, "file-" + i);
    }
    queueStorage.addWAL(ServerName.valueOf("localhost", 10000, 100000), peerId2, "file");
    HBaseFsck fsck = HbckTestingUtil.doFsck(UTIL.getConfiguration(), true);
    HbckTestingUtil.assertNoErrors(fsck);
    // should not remove anything since the replication peer is still alive
    assertEquals(10, queueStorage.getListOfReplicators().size());
    peerStorage.removePeer(peerId1);
    // there should be orphan queues
    assertEquals(10, queueStorage.getListOfReplicators().size());
    fsck = HbckTestingUtil.doFsck(UTIL.getConfiguration(), false);
    HbckTestingUtil.assertErrors(fsck, Stream.generate(() -> {
        return ERROR_CODE.UNDELETED_REPLICATION_QUEUE;
    }).limit(10).toArray(ERROR_CODE[]::new));
    // should not delete anything when fix is false
    assertEquals(10, queueStorage.getListOfReplicators().size());
    fsck = HbckTestingUtil.doFsck(UTIL.getConfiguration(), true);
    HbckTestingUtil.assertErrors(fsck, Stream.generate(() -> {
        return ERROR_CODE.UNDELETED_REPLICATION_QUEUE;
    }).limit(10).toArray(ERROR_CODE[]::new));
    List<ServerName> replicators = queueStorage.getListOfReplicators();
    // should not remove the server with queue for peerId2
    assertEquals(1, replicators.size());
    assertEquals(ServerName.valueOf("localhost", 10000, 100000), replicators.get(0));
    for (String queueId : queueStorage.getAllQueues(replicators.get(0))) {
        assertEquals(peerId2, queueId);
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage) ReplicationPeerStorage(org.apache.hadoop.hbase.replication.ReplicationPeerStorage) ERROR_CODE(org.apache.hadoop.hbase.util.HbckErrorReporter.ERROR_CODE) Test(org.junit.Test)

Aggregations

ServerName (org.apache.hadoop.hbase.ServerName)1 ReplicationPeerStorage (org.apache.hadoop.hbase.replication.ReplicationPeerStorage)1 ReplicationQueueStorage (org.apache.hadoop.hbase.replication.ReplicationQueueStorage)1 ERROR_CODE (org.apache.hadoop.hbase.util.HbckErrorReporter.ERROR_CODE)1 Test (org.junit.Test)1