Search in sources :

Example 1 with ReplicationPeerStorage

use of org.apache.hadoop.hbase.replication.ReplicationPeerStorage in project hbase by apache.

the class ReplicationPeerManager method create.

public static ReplicationPeerManager create(ZKWatcher zk, Configuration conf, String clusterId) throws ReplicationException {
    ReplicationPeerStorage peerStorage = ReplicationStorageFactory.getReplicationPeerStorage(zk, conf);
    ConcurrentMap<String, ReplicationPeerDescription> peers = new ConcurrentHashMap<>();
    for (String peerId : peerStorage.listPeerIds()) {
        ReplicationPeerConfig peerConfig = peerStorage.getPeerConfig(peerId);
        if (ReplicationUtils.LEGACY_REGION_REPLICATION_ENDPOINT_NAME.equals(peerConfig.getReplicationEndpointImpl())) {
            // we do not use this endpoint for region replication any more, see HBASE-26233
            LOG.info("Legacy region replication peer found, removing: {}", peerConfig);
            peerStorage.removePeer(peerId);
            continue;
        }
        peerConfig = ReplicationPeerConfigUtil.updateReplicationBasePeerConfigs(conf, peerConfig);
        peerStorage.updatePeerConfig(peerId, peerConfig);
        boolean enabled = peerStorage.isPeerEnabled(peerId);
        SyncReplicationState state = peerStorage.getPeerSyncReplicationState(peerId);
        peers.put(peerId, new ReplicationPeerDescription(peerId, enabled, peerConfig, state));
    }
    return new ReplicationPeerManager(peerStorage, ReplicationStorageFactory.getReplicationQueueStorage(zk, conf), peers, conf, clusterId);
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) SyncReplicationState(org.apache.hadoop.hbase.replication.SyncReplicationState) ReplicationPeerDescription(org.apache.hadoop.hbase.replication.ReplicationPeerDescription) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ReplicationPeerStorage(org.apache.hadoop.hbase.replication.ReplicationPeerStorage)

Example 2 with ReplicationPeerStorage

use of org.apache.hadoop.hbase.replication.ReplicationPeerStorage in project hbase by apache.

the class VerifyReplication method getPeerQuorumConfig.

private static Pair<ReplicationPeerConfig, Configuration> getPeerQuorumConfig(final Configuration conf, String peerId) throws IOException {
    ZKWatcher localZKW = null;
    try {
        localZKW = new ZKWatcher(conf, "VerifyReplication", new Abortable() {

            @Override
            public void abort(String why, Throwable e) {
            }

            @Override
            public boolean isAborted() {
                return false;
            }
        });
        ReplicationPeerStorage storage = ReplicationStorageFactory.getReplicationPeerStorage(localZKW, conf);
        ReplicationPeerConfig peerConfig = storage.getPeerConfig(peerId);
        return Pair.newPair(peerConfig, ReplicationUtils.getPeerClusterConfiguration(peerConfig, conf));
    } catch (ReplicationException e) {
        throw new IOException("An error occurred while trying to connect to the remote peer cluster", e);
    } finally {
        if (localZKW != null) {
            localZKW.close();
        }
    }
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) Abortable(org.apache.hadoop.hbase.Abortable) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) IOException(java.io.IOException) ReplicationPeerStorage(org.apache.hadoop.hbase.replication.ReplicationPeerStorage)

Example 3 with ReplicationPeerStorage

use of org.apache.hadoop.hbase.replication.ReplicationPeerStorage 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

ReplicationPeerStorage (org.apache.hadoop.hbase.replication.ReplicationPeerStorage)3 ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)2 IOException (java.io.IOException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Abortable (org.apache.hadoop.hbase.Abortable)1 ServerName (org.apache.hadoop.hbase.ServerName)1 ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)1 ReplicationPeerDescription (org.apache.hadoop.hbase.replication.ReplicationPeerDescription)1 ReplicationQueueStorage (org.apache.hadoop.hbase.replication.ReplicationQueueStorage)1 SyncReplicationState (org.apache.hadoop.hbase.replication.SyncReplicationState)1 ERROR_CODE (org.apache.hadoop.hbase.util.HbckErrorReporter.ERROR_CODE)1 ZKWatcher (org.apache.hadoop.hbase.zookeeper.ZKWatcher)1 Test (org.junit.Test)1