Skip to content

Commit

Permalink
HBASE-18440 ITs and Actions modify immutable TableDescriptors
Browse files Browse the repository at this point in the history
Signed-off-by: Guanghao Zhang <zghao@apache.org>
  • Loading branch information
madrob authored and infraio committed Dec 19, 2017
1 parent e343b0c commit 74beb5a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
Expand Up @@ -24,6 +24,9 @@
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;
Expand Down Expand Up @@ -73,7 +76,7 @@ public void setUpCluster() throws Exception {
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();
Expand All @@ -94,14 +97,14 @@ public void setUp() throws Exception {
// 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
Expand Down
Expand Up @@ -21,10 +21,12 @@
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.
Expand All @@ -45,12 +47,12 @@ public void init(ActionContext context) throws IOException {

@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
Expand All @@ -60,7 +62,8 @@ public void perform() throws Exception {

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);
}
}
Expand Up @@ -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 {

Expand All @@ -33,21 +34,26 @@ 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;
this.tableName = tableName;
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.
Expand All @@ -66,15 +72,16 @@ public void perform() throws Exception {
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()) {
return;
}

// modify the table.
admin.modifyTable(tableName, htd);
admin.modifyTable(modifiedTable);

// Sleep some time.
if (sleepTime > 0) {
Expand Down

0 comments on commit 74beb5a

Please sign in to comment.