HBASE-18440 ITs and Actions modify immutable TableDescriptors
Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
parent
9acfb8ae67
commit
e7808b61be
|
@ -24,6 +24,9 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.Waiter.Predicate;
|
import org.apache.hadoop.hbase.Waiter.Predicate;
|
||||||
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.TableDescriptor;
|
||||||
import org.apache.hadoop.hbase.io.crypto.KeyProviderForTesting;
|
import org.apache.hadoop.hbase.io.crypto.KeyProviderForTesting;
|
||||||
import org.apache.hadoop.hbase.io.hfile.HFile;
|
import org.apache.hadoop.hbase.io.hfile.HFile;
|
||||||
import org.apache.hadoop.hbase.io.hfile.HFileReaderImpl;
|
import org.apache.hadoop.hbase.io.hfile.HFileReaderImpl;
|
||||||
|
@ -73,7 +76,7 @@ public class IntegrationTestIngestWithEncryption extends IntegrationTestIngest {
|
||||||
try {
|
try {
|
||||||
EncryptionTest.testEncryption(conf, "AES", null);
|
EncryptionTest.testEncryption(conf, "AES", null);
|
||||||
} catch (Exception e) {
|
} 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;
|
return;
|
||||||
}
|
}
|
||||||
super.setUpCluster();
|
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
|
// Update the test table schema so HFiles from this point will be written with
|
||||||
// encryption features enabled.
|
// encryption features enabled.
|
||||||
final Admin admin = util.getAdmin();
|
final Admin admin = util.getAdmin();
|
||||||
HTableDescriptor tableDescriptor =
|
TableDescriptor tableDescriptor = admin.getDescriptor(getTablename());
|
||||||
new HTableDescriptor(admin.getTableDescriptor(getTablename()));
|
for (ColumnFamilyDescriptor columnDescriptor : tableDescriptor.getColumnFamilies()) {
|
||||||
for (HColumnDescriptor columnDescriptor: tableDescriptor.getColumnFamilies()) {
|
ColumnFamilyDescriptor updatedColumn = ColumnFamilyDescriptorBuilder
|
||||||
columnDescriptor.setEncryptionType("AES");
|
.newBuilder(columnDescriptor).setEncryptionType("AES").build();
|
||||||
LOG.info("Updating CF schema for " + getTablename() + "." +
|
LOG.info(
|
||||||
columnDescriptor.getNameAsString());
|
"Updating CF schema for " + getTablename() + "." + columnDescriptor.getNameAsString());
|
||||||
admin.disableTable(getTablename());
|
admin.disableTable(getTablename());
|
||||||
admin.modifyColumnFamily(getTablename(), columnDescriptor);
|
admin.modifyColumnFamily(getTablename(), updatedColumn);
|
||||||
admin.enableTable(getTablename());
|
admin.enableTable(getTablename());
|
||||||
util.waitFor(30000, 1000, true, new Predicate<IOException>() {
|
util.waitFor(30000, 1000, true, new Predicate<IOException>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,10 +21,12 @@ package org.apache.hadoop.hbase.chaos.actions;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
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.TableName;
|
||||||
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.TableDescriptor;
|
||||||
|
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action the adds a column family to a table.
|
* Action the adds a column family to a table.
|
||||||
|
@ -45,12 +47,12 @@ public class AddColumnAction extends Action {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void perform() throws Exception {
|
public void perform() throws Exception {
|
||||||
HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
|
TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
|
||||||
HColumnDescriptor columnDescriptor = null;
|
ColumnFamilyDescriptor columnDescriptor = null;
|
||||||
|
|
||||||
while(columnDescriptor == null ||
|
while (columnDescriptor == null
|
||||||
tableDescriptor.getFamily(columnDescriptor.getName()) != null) {
|
|| tableDescriptor.getColumnFamily(columnDescriptor.getName()) != null) {
|
||||||
columnDescriptor = new HColumnDescriptor(RandomStringUtils.randomAlphabetic(5));
|
columnDescriptor = ColumnFamilyDescriptorBuilder.of(RandomStringUtils.randomAlphabetic(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't try the modify if we're stopping
|
// 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);
|
LOG.debug("Performing action: Adding " + columnDescriptor + " to " + tableName);
|
||||||
|
|
||||||
tableDescriptor.addFamily(columnDescriptor);
|
TableDescriptor modifiedTable = TableDescriptorBuilder.newBuilder(tableDescriptor)
|
||||||
admin.modifyTable(tableName, tableDescriptor);
|
.addColumnFamily(columnDescriptor).build();
|
||||||
|
admin.modifyTable(modifiedTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,14 @@
|
||||||
|
|
||||||
package org.apache.hadoop.hbase.chaos.actions;
|
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.HConstants;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.client.Admin;
|
import org.apache.hadoop.hbase.client.Admin;
|
||||||
|
import org.apache.hadoop.hbase.client.TableDescriptor;
|
||||||
import java.util.Random;
|
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
|
||||||
|
|
||||||
public class DecreaseMaxHFileSizeAction extends Action {
|
public class DecreaseMaxHFileSizeAction extends Action {
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ public class DecreaseMaxHFileSizeAction extends Action {
|
||||||
private final long sleepTime;
|
private final long sleepTime;
|
||||||
private final TableName tableName;
|
private final TableName tableName;
|
||||||
private final Random random;
|
private final Random random;
|
||||||
|
private Admin admin;
|
||||||
|
|
||||||
public DecreaseMaxHFileSizeAction(long sleepTime, TableName tableName) {
|
public DecreaseMaxHFileSizeAction(long sleepTime, TableName tableName) {
|
||||||
this.sleepTime = sleepTime;
|
this.sleepTime = sleepTime;
|
||||||
|
@ -40,14 +42,18 @@ public class DecreaseMaxHFileSizeAction extends Action {
|
||||||
this.random = new Random();
|
this.random = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(ActionContext context) throws IOException {
|
||||||
|
super.init(context);
|
||||||
|
this.admin = context.getHBaseIntegrationTestingUtility().getAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void perform() throws Exception {
|
public void perform() throws Exception {
|
||||||
HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
|
TableDescriptor td = admin.getDescriptor(tableName);
|
||||||
Admin admin = util.getAdmin();
|
|
||||||
HTableDescriptor htd = admin.getTableDescriptor(tableName);
|
|
||||||
|
|
||||||
// Try and get the current value.
|
// 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 the current value is not set use the default for the cluster.
|
||||||
// If configs are really weird this might not work.
|
// 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));
|
newValue = Math.max(minFileSize, newValue) - (512 - random.nextInt(1024));
|
||||||
|
|
||||||
// Change the table descriptor.
|
// Change the table descriptor.
|
||||||
htd.setMaxFileSize(newValue);
|
TableDescriptor modifiedTable =
|
||||||
|
TableDescriptorBuilder.newBuilder(td).setMaxFileSize(newValue).build();
|
||||||
|
|
||||||
// Don't try the modify if we're stopping
|
// Don't try the modify if we're stopping
|
||||||
if (context.isStopping()) {
|
if (context.isStopping()) {
|
||||||
|
@ -74,7 +81,7 @@ public class DecreaseMaxHFileSizeAction extends Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
// modify the table.
|
// modify the table.
|
||||||
admin.modifyTable(tableName, htd);
|
admin.modifyTable(modifiedTable);
|
||||||
|
|
||||||
// Sleep some time.
|
// Sleep some time.
|
||||||
if (sleepTime > 0) {
|
if (sleepTime > 0) {
|
||||||
|
|
Loading…
Reference in New Issue