HBASE-18440 ITs and Actions modify immutable TableDescriptors

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
Mike Drob 2017-07-23 12:57:23 -05:00 committed by Guanghao Zhang
parent 9acfb8ae67
commit e7808b61be
3 changed files with 40 additions and 27 deletions

View File

@ -24,6 +24,9 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Waiter.Predicate;
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.TableDescriptor;
import org.apache.hadoop.hbase.io.crypto.KeyProviderForTesting;
import org.apache.hadoop.hbase.io.hfile.HFile;
import org.apache.hadoop.hbase.io.hfile.HFileReaderImpl;
@ -73,7 +76,7 @@ public class IntegrationTestIngestWithEncryption extends IntegrationTestIngest {
try {
EncryptionTest.testEncryption(conf, "AES", null);
} catch (Exception e) {
LOG.warn("Encryption configuration test did not pass, skipping test");
LOG.warn("Encryption configuration test did not pass, skipping test", e);
return;
}
super.setUpCluster();
@ -94,14 +97,14 @@ public class IntegrationTestIngestWithEncryption extends IntegrationTestIngest {
// Update the test table schema so HFiles from this point will be written with
// encryption features enabled.
final Admin admin = util.getAdmin();
HTableDescriptor tableDescriptor =
new HTableDescriptor(admin.getTableDescriptor(getTablename()));
for (HColumnDescriptor columnDescriptor: tableDescriptor.getColumnFamilies()) {
columnDescriptor.setEncryptionType("AES");
LOG.info("Updating CF schema for " + getTablename() + "." +
columnDescriptor.getNameAsString());
TableDescriptor tableDescriptor = admin.getDescriptor(getTablename());
for (ColumnFamilyDescriptor columnDescriptor : tableDescriptor.getColumnFamilies()) {
ColumnFamilyDescriptor updatedColumn = ColumnFamilyDescriptorBuilder
.newBuilder(columnDescriptor).setEncryptionType("AES").build();
LOG.info(
"Updating CF schema for " + getTablename() + "." + columnDescriptor.getNameAsString());
admin.disableTable(getTablename());
admin.modifyColumnFamily(getTablename(), columnDescriptor);
admin.modifyColumnFamily(getTablename(), updatedColumn);
admin.enableTable(getTablename());
util.waitFor(30000, 1000, true, new Predicate<IOException>() {
@Override

View File

@ -21,10 +21,12 @@ package org.apache.hadoop.hbase.chaos.actions;
import java.io.IOException;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
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.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
/**
* Action the adds a column family to a table.
@ -45,12 +47,12 @@ public class AddColumnAction extends Action {
@Override
public void perform() throws Exception {
HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
HColumnDescriptor columnDescriptor = null;
TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
ColumnFamilyDescriptor columnDescriptor = null;
while(columnDescriptor == null ||
tableDescriptor.getFamily(columnDescriptor.getName()) != null) {
columnDescriptor = new HColumnDescriptor(RandomStringUtils.randomAlphabetic(5));
while (columnDescriptor == null
|| tableDescriptor.getColumnFamily(columnDescriptor.getName()) != null) {
columnDescriptor = ColumnFamilyDescriptorBuilder.of(RandomStringUtils.randomAlphabetic(5));
}
// Don't try the modify if we're stopping
@ -60,7 +62,8 @@ public class AddColumnAction extends Action {
LOG.debug("Performing action: Adding " + columnDescriptor + " to " + tableName);
tableDescriptor.addFamily(columnDescriptor);
admin.modifyTable(tableName, tableDescriptor);
TableDescriptor modifiedTable = TableDescriptorBuilder.newBuilder(tableDescriptor)
.addColumnFamily(columnDescriptor).build();
admin.modifyTable(modifiedTable);
}
}

View File

@ -18,13 +18,14 @@
package org.apache.hadoop.hbase.chaos.actions;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import java.io.IOException;
import java.util.Random;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import java.util.Random;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
public class DecreaseMaxHFileSizeAction extends Action {
@ -33,6 +34,7 @@ public class DecreaseMaxHFileSizeAction extends Action {
private final long sleepTime;
private final TableName tableName;
private final Random random;
private Admin admin;
public DecreaseMaxHFileSizeAction(long sleepTime, TableName tableName) {
this.sleepTime = sleepTime;
@ -40,14 +42,18 @@ public class DecreaseMaxHFileSizeAction extends Action {
this.random = new Random();
}
@Override
public void init(ActionContext context) throws IOException {
super.init(context);
this.admin = context.getHBaseIntegrationTestingUtility().getAdmin();
}
@Override
public void perform() throws Exception {
HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
Admin admin = util.getAdmin();
HTableDescriptor htd = admin.getTableDescriptor(tableName);
TableDescriptor td = admin.getDescriptor(tableName);
// Try and get the current value.
long currentValue = htd.getMaxFileSize();
long currentValue = td.getMaxFileSize();
// If the current value is not set use the default for the cluster.
// If configs are really weird this might not work.
@ -66,7 +72,8 @@ public class DecreaseMaxHFileSizeAction extends Action {
newValue = Math.max(minFileSize, newValue) - (512 - random.nextInt(1024));
// Change the table descriptor.
htd.setMaxFileSize(newValue);
TableDescriptor modifiedTable =
TableDescriptorBuilder.newBuilder(td).setMaxFileSize(newValue).build();
// Don't try the modify if we're stopping
if (context.isStopping()) {
@ -74,7 +81,7 @@ public class DecreaseMaxHFileSizeAction extends Action {
}
// modify the table.
admin.modifyTable(tableName, htd);
admin.modifyTable(modifiedTable);
// Sleep some time.
if (sleepTime > 0) {