use of org.apache.hadoop.hbase.HBaseTestingUtil in project hbase by apache.
the class Action method modifyAllTableColumns.
/**
* Apply a transform to all columns in a given table. If there are no columns in a table
* or if the context is stopping does nothing.
* @param tableName the table to modify
* @param transform the modification to perform. Callers will have the
* column name as a string and a column family builder available to them
*/
protected void modifyAllTableColumns(TableName tableName, BiConsumer<String, ColumnFamilyDescriptorBuilder> transform) throws IOException {
HBaseTestingUtil util = this.context.getHBaseIntegrationTestingUtility();
Admin admin = util.getAdmin();
TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
ColumnFamilyDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();
if (columnDescriptors == null || columnDescriptors.length == 0) {
return;
}
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
for (ColumnFamilyDescriptor descriptor : columnDescriptors) {
ColumnFamilyDescriptorBuilder cfd = ColumnFamilyDescriptorBuilder.newBuilder(descriptor);
transform.accept(descriptor.getNameAsString(), cfd);
builder.modifyColumnFamily(cfd.build());
}
// Don't try the modify if we're stopping
if (this.context.isStopping()) {
return;
}
admin.modifyTable(builder.build());
}
use of org.apache.hadoop.hbase.HBaseTestingUtil in project hbase by apache.
the class ChangeSplitPolicyAction method perform.
@Override
public void perform() throws Exception {
HBaseTestingUtil util = context.getHBaseIntegrationTestingUtility();
Admin admin = util.getAdmin();
getLogger().info("Performing action: Change split policy of table " + tableName);
TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
String chosenPolicy = possiblePolicies[random.nextInt(possiblePolicies.length)];
builder.setRegionSplitPolicyClassName(chosenPolicy);
getLogger().info("Changing " + tableName + " split policy to " + chosenPolicy);
admin.modifyTable(builder.build());
}
use of org.apache.hadoop.hbase.HBaseTestingUtil in project hbase by apache.
the class SplitRandomRegionOfTableAction method perform.
@Override
public void perform() throws Exception {
HBaseTestingUtil util = context.getHBaseIntegrationTestingUtility();
Admin admin = util.getAdmin();
getLogger().info("Performing action: Split random region of table " + tableName);
List<RegionInfo> regions = admin.getRegions(tableName);
if (regions == null || regions.isEmpty()) {
getLogger().info("Table " + tableName + " doesn't have regions to split");
return;
}
// Don't try the split if we're stopping
if (context.isStopping()) {
return;
}
RegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(regions.toArray(new RegionInfo[0]));
getLogger().debug("Splitting region " + region.getRegionNameAsString());
try {
admin.splitRegionAsync(region.getRegionName()).get();
} catch (Exception ex) {
getLogger().warn("Split failed, might be caused by other chaos: " + ex.getMessage());
}
if (sleepTime > 0) {
Thread.sleep(sleepTime);
}
}
use of org.apache.hadoop.hbase.HBaseTestingUtil in project hbase by apache.
the class TruncateTableAction method perform.
@Override
public void perform() throws Exception {
HBaseTestingUtil util = context.getHBaseIntegrationTestingUtility();
Admin admin = util.getAdmin();
// Don't try the truncate if we're stopping
if (context.isStopping()) {
return;
}
boolean preserveSplits = random.nextBoolean();
getLogger().info("Performing action: Truncate table {} preserve splits {}", tableName.getNameAsString(), preserveSplits);
admin.truncateTable(tableName, preserveSplits);
}
use of org.apache.hadoop.hbase.HBaseTestingUtil in project hbase by apache.
the class MergeRandomAdjacentRegionsOfTableAction method perform.
@Override
public void perform() throws Exception {
HBaseTestingUtil util = context.getHBaseIntegrationTestingUtility();
Admin admin = util.getAdmin();
getLogger().info("Performing action: Merge random adjacent regions of table " + tableName);
List<RegionInfo> regions = admin.getRegions(tableName);
if (regions == null || regions.size() < 2) {
getLogger().info("Table " + tableName + " doesn't have enough regions to merge");
return;
}
int i = RandomUtils.nextInt(0, regions.size() - 1);
RegionInfo a = regions.get(i++);
RegionInfo b = regions.get(i);
getLogger().debug("Merging " + a.getRegionNameAsString() + " and " + b.getRegionNameAsString());
// Don't try the merge if we're stopping
if (context.isStopping()) {
return;
}
try {
admin.mergeRegionsAsync(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);
} catch (Exception ex) {
getLogger().warn("Merge failed, might be caused by other chaos: " + ex.getMessage());
}
if (sleepTime > 0) {
Thread.sleep(sleepTime);
}
}
Aggregations