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 a81c82a..05891df 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 @@ -1067,81 +1067,6 @@ public class HTableDescriptor implements Comparable { } /** - * 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 diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 6fb448b..5150194 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -26,6 +26,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -4083,6 +4084,77 @@ public class HBaseAdmin implements Admin { } /** + * 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 peerHtd descriptor on peer cluster + * @param localHtd - The HTableDescriptor of table from source cluster. + * @return true If the name of table and column families match and REPLICATION_SCOPE copied + * successfully. false If there is any mismatch in the names. + */ + private boolean copyReplicationScope(final HTableDescriptor peerHtd, + final HTableDescriptor localHtd) { + // Copy the REPLICATION_SCOPE only when table names and the names of + // Column-Families are same. + int result = peerHtd.getTableName().compareTo(localHtd.getTableName()); + + if (result == 0) { + Iterator remoteHCDIter = peerHtd.getFamilies().iterator(); + Iterator localHCDIter = localHtd.getFamilies().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; + } + } + if (remoteHCDIter.hasNext() || localHCDIter.hasNext()) { + return false; + } + } + + return result == 0; + } + + /** + * 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 peerHtd descriptor on peer cluster + * @param localHtd 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) + */ + private boolean compareForReplication(HTableDescriptor peerHtd, HTableDescriptor localHtd) { + if (peerHtd == localHtd) { + return true; + } + if (peerHtd == null) { + 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(peerHtd); + + result = copyReplicationScope(peerHtdCopy, localHtd); + + // If copy was successful, compare the two tables now. + if (result) { + result = (peerHtdCopy.compareTo(localHtd) == 0); + } + + return result; + } + + /** * Connect to peer and check the table descriptor on peer: *
    *
  1. Create the same table on peer when not exist.
  2. @@ -4125,7 +4197,7 @@ public class HBaseAdmin implements Admin { throw new IllegalArgumentException("Table " + tableName.getNameAsString() + " has replication already enabled for at least one Column Family."); } else { - if (!peerHtd.compareForReplication(localHtd)) { + if (!compareForReplication(peerHtd, localHtd)) { throw new IllegalArgumentException("Table " + tableName.getNameAsString() + " exists in peer cluster " + peerDesc.getPeerId() + ", but the table descriptors are not same when compared with source cluster."