Java Code Examples for org.apache.hadoop.hbase.HBaseTestingUtility.getHBaseAdmin()

The following are Jave code examples for showing how to use getHBaseAdmin() of the org.apache.hadoop.hbase.HBaseTestingUtility class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ditb   File: TestClientOperationInterrupt.java   Source Code and License Vote up 6 votes
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf = HBaseConfiguration.create();
  conf.setStrings(CoprocessorHost.USER_REGION_COPROCESSOR_CONF_KEY,
      TestCoprocessor.class.getName());
  util = new HBaseTestingUtility(conf);
  util.startMiniCluster();

  Admin admin = util.getHBaseAdmin();
  if (admin.tableExists(tableName)) {
    if (admin.isTableEnabled(tableName)) {
      admin.disableTable(tableName);
    }
    admin.deleteTable(tableName);
  }
  util.createTable(tableName, new byte[][]{dummy, test});

  Table ht = new HTable(conf, tableName);
  Put p = new Put(row1);
  p.add(dummy, dummy, dummy);
  ht.put(p);
}
 
Example 2
Project: ditb   File: FlushRandomRegionOfTableAction.java   Source Code and License Vote up 6 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Flush random region of table " + tableName);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    LOG.info("Table " + tableName + " doesn't have regions to flush");
    return;
  }

  HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
    regions.toArray(new HRegionInfo[regions.size()]));
  LOG.debug("Flushing region " + region.getRegionNameAsString());
  try {
    admin.flushRegion(region.getRegionName());
  } catch (Exception ex) {
    LOG.warn("Flush failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 3
Project: ditb   File: SnapshotTableAction.java   Source Code and License Vote up 6 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  String snapshotName = tableName + "-it-" + System.currentTimeMillis();
  Admin admin = util.getHBaseAdmin();

  // Don't try the snapshot if we're stopping
  if (context.isStopping()) {
    return;
  }

  LOG.info("Performing action: Snapshot table " + tableName);
  admin.snapshot(snapshotName, tableName);
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 4
Project: ditb   File: SplitAllRegionOfTableAction.java   Source Code and License Vote up 6 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();
  // Don't try the split if we're stopping
  if (context.isStopping()) {
    return;
  }


  // Don't always split. This should allow splitting of a full table later in the run
  if (ThreadLocalRandom.current().nextDouble()
      < (((double) splits) / ((double) maxFullTableSplits)) / ((double) 2)) {
    splits++;
    LOG.info("Performing action: Split all regions of  " + tableName);
    admin.split(tableName);
  } else {
    LOG.info("Skipping split of all regions.");
  }
}
 
Example 5
Project: ditb   File: CompactTableAction.java   Source Code and License Vote up 6 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();
  boolean major = RandomUtils.nextInt(100) < majorRatio;

  LOG.info("Performing action: Compact table " + tableName + ", major=" + major);
  try {
    if (major) {
      admin.majorCompact(tableName);
    } else {
      admin.compact(tableName);
    }
  } catch (Exception ex) {
    LOG.warn("Compaction failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 6
Project: ditb   File: MoveRandomRegionOfTableAction.java   Source Code and License Vote up 6 votes
@Override
public void perform() throws Exception {
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }

  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Move random region of table " + tableName);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    LOG.info("Table " + tableName + " doesn't have regions to move");
    return;
  }

  HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
    regions.toArray(new HRegionInfo[regions.size()]));
  LOG.debug("Unassigning region " + region.getRegionNameAsString());
  admin.unassign(region.getRegionName(), false);
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 7
Project: ditb   File: FlushTableAction.java   Source Code and License Vote up 6 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  // Don't try the flush if we're stopping
  if (context.isStopping()) {
    return;
  }

  LOG.info("Performing action: Flush table " + tableName);
  try {
    admin.flush(tableName);
  } catch (Exception ex) {
    LOG.warn("Flush failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 8
Project: ditb   File: TestTableSnapshotScanner.java   Source Code and License Vote up 5 votes
public static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName,
    String snapshotName, int numRegions)
    throws Exception {
  try {
    util.deleteTable(tableName);
  } catch(Exception ex) {
    // ignore
  }

  if (numRegions > 1) {
    util.createTable(tableName, FAMILIES, 1, bbb, yyy, numRegions);
  } else {
    util.createTable(tableName, FAMILIES);
  }
  Admin admin = util.getHBaseAdmin();

  // put some stuff in the table
  HTable table = new HTable(util.getConfiguration(), tableName);
  util.loadTable(table, FAMILIES);

  Path rootDir = FSUtils.getRootDir(util.getConfiguration());
  FileSystem fs = rootDir.getFileSystem(util.getConfiguration());

  SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName,
      Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);

  // load different values
  byte[] value = Bytes.toBytes("after_snapshot_value");
  util.loadTable(table, FAMILIES, value);

  // cause flush to create new files in the region
  admin.flush(tableName);
  table.close();
}
 
Example 9
Project: ditb   File: TableSnapshotInputFormatTestBase.java   Source Code and License Vote up 5 votes
protected static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName,
  String snapshotName, byte[] startRow, byte[] endRow, int numRegions)
  throws Exception {
  try {
    util.deleteTable(tableName);
  } catch(Exception ex) {
    // ignore
  }

  if (numRegions > 1) {
    util.createTable(tableName, FAMILIES, 1, startRow, endRow, numRegions);
  } else {
    util.createTable(tableName, FAMILIES);
  }
  Admin admin = util.getHBaseAdmin();

  // put some stuff in the table
  HTable table = new HTable(util.getConfiguration(), tableName);
  util.loadTable(table, FAMILIES);

  Path rootDir = FSUtils.getRootDir(util.getConfiguration());
  FileSystem fs = rootDir.getFileSystem(util.getConfiguration());

  SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName,
    Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);

  // load different values
  byte[] value = Bytes.toBytes("after_snapshot_value");
  util.loadTable(table, FAMILIES, value);

  // cause flush to create new files in the region
  admin.flush(tableName);
  table.close();
}
 
Example 10
Project: ditb   File: CompactRandomRegionOfTableAction.java   Source Code and License Vote up 5 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();
  boolean major = RandomUtils.nextInt(100) < majorRatio;

  LOG.info("Performing action: Compact random region of table "
    + tableName + ", major=" + major);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    LOG.info("Table " + tableName + " doesn't have regions to compact");
    return;
  }

  HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
    regions.toArray(new HRegionInfo[regions.size()]));

  try {
    if (major) {
      LOG.debug("Major compacting region " + region.getRegionNameAsString());
      admin.majorCompactRegion(region.getRegionName());
    } else {
      LOG.debug("Compacting region " + region.getRegionNameAsString());
      admin.compactRegion(region.getRegionName());
    }
  } catch (Exception ex) {
    LOG.warn("Compaction failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 11
Project: ditb   File: MergeRandomAdjacentRegionsOfTableAction.java   Source Code and License Vote up 5 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Merge random adjacent regions of table " + tableName);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.size() < 2) {
    LOG.info("Table " + tableName + " doesn't have enough regions to merge");
    return;
  }

  int i = RandomUtils.nextInt(regions.size() - 1);
  HRegionInfo a = regions.get(i++);
  HRegionInfo b = regions.get(i);
  LOG.debug("Merging " + a.getRegionNameAsString() + " and " + b.getRegionNameAsString());

  // Don't try the merge if we're stopping
  if (context.isStopping()) {
    return;
  }

  try {
    admin.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);
  } catch (Exception ex) {
    LOG.warn("Merge failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 12
Project: ditb   File: TruncateTableAction.java   Source Code and License Vote up 5 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  // Don't try the truncate if we're stopping
  if (context.isStopping()) {
    return;
  }

  boolean preserveSplits = random.nextBoolean();
  LOG.info("Performing action: Truncate table " + tableName.getNameAsString() +
           "preserve splits " + preserveSplits);
  admin.truncateTable(tableName, preserveSplits);
}
 
Example 13
Project: ditb   File: SplitRandomRegionOfTableAction.java   Source Code and License Vote up 5 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Split random region of table " + tableName);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    LOG.info("Table " + tableName + " doesn't have regions to split");
    return;
  }
  // Don't try the split if we're stopping
  if (context.isStopping()) {
    return;
  }

  HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
      regions.toArray(new HRegionInfo[regions.size()]));
  LOG.debug("Splitting region " + region.getRegionNameAsString());
  try {
    admin.splitRegion(region.getRegionName());
  } catch (Exception ex) {
    LOG.warn("Split failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 14
Project: ditb   File: ChangeSplitPolicyAction.java   Source Code and License Vote up 5 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Change split policy of table " + tableName);
  HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
  String chosenPolicy = possiblePolicies[random.nextInt(possiblePolicies.length)];
  tableDescriptor.setRegionSplitPolicyClassName(chosenPolicy);
  LOG.info("Changing "  + tableName + " split policy to " + chosenPolicy);
  admin.modifyTable(tableName, tableDescriptor);
}
 
Example 15
Project: ditb   File: ChangeBloomFilterAction.java   Source Code and License Vote up 5 votes
@Override
public void perform() throws Exception {
  Random random = new Random();
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Change bloom filter on all columns of table "
      + tableName);
  HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName);
  HColumnDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();

  if (columnDescriptors == null || columnDescriptors.length == 0) {
    return;
  }

  final BloomType[] bloomArray = BloomType.values();
  final int bloomArraySize = bloomArray.length;

  for (HColumnDescriptor descriptor : columnDescriptors) {
    int bloomFilterIndex = random.nextInt(bloomArraySize);
    LOG.debug("Performing action: About to set bloom filter type to "
        + bloomArray[bloomFilterIndex] + " on column "
        + descriptor.getNameAsString() + " of table " + tableName);
    descriptor.setBloomFilterType(bloomArray[bloomFilterIndex]);
    LOG.debug("Performing action: Just set bloom filter type to "
        + bloomArray[bloomFilterIndex] + " on column "
        + descriptor.getNameAsString() + " of table " + tableName);
  }

  // Don't try the modify if we're stopping
  if (context.isStopping()) {
    return;
  }
  admin.modifyTable(tableName, tableDescriptor);
}
 
Example 16
Project: ditb   File: DecreaseMaxHFileSizeAction.java   Source Code and License Vote up 4 votes
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();
  HTableDescriptor htd = admin.getTableDescriptor(tableName);

  // Try and get the current value.
  long currentValue = htd.getMaxFileSize();

  // If the current value is not set use the default for the cluster.
  // If configs are really weird this might not work.
  // That's ok. We're trying to cause chaos.
  if (currentValue <= 0) {
    currentValue =
        context.getHBaseCluster().getConf().getLong(HConstants.HREGION_MAX_FILESIZE,
            HConstants.DEFAULT_MAX_FILE_SIZE);
  }

  // Decrease by 10% at a time.
  long newValue = (long) (currentValue * 0.9);

  // We don't want to go too far below 1gb.
  // So go to about 1gb +/- 512 on each side.
  newValue = Math.max(minFileSize, newValue) - (512 - random.nextInt(1024));

  // Change the table descriptor.
  htd.setMaxFileSize(newValue);

  // Don't try the modify if we're stopping
  if (context.isStopping()) {
    return;
  }

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

  // Sleep some time.
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}