HBASE-18428 Migrate ITDDLMasterFailover away from HTable/HColumn

Signed-off-by: Michael Stack <stack@apache.org>
This commit is contained in:
Mike Drob 2017-07-21 15:36:09 -05:00 committed by Michael Stack
parent 79b61a0546
commit ab90823c4a
1 changed files with 74 additions and 61 deletions

View File

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