Search in sources :

Example 81 with HBaseTestingUtil

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());
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 82 with HBaseTestingUtil

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());
}
Also used : TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Admin(org.apache.hadoop.hbase.client.Admin) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 83 with HBaseTestingUtil

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);
    }
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Admin(org.apache.hadoop.hbase.client.Admin)

Example 84 with HBaseTestingUtil

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);
}
Also used : HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Admin(org.apache.hadoop.hbase.client.Admin)

Example 85 with HBaseTestingUtil

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);
    }
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Admin(org.apache.hadoop.hbase.client.Admin)

Aggregations

HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)144 Configuration (org.apache.hadoop.conf.Configuration)42 Test (org.junit.Test)42 Before (org.junit.Before)41 BeforeClass (org.junit.BeforeClass)37 Path (org.apache.hadoop.fs.Path)24 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)22 Admin (org.apache.hadoop.hbase.client.Admin)22 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)15 StartTestingClusterOption (org.apache.hadoop.hbase.StartTestingClusterOption)14 FileSystem (org.apache.hadoop.fs.FileSystem)13 MiniZooKeeperCluster (org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster)12 TableName (org.apache.hadoop.hbase.TableName)10 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)10 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)9 ServerName (org.apache.hadoop.hbase.ServerName)8 Table (org.apache.hadoop.hbase.client.Table)8 ZKWatcher (org.apache.hadoop.hbase.zookeeper.ZKWatcher)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7