From 001bce54e7835fd1877bec1976b227dfab45e2e3 Mon Sep 17 00:00:00 2001 From: Guanghao Zhang Date: Fri, 22 Dec 2017 12:02:19 +0800 Subject: [PATCH] HBASE-19590 Remove the duplicate code in deprecated ReplicationAdmin --- .../client/replication/ReplicationAdmin.java | 103 +----------------- .../replication/TestReplicationAdmin.java | 2 +- 2 files changed, 3 insertions(+), 102 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 a5081cb7be5..78d4fbbdf2c 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 @@ -23,10 +23,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.TreeMap; import java.util.regex.Pattern; @@ -44,7 +42,6 @@ import org.apache.hadoop.hbase.replication.ReplicationException; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting; -import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; /** *

@@ -131,8 +128,6 @@ public class ReplicationAdmin implements Closeable { @Deprecated public void addPeer(String id, ReplicationPeerConfig peerConfig) throws ReplicationException, IOException { - checkNamespacesAndTableCfsConfigConflict(peerConfig.getNamespaces(), - peerConfig.getTableCFsMap()); this.admin.addReplicationPeer(id, peerConfig); } @@ -256,36 +251,7 @@ public class ReplicationAdmin implements Closeable { @Deprecated public void appendPeerTableCFs(String id, Map> tableCfs) throws ReplicationException, IOException { - if (tableCfs == null) { - throw new ReplicationException("tableCfs is null"); - } - ReplicationPeerConfig peerConfig = admin.getReplicationPeerConfig(id); - Map> preTableCfs = peerConfig.getTableCFsMap(); - if (preTableCfs == null) { - setPeerTableCFs(id, tableCfs); - return; - } - for (Map.Entry> entry : tableCfs.entrySet()) { - TableName table = entry.getKey(); - Collection appendCfs = entry.getValue(); - if (preTableCfs.containsKey(table)) { - List cfs = preTableCfs.get(table); - if (cfs == null || appendCfs == null || appendCfs.isEmpty()) { - preTableCfs.put(table, null); - } else { - Set cfSet = new HashSet<>(cfs); - cfSet.addAll(appendCfs); - preTableCfs.put(table, Lists.newArrayList(cfSet)); - } - } else { - if (appendCfs == null || appendCfs.isEmpty()) { - preTableCfs.put(table, null); - } else { - preTableCfs.put(table, Lists.newArrayList(appendCfs)); - } - } - } - updatePeerConfig(id, peerConfig); + this.admin.appendReplicationPeerTableCFs(id, tableCfs); } /** @@ -313,42 +279,7 @@ public class ReplicationAdmin implements Closeable { @Deprecated public void removePeerTableCFs(String id, Map> tableCfs) throws ReplicationException, IOException { - if (tableCfs == null) { - throw new ReplicationException("tableCfs is null"); - } - ReplicationPeerConfig peerConfig = admin.getReplicationPeerConfig(id); - Map> preTableCfs = peerConfig.getTableCFsMap(); - if (preTableCfs == null) { - throw new ReplicationException("Table-Cfs for peer" + id + " is null"); - } - for (Map.Entry> entry: tableCfs.entrySet()) { - - TableName table = entry.getKey(); - Collection removeCfs = entry.getValue(); - if (preTableCfs.containsKey(table)) { - List cfs = preTableCfs.get(table); - if (cfs == null && (removeCfs == null || removeCfs.isEmpty())) { - preTableCfs.remove(table); - } else if (cfs != null && (removeCfs != null && !removeCfs.isEmpty())) { - Set cfSet = new HashSet<>(cfs); - cfSet.removeAll(removeCfs); - if (cfSet.isEmpty()) { - preTableCfs.remove(table); - } else { - preTableCfs.put(table, Lists.newArrayList(cfSet)); - } - } else if (cfs == null && (removeCfs != null && !removeCfs.isEmpty())) { - throw new ReplicationException("Cannot remove cf of table: " + table - + " which doesn't specify cfs from table-cfs config in peer: " + id); - } else if (cfs != null && (removeCfs == null || removeCfs.isEmpty())) { - throw new ReplicationException("Cannot remove table: " + table - + " which has specified cfs from table-cfs config in peer: " + id); - } - } else { - throw new ReplicationException("No table: " + table + " in table-cfs config of peer: " + id); - } - } - updatePeerConfig(id, peerConfig); + this.admin.removeReplicationPeerTableCFs(id, tableCfs); } /** @@ -455,34 +386,4 @@ public class ReplicationAdmin implements Closeable { List listReplicationPeers() throws IOException { return admin.listReplicationPeers(); } - - /** - * Set a namespace in the peer config means that all tables in this namespace - * will be replicated to the peer cluster. - * - * 1. If you already have set a namespace in the peer config, then you can't set any table - * of this namespace to the peer config. - * 2. If you already have set a table in the peer config, then you can't set this table's - * namespace to the peer config. - * - * @param namespaces - * @param tableCfs - * @throws ReplicationException - */ - private void checkNamespacesAndTableCfsConfigConflict(Set namespaces, - Map> tableCfs) throws ReplicationException { - if (namespaces == null || namespaces.isEmpty()) { - return; - } - if (tableCfs == null || tableCfs.isEmpty()) { - return; - } - for (Map.Entry> entry : tableCfs.entrySet()) { - TableName table = entry.getKey(); - if (namespaces.contains(table.getNamespaceAsString())) { - throw new ReplicationException( - "Table-cfs config conflict with namespaces config in peer"); - } - } - } } 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 67c635b9f7d..87702992627 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 @@ -748,4 +748,4 @@ public class TestReplicationAdmin { assertEquals(2097152, admin.getPeerConfig(ID_ONE).getBandwidth()); admin.removePeer(ID_ONE); } -} +} \ No newline at end of file