Java Code Examples for org.apache.hadoop.hbase.client.Admin#majorCompactRegion()

The following examples show how to use org.apache.hadoop.hbase.client.Admin#majorCompactRegion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MobFileCompactionChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void startCompaction(Admin admin, TableName table, RegionInfo region, byte[] cf)
    throws IOException, InterruptedException {

  LOG.info("Started major compaction: table={} cf={} region={}", table,
    Bytes.toString(cf), region.getRegionNameAsString());
  admin.majorCompactRegion(region.getRegionName(), cf);
  // Wait until it really starts
  // but with finite timeout
  long waitTime = 300000; // 5 min
  long startTime = EnvironmentEdgeManager.currentTime();
  while (admin.getCompactionStateForRegion(region.getRegionName()) == CompactionState.NONE) {
    // Is 1 second too aggressive?
    Thread.sleep(1000);
    if (EnvironmentEdgeManager.currentTime() - startTime > waitTime) {
      LOG.warn("Waited for {} ms to start major MOB compaction on table={} cf={} region={}."+
        " Stopped waiting for request confirmation. This is not an ERROR, continue next region."
        , waitTime, table.getNameAsString(), Bytes.toString(cf),region.getRegionNameAsString());
      break;
    }
  }
}
 
Example 2
Source File: TestEndToEndSplitTransaction.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void compactAndBlockUntilDone(Admin admin, HRegionServer rs, byte[] regionName)
    throws IOException, InterruptedException {
  log("Compacting region: " + Bytes.toStringBinary(regionName));
  // Wait till its online before we do compact else it comes back with NoServerForRegionException
  try {
    TEST_UTIL.waitFor(10000, new Waiter.Predicate<Exception>() {
      @Override public boolean evaluate() throws Exception {
        return rs.getServerName().equals(MetaTableAccessor.
          getRegionLocation(admin.getConnection(), regionName).getServerName());
      }
    });
  } catch (Exception e) {
    throw new IOException(e);
  }
  admin.majorCompactRegion(regionName);
  log("blocking until compaction is complete: " + Bytes.toStringBinary(regionName));
  Threads.sleepWithoutInterrupt(500);
  outer: for (;;) {
    for (Store store : rs.getOnlineRegion(regionName).getStores()) {
      if (store.getStorefilesCount() > 1) {
        Threads.sleep(50);
        continue outer;
      }
    }
    break;
  }
}
 
Example 3
Source File: CompactRandomRegionOfTableAction.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getAdmin();
  boolean major = RandomUtils.nextInt(0, 100) < majorRatio;

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

  RegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
    regions.toArray(new RegionInfo[0]));

  try {
    if (major) {
      getLogger().debug("Major compacting region " + region.getRegionNameAsString());
      admin.majorCompactRegion(region.getRegionName());
    } else {
      getLogger().debug("Compacting region " + region.getRegionNameAsString());
      admin.compactRegion(region.getRegionName());
    }
  } catch (Exception ex) {
    getLogger().warn("Compaction failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 4
Source File: MajorCompactor.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void compactRegionOnServer(MajorCompactionRequest request, Admin admin, String store)
    throws IOException {
  admin.majorCompactRegion(request.getRegion().getEncodedNameAsBytes(),
      Bytes.toBytes(store));
}