diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java index 2d3693ab023..e2804535e54 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/IntegrationTestDDLMasterFailover.java @@ -31,10 +31,14 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.client.TableDescriptor; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding; import org.apache.hadoop.hbase.testclassification.IntegrationTests; import org.apache.hadoop.hbase.util.Bytes; @@ -127,11 +131,11 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { ConcurrentHashMap namespaceMap = new ConcurrentHashMap<>(); - ConcurrentHashMap enabledTables = new ConcurrentHashMap<>(); + ConcurrentHashMap enabledTables = new ConcurrentHashMap<>(); - ConcurrentHashMap disabledTables = new ConcurrentHashMap<>(); + ConcurrentHashMap disabledTables = new ConcurrentHashMap<>(); - ConcurrentHashMap deletedTables = new ConcurrentHashMap<>(); + ConcurrentHashMap deletedTables = new ConcurrentHashMap<>(); @Override public void setUpCluster() throws Exception { @@ -384,7 +388,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { private abstract class TableAction extends MasterAction{ // TableAction has implemented selectTable() shared by multiple table Actions - protected HTableDescriptor selectTable(ConcurrentHashMap tableMap) + protected TableDescriptor selectTable(ConcurrentHashMap tableMap) { // synchronization to prevent removal from multiple threads synchronized (tableMap){ @@ -394,10 +398,8 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { } ArrayList tableList = new ArrayList<>(tableMap.keySet()); TableName randomKey = tableList.get(RandomUtils.nextInt(tableList.size())); - HTableDescriptor randomHtd = tableMap.get(randomKey); - // remove from tableMap - tableMap.remove(randomKey); - return randomHtd; + TableDescriptor randomTd = tableMap.remove(randomKey); + return randomTd; } } } @@ -408,8 +410,8 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { void perform() throws IOException { Admin admin = connection.getAdmin(); try { - HTableDescriptor htd = createTableDesc(); - TableName tableName = htd.getTableName(); + TableDescriptor td = createTableDesc(); + TableName tableName = td.getTableName(); if ( admin.tableExists(tableName)){ return; } @@ -417,10 +419,10 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { numRegions = getConf().getInt(numRegionKey, DEFAULT_NUM_REGIONS); byte[] startKey = Bytes.toBytes("row-0000000000"); byte[] endKey = Bytes.toBytes("row-" + Integer.MAX_VALUE); - LOG.info("Creating table:" + htd); - admin.createTable(htd, startKey, endKey, numRegions); - Assert.assertTrue("Table: " + htd + " was not created", admin.tableExists(tableName)); - HTableDescriptor freshTableDesc = admin.getTableDescriptor(tableName); + LOG.info("Creating table:" + td); + admin.createTable(td, startKey, endKey, numRegions); + Assert.assertTrue("Table: " + td + " was not created", admin.tableExists(tableName)); + TableDescriptor freshTableDesc = admin.listTableDescriptor(tableName); Assert.assertTrue( "After create, Table: " + tableName + " in not enabled", admin.isTableEnabled(tableName)); enabledTables.put(tableName, freshTableDesc); @@ -433,14 +435,12 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { } } - private HTableDescriptor createTableDesc() { - String tableName = "ittable-" + String.format("%010d", - RandomUtils.nextInt(Integer.MAX_VALUE)); + private TableDescriptor createTableDesc() { + String tableName = String.format("ittable-%010d", RandomUtils.nextInt(Integer.MAX_VALUE)); String familyName = "cf-" + Math.abs(RandomUtils.nextInt()); - HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName)); - // add random column family - htd.addFamily(new HColumnDescriptor(familyName)); - return htd; + return TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName)) + .addColumnFamily(ColumnFamilyDescriptorBuilder.of(familyName)) + .build(); } } @@ -449,7 +449,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { @Override void perform() throws IOException { - HTableDescriptor selected = selectTable(enabledTables); + TableDescriptor selected = selectTable(enabledTables); if (selected == null) { return; } @@ -461,7 +461,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { admin.disableTable(tableName); Assert.assertTrue("Table: " + selected + " was not disabled", admin.isTableDisabled(tableName)); - HTableDescriptor freshTableDesc = admin.getTableDescriptor(tableName); + TableDescriptor freshTableDesc = admin.listTableDescriptor(tableName); Assert.assertTrue( "After disable, Table: " + tableName + " is not disabled", admin.isTableDisabled(tableName)); @@ -498,7 +498,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { @Override void perform() throws IOException { - HTableDescriptor selected = selectTable(disabledTables); + TableDescriptor selected = selectTable(disabledTables); if (selected == null ) { return; } @@ -510,7 +510,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { admin.enableTable(tableName); Assert.assertTrue("Table: " + selected + " was not enabled", admin.isTableEnabled(tableName)); - HTableDescriptor freshTableDesc = admin.getTableDescriptor(tableName); + TableDescriptor freshTableDesc = admin.listTableDescriptor(tableName); Assert.assertTrue( "After enable, Table: " + tableName + " in not enabled", admin.isTableEnabled(tableName)); enabledTables.put(tableName, freshTableDesc); @@ -546,7 +546,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { @Override void perform() throws IOException { - HTableDescriptor selected = selectTable(disabledTables); + TableDescriptor selected = selectTable(disabledTables); if (selected == null) { return; } @@ -572,16 +572,16 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { private abstract class ColumnAction extends TableAction{ // ColumnAction has implemented selectFamily() shared by multiple family Actions - protected HColumnDescriptor selectFamily(HTableDescriptor htd) { - if (htd == null) { + protected ColumnFamilyDescriptor selectFamily(TableDescriptor td) { + if (td == null) { return null; } - HColumnDescriptor[] families = htd.getColumnFamilies(); + ColumnFamilyDescriptor[] families = td.getColumnFamilies(); if (families.length == 0){ - LOG.info("No column families in table: " + htd); + LOG.info("No column families in table: " + td); return null; } - HColumnDescriptor randomCfd = families[RandomUtils.nextInt(families.length)]; + ColumnFamilyDescriptor randomCfd = families[RandomUtils.nextInt(families.length)]; return randomCfd; } } @@ -590,26 +590,26 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { @Override void perform() throws IOException { - HTableDescriptor selected = selectTable(disabledTables); + TableDescriptor selected = selectTable(disabledTables); if (selected == null) { return; } Admin admin = connection.getAdmin(); try { - HColumnDescriptor cfd = createFamilyDesc(); - if (selected.hasFamily(cfd.getName())){ + ColumnFamilyDescriptor cfd = createFamilyDesc(); + if (selected.hasColumnFamily(cfd.getName())){ LOG.info(new String(cfd.getName()) + " already exists in table " + selected.getTableName()); return; } TableName tableName = selected.getTableName(); LOG.info("Adding column family: " + cfd + " to table: " + tableName); - admin.addColumn(tableName, cfd); + admin.addColumnFamily(tableName, cfd); // assertion - HTableDescriptor freshTableDesc = admin.getTableDescriptor(tableName); + TableDescriptor freshTableDesc = admin.listTableDescriptor(tableName); Assert.assertTrue("Column family: " + cfd + " was not added", - freshTableDesc.hasFamily(cfd.getName())); + freshTableDesc.hasColumnFamily(cfd.getName())); Assert.assertTrue( "After add column family, Table: " + tableName + " is not disabled", admin.isTableDisabled(tableName)); @@ -623,10 +623,9 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { } } - private HColumnDescriptor createFamilyDesc() { - String familyName = "cf-" + String.format("%010d", RandomUtils.nextInt(Integer.MAX_VALUE)); - HColumnDescriptor cfd = new HColumnDescriptor(familyName); - return cfd; + private ColumnFamilyDescriptor createFamilyDesc() { + String familyName = String.format("cf-%010d", RandomUtils.nextInt(Integer.MAX_VALUE)); + return ColumnFamilyDescriptorBuilder.of(familyName); } } @@ -634,11 +633,11 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { @Override void perform() throws IOException { - HTableDescriptor selected = selectTable(disabledTables); + TableDescriptor selected = selectTable(disabledTables); if (selected == null) { return; } - HColumnDescriptor columnDesc = selectFamily(selected); + ColumnFamilyDescriptor columnDesc = selectFamily(selected); if (columnDesc == null){ return; } @@ -649,12 +648,19 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { TableName tableName = selected.getTableName(); LOG.info("Altering versions of column family: " + columnDesc + " to: " + versions + " in table: " + tableName); - columnDesc.setMinVersions(versions); - columnDesc.setMaxVersions(versions); - admin.modifyTable(tableName, selected); + + ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(columnDesc) + .setMinVersions(versions) + .setMaxVersions(versions) + .build(); + TableDescriptor td = TableDescriptorBuilder.newBuilder(selected) + .modifyColumnFamily(cfd) + .build(); + admin.modifyTable(td); + // assertion - HTableDescriptor freshTableDesc = admin.getTableDescriptor(tableName); - HColumnDescriptor freshColumnDesc = freshTableDesc.getFamily(columnDesc.getName()); + TableDescriptor freshTableDesc = admin.listTableDescriptor(tableName); + ColumnFamilyDescriptor freshColumnDesc = freshTableDesc.getColumnFamily(columnDesc.getName()); Assert.assertEquals("Column family: " + columnDesc + " was not altered", freshColumnDesc.getMaxVersions(), versions); Assert.assertEquals("Column family: " + freshColumnDesc + " was not altered", @@ -678,11 +684,11 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { @Override void perform() throws IOException { - HTableDescriptor selected = selectTable(disabledTables); + TableDescriptor selected = selectTable(disabledTables); if (selected == null) { return; } - HColumnDescriptor columnDesc = selectFamily(selected); + ColumnFamilyDescriptor columnDesc = selectFamily(selected); if (columnDesc == null){ return; } @@ -695,11 +701,18 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { short id = (short) possibleIds[RandomUtils.nextInt(possibleIds.length)]; LOG.info("Altering encoding of column family: " + columnDesc + " to: " + id + " in table: " + tableName); - columnDesc.setDataBlockEncoding(DataBlockEncoding.getEncodingById(id)); - admin.modifyTable(tableName, selected); + + ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(columnDesc) + .setDataBlockEncoding(DataBlockEncoding.getEncodingById(id)) + .build(); + TableDescriptor td = TableDescriptorBuilder.newBuilder(selected) + .modifyColumnFamily(cfd) + .build(); + admin.modifyTable(td); + // assertion - HTableDescriptor freshTableDesc = admin.getTableDescriptor(tableName); - HColumnDescriptor freshColumnDesc = freshTableDesc.getFamily(columnDesc.getName()); + TableDescriptor freshTableDesc = admin.getTableDescriptor(tableName); + ColumnFamilyDescriptor freshColumnDesc = freshTableDesc.getColumnFamily(columnDesc.getName()); Assert.assertEquals("Encoding of column family: " + columnDesc + " was not altered", freshColumnDesc.getDataBlockEncoding().getId(), id); Assert.assertTrue( @@ -721,8 +734,8 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { @Override void perform() throws IOException { - HTableDescriptor selected = selectTable(disabledTables); - HColumnDescriptor cfd = selectFamily(selected); + TableDescriptor selected = selectTable(disabledTables); + ColumnFamilyDescriptor cfd = selectFamily(selected); if (selected == null || cfd == null) { return; } @@ -737,9 +750,9 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { LOG.info("Deleting column family: " + cfd + " from table: " + tableName); admin.deleteColumnFamily(tableName, cfd.getName()); // assertion - HTableDescriptor freshTableDesc = admin.getTableDescriptor(tableName); + TableDescriptor freshTableDesc = admin.listTableDescriptor(tableName); Assert.assertFalse("Column family: " + cfd + " was not added", - freshTableDesc.hasFamily(cfd.getName())); + freshTableDesc.hasColumnFamily(cfd.getName())); Assert.assertTrue( "After delete column family, Table: " + tableName + " is not disabled", admin.isTableDisabled(tableName)); @@ -758,7 +771,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { // populate tables @Override void perform() throws IOException { - HTableDescriptor selected = selectTable(enabledTables); + TableDescriptor selected = selectTable(enabledTables); if (selected == null ) { return; } @@ -777,7 +790,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { // nextInt(Integer.MAX_VALUE)) to return positive numbers only byte[] rowKey = Bytes.toBytes( "row-" + String.format("%010d", RandomUtils.nextInt(Integer.MAX_VALUE))); - HColumnDescriptor cfd = selectFamily(selected); + ColumnFamilyDescriptor cfd = selectFamily(selected); if (cfd == null){ return; } @@ -788,7 +801,7 @@ public class IntegrationTestDDLMasterFailover extends IntegrationTestBase { put.addColumn(family, qualifier, value); table.put(put); } - HTableDescriptor freshTableDesc = admin.getTableDescriptor(tableName); + TableDescriptor freshTableDesc = admin.listTableDescriptor(tableName); Assert.assertTrue( "After insert, Table: " + tableName + " in not enabled", admin.isTableEnabled(tableName)); enabledTables.put(tableName, freshTableDesc);