From a053deadd3b24cd432c72a6a7353971781027f49 Mon Sep 17 00:00:00 2001 From: Ashish Singhi Date: Fri, 4 Mar 2016 15:21:22 +0530 Subject: [PATCH] HBASE-15393 Enable table replication command will fail when parent znode is not /hbase(default) in peer cluster --- .../hbase/client/replication/ReplicationAdmin.java | 45 +++++++--------------- .../client/replication/TestReplicationAdmin.java | 2 +- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java index c2e7489..00b248c 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java @@ -18,6 +18,9 @@ */ package org.apache.hadoop.hbase.client.replication; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.Lists; + import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; @@ -54,11 +57,6 @@ import org.apache.hadoop.hbase.replication.ReplicationPeers; import org.apache.hadoop.hbase.replication.ReplicationQueuesClient; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.data.Stat; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; /** *

@@ -187,7 +185,7 @@ public class ReplicationAdmin implements Closeable { this.replicationPeers.addPeer(id, new ReplicationPeerConfig().setClusterKey(clusterKey), tableCFs); } - + /** * Add a new remote slave cluster for replication. * @param id a short name that identifies the cluster @@ -595,13 +593,13 @@ public class ReplicationAdmin implements Closeable { */ private void checkAndSyncTableDescToPeers(final TableName tableName, final byte[][] splits) throws IOException { - List repPeers = listValidReplicationPeers(); + List repPeers = listReplicationPeer(); if (repPeers == null || repPeers.size() <= 0) { throw new IllegalArgumentException("Found no peer cluster for replication."); } - + final TableName onlyTableNameQualifier = TableName.valueOf(tableName.getQualifierAsString()); - + for (ReplicationPeer repPeer : repPeers) { Map> tableCFMap = repPeer.getTableCFs(); // TODO Currently peer TableCFs will not include namespace so we need to check only for table @@ -636,46 +634,29 @@ public class ReplicationAdmin implements Closeable { } @VisibleForTesting - List listValidReplicationPeers() { + List listReplicationPeer() { Map peers = listPeerConfigs(); if (peers == null || peers.size() <= 0) { return null; } - List validPeers = new ArrayList(peers.size()); + List listOfPeer = new ArrayList(peers.size()); for (Entry peerEntry : peers.entrySet()) { String peerId = peerEntry.getKey(); - Stat s = null; try { Pair pair = this.replicationPeers.getPeerConf(peerId); Configuration peerConf = pair.getSecond(); ReplicationPeer peer = new ReplicationPeerZKImpl(peerConf, peerId, pair.getFirst(), parseTableCFsFromConfig(this.getPeerTableCFs(peerId))); - s = - zkw.getRecoverableZooKeeper().exists(peerConf.get(HConstants.ZOOKEEPER_ZNODE_PARENT), - null); - if (null == s) { - LOG.info(peerId + ' ' + pair.getFirst().getClusterKey() + " is invalid now."); - continue; - } - validPeers.add(peer); + listOfPeer.add(peer); } catch (ReplicationException e) { LOG.warn("Failed to get valid replication peers. " - + "Error connecting to peer cluster with peerId=" + peerId); - LOG.debug("Failure details to get valid replication peers.", e); - continue; - } catch (KeeperException e) { - LOG.warn("Failed to get valid replication peers. KeeperException code=" - + e.code().intValue()); - LOG.debug("Failure details to get valid replication peers.", e); - continue; - } catch (InterruptedException e) { - LOG.warn("Failed to get valid replication peers due to InterruptedException."); + + "Error connecting to peer cluster with peerId=" + peerId + ". Error message=" + + e.getMessage()); LOG.debug("Failure details to get valid replication peers.", e); - Thread.currentThread().interrupt(); continue; } } - return validPeers; + return listOfPeer; } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java index e18220d..d7d9579 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java @@ -136,7 +136,7 @@ public class TestReplicationAdmin { config.getConfiguration().put("key2", "value2"); admin.addPeer(ID_ONE, config, null); - List peers = admin.listValidReplicationPeers(); + List peers = admin.listReplicationPeer(); assertEquals(1, peers.size()); ReplicationPeer peerOne = peers.get(0); assertNotNull(peerOne); -- 1.9.2.msysgit.0