diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 1f143b5..28ebc91 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -4233,7 +4233,8 @@ public class HBaseAdmin implements Admin { */ private void setTableRep(final TableName tableName, boolean isRepEnabled) throws IOException { HTableDescriptor htd = getTableDescriptor(tableName); - if (isTableRepEnabled(htd) ^ isRepEnabled) { + if (isRepEnabled && isTableRepEnabled(htd) != ReplicationState.ENABLED + || !isRepEnabled && isTableRepEnabled(htd) != ReplicationState.DISABLED) { for (HColumnDescriptor hcd : htd.getFamilies()) { hcd.setScope(isRepEnabled ? HConstants.REPLICATION_SCOPE_GLOBAL : HConstants.REPLICATION_SCOPE_LOCAL); @@ -4243,17 +4244,34 @@ public class HBaseAdmin implements Admin { } /** + * This enum indicates the current state of the replication for a given table. + */ + private enum ReplicationState { + ENABLED, // all column families enabled + MIXED, // some column families enabled, some disabled + DISABLED // all column families disabled + } + + /** * @param htd table descriptor details for the table to check - * @return true if table's replication switch is enabled + * @return ReplicationState the current state of the table. */ - private boolean isTableRepEnabled(HTableDescriptor htd) { + private ReplicationState isTableRepEnabled(HTableDescriptor htd) { + boolean hasEnabled = false; + boolean hasDisabled = false; + for (HColumnDescriptor hcd : htd.getFamilies()) { if (hcd.getScope() != HConstants.REPLICATION_SCOPE_GLOBAL && hcd.getScope() != HConstants.REPLICATION_SCOPE_SERIAL) { - return false; + hasDisabled = true; + } else { + hasEnabled = true; } } - return true; + + if (hasEnabled && hasDisabled) return ReplicationState.MIXED; + if (hasEnabled) return ReplicationState.ENABLED; + return ReplicationState.DISABLED; } /** diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdminWithClusters.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdminWithClusters.java index b44ecbf..312a90a 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdminWithClusters.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdminWithClusters.java @@ -76,6 +76,23 @@ public class TestReplicationAdminWithClusters extends TestReplicationBase { } @Test(timeout = 300000) + public void disableNotFullReplication() throws Exception { + HTableDescriptor table = admin2.getTableDescriptor(tableName); + HColumnDescriptor f = new HColumnDescriptor("notReplicatedFamily"); + table.addFamily(f); + admin1.disableTable(tableName); + admin1.modifyTable(tableName, table); + admin1.enableTable(tableName); + + + admin1.disableTableReplication(tableName); + table = admin1.getTableDescriptor(tableName); + for (HColumnDescriptor fam : table.getColumnFamilies()) { + assertEquals(fam.getScope(), HConstants.REPLICATION_SCOPE_LOCAL); + } + } + + @Test(timeout = 300000) public void testEnableReplicationWhenSlaveClusterDoesntHaveTable() throws Exception { admin1.disableTableReplication(tableName); admin2.disableTable(tableName);