Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3BA0E200C29 for ; Tue, 14 Feb 2017 01:01:33 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3A03E160B6C; Tue, 14 Feb 2017 00:01:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5C520160B60 for ; Tue, 14 Feb 2017 01:01:32 +0100 (CET) Received: (qmail 32215 invoked by uid 500); 14 Feb 2017 00:01:31 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 32206 invoked by uid 99); 14 Feb 2017 00:01:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Feb 2017 00:01:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1BF05DFC2F; Tue, 14 Feb 2017 00:01:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tedyu@apache.org To: commits@hbase.apache.org Message-Id: <77c1660b1a2347a2be9c732c97d3773c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-17460 enable_table_replication can not perform cyclic replication of a table - revert due to failure in testEnableReplicationWhenSlaveClusterDoesntHaveTable Date: Tue, 14 Feb 2017 00:01:31 +0000 (UTC) archived-at: Tue, 14 Feb 2017 00:01:33 -0000 Repository: hbase Updated Branches: refs/heads/branch-1 eb889f6a4 -> 2ac0c3b6d HBASE-17460 enable_table_replication can not perform cyclic replication of a table - revert due to failure in testEnableReplicationWhenSlaveClusterDoesntHaveTable Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/2ac0c3b6 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/2ac0c3b6 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/2ac0c3b6 Branch: refs/heads/branch-1 Commit: 2ac0c3b6daba835e064d67942b9ceb67065beafe Parents: eb889f6 Author: tedyu Authored: Mon Feb 13 16:01:25 2017 -0800 Committer: tedyu Committed: Mon Feb 13 16:01:25 2017 -0800 ---------------------------------------------------------------------- .../apache/hadoop/hbase/HColumnDescriptor.java | 2 +- .../apache/hadoop/hbase/HTableDescriptor.java | 100 ------------------- .../client/replication/ReplicationAdmin.java | 41 +++----- 3 files changed, 13 insertions(+), 130 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/2ac0c3b6/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java index 94899e3..3b2e99c 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HColumnDescriptor.java @@ -1386,7 +1386,7 @@ public class HColumnDescriptor implements WritableComparable public int compareTo(HColumnDescriptor o) { int result = Bytes.compareTo(this.name, o.getName()); if (result == 0) { - // punt on comparison for ordering, just calculate difference. + // punt on comparison for ordering, just calculate difference result = this.values.hashCode() - o.values.hashCode(); if (result < 0) result = -1; http://git-wip-us.apache.org/repos/asf/hbase/blob/2ac0c3b6/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java index ea920b4..4f3ac9c 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java @@ -1064,106 +1064,6 @@ public class HTableDescriptor implements WritableComparable { } /** - * Detects whether replication has been already enabled on any of the column families of this - * table descriptor. - * @return true if any of the column families has replication enabled. - */ - public boolean isReplicationEnabled() { - // Go through each Column-Family descriptor and check if the - // Replication has been enabled already. - // Return 'true' if replication has been enabled on any CF, - // otherwise return 'false'. - // - boolean result = false; - Iterator it = this.families.values().iterator(); - - while (it.hasNext()) { - HColumnDescriptor tempHcd = it.next(); - if (tempHcd.getScope() != HConstants.REPLICATION_SCOPE_LOCAL) { - result = true; - break; - } - } - - return result; - } - - /** - * Compare the contents of the descriptor with another one passed as a parameter for replication - * purpose. The REPLICATION_SCOPE field is ignored during comparison. - * @param obj descriptor on source cluster which needs to be replicated. - * @return true if the contents of the two descriptors match (ignoring just REPLICATION_SCOPE). - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean compareForReplication(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof HTableDescriptor)) { - return false; - } - - boolean result = false; - - // Create a copy of peer HTD as we need to change its replication - // scope to match with the local HTD. - HTableDescriptor peerHtdCopy = new HTableDescriptor(this); - - // Copy the replication scope of local Htd to remote Htd. - HTableDescriptor localHtd = (HTableDescriptor) obj; - - result = (peerHtdCopy.copyReplicationScope(localHtd) == 0); - - // If copy was successful, compare the two tables now. - if (result == true) { - result = (peerHtdCopy.compareTo(localHtd) == 0); - } - - return result; - } - - /** - * Copies the REPLICATION_SCOPE of table descriptor passed as an argument. Before copy, the method - * ensures that the name of table and column-families should match. - * @param localHtd - The HTableDescriptor of table from source cluster. - * @return 0 If the name of table and column families match and REPLICATION_SCOPE copied - * successfully. 1 If there is any mismatch in the names. - */ - public int copyReplicationScope(final HTableDescriptor localHtd) - { - // Copy the REPLICATION_SCOPE only when table names and the names of - // Column-Families are same. - int result = this.name.compareTo(localHtd.name); - - if (result == 0) { - Iterator remoteHCDIter = families.values().iterator(); - Iterator localHCDIter = localHtd.families.values().iterator(); - - while (remoteHCDIter.hasNext() && localHCDIter.hasNext()) { - HColumnDescriptor remoteHCD = remoteHCDIter.next(); - HColumnDescriptor localHCD = localHCDIter.next(); - - String remoteHCDName = remoteHCD.getNameAsString(); - String localHCDName = localHCD.getNameAsString(); - - if (remoteHCDName.equals(localHCDName)) - { - remoteHCD.setScope(localHCD.getScope()); - } - else { - result = -1; - break; - } - } - } - - return result; - } - - /** * @see java.lang.Object#hashCode() */ @Override http://git-wip-us.apache.org/repos/asf/hbase/blob/2ac0c3b6/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java ---------------------------------------------------------------------- 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 1fa7709..d462f38 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; @@ -51,9 +54,6 @@ import org.apache.hadoop.hbase.replication.ReplicationSerDeHelper; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; - /** *

* This class provides the administrative interface to HBase cluster @@ -560,9 +560,7 @@ public class ReplicationAdmin implements Closeable { * Connect to peer and check the table descriptor on peer: *

    *
  1. Create the same table on peer when not exist.
  2. - *
  3. Throw an exception if the table already has replication enabled on any of the column - * families.
  4. - *
  5. Throw an exception if the table exists on peer cluster but descriptors are not same.
  6. + *
  7. Throw exception if the table exists on peer cluster but descriptors are not same.
  8. *
* @param tableName name of the table to sync to the peer * @param splits table split keys @@ -586,39 +584,24 @@ public class ReplicationAdmin implements Closeable { } Configuration peerConf = repPeer.getConfiguration(); - - HTableDescriptor localHtd = null; + HTableDescriptor htd = null; try (Connection conn = ConnectionFactory.createConnection(peerConf); Admin admin = this.connection.getAdmin(); Admin repHBaseAdmin = conn.getAdmin()) { - localHtd = admin.getTableDescriptor(tableName); + htd = admin.getTableDescriptor(tableName); HTableDescriptor peerHtd = null; if (!repHBaseAdmin.tableExists(tableName)) { - repHBaseAdmin.createTable(localHtd, splits); + repHBaseAdmin.createTable(htd, splits); } else { peerHtd = repHBaseAdmin.getTableDescriptor(tableName); if (peerHtd == null) { throw new IllegalArgumentException("Failed to get table descriptor for table " + tableName.getNameAsString() + " from peer cluster " + repPeer.getId()); - } else { - // To support cyclic replication (HBASE-17460), we need to match the - // REPLICATION_SCOPE of table on both the clusters. We should do this - // only when the replication is not already enabled on local HTD (local - // table on this cluster). - // - if (localHtd.isReplicationEnabled()) { - throw new IllegalArgumentException("Table " + tableName.getNameAsString() - + " has replication already enabled for atleast one Column Family."); - } - else - { - if (!peerHtd.compareForReplication(localHtd)) { - throw new IllegalArgumentException("Table " + tableName.getNameAsString() - + " exists in peer cluster " + repPeer.getId() - + ", but the table descriptors are not same when compared with source cluster." - + " Thus can not enable the table's replication switch."); - } - } + } else if (!peerHtd.equals(htd)) { + throw new IllegalArgumentException("Table " + tableName.getNameAsString() + + " exists in peer cluster " + repPeer.getId() + + ", but the table descriptors are not same when compared with source cluster." + + " Thus can not enable the table's replication switch."); } } }