Search in sources :

Example 36 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestFlushWithThroughputController method getStoreWithName.

private Store getStoreWithName(TableName tableName) {
    MiniHBaseCluster cluster = hbtu.getMiniHBaseCluster();
    List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
    for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
        HRegionServer hrs = rsts.get(i).getRegionServer();
        for (Region region : hrs.getOnlineRegions(tableName)) {
            return region.getStores().iterator().next();
        }
    }
    return null;
}
Also used : MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Region(org.apache.hadoop.hbase.regionserver.Region) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Example 37 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestMasterReplication method rollWALAndWait.

private void rollWALAndWait(final HBaseTestingUtility utility, final TableName table, final byte[] row) throws IOException {
    final Admin admin = utility.getAdmin();
    final MiniHBaseCluster cluster = utility.getMiniHBaseCluster();
    // find the region that corresponds to the given row.
    HRegion region = null;
    for (HRegion candidate : cluster.getRegions(table)) {
        if (HRegion.rowIsInRange(candidate.getRegionInfo(), row)) {
            region = candidate;
            break;
        }
    }
    assertNotNull("Couldn't find the region for row '" + Arrays.toString(row) + "'", region);
    final CountDownLatch latch = new CountDownLatch(1);
    // listen for successful log rolls
    final WALActionsListener listener = new WALActionsListener.Base() {

        @Override
        public void postLogRoll(final Path oldPath, final Path newPath) throws IOException {
            latch.countDown();
        }
    };
    region.getWAL().registerWALActionsListener(listener);
    // request a roll
    admin.rollWALWriter(cluster.getServerHoldingRegion(region.getTableDesc().getTableName(), region.getRegionInfo().getRegionName()));
    // wait
    try {
        latch.await();
    } catch (InterruptedException exception) {
        LOG.warn("Interrupted while waiting for the wal of '" + region + "' to roll. If later " + "replication tests fail, it's probably because we should still be waiting.");
        Thread.currentThread().interrupt();
    }
    region.getWAL().unregisterWALActionsListener(listener);
}
Also used : Path(org.apache.hadoop.fs.Path) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) WALActionsListener(org.apache.hadoop.hbase.regionserver.wal.WALActionsListener) Admin(org.apache.hadoop.hbase.client.Admin) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 38 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project cdap by caskdata.

the class HBaseTestBase method forceRegionFlush.

/**
   * Force and block on a flush to occur on all regions of table {@code tableName}.
   * @param tableName The table whose regions should be flushed.
   */
public void forceRegionFlush(byte[] tableName) throws IOException {
    MiniHBaseCluster hbaseCluster = getHBaseCluster();
    if (hbaseCluster != null) {
        TableName qualifiedTableName = TableName.valueOf(tableName);
        for (JVMClusterUtil.RegionServerThread t : hbaseCluster.getRegionServerThreads()) {
            List<HRegion> serverRegions = t.getRegionServer().getOnlineRegions(qualifiedTableName);
            List<Runnable> flushers = new ArrayList<>();
            for (HRegion region : serverRegions) {
                flushers.add(createFlushRegion(region));
            }
            parallelRun(flushers);
            LOG.info("RegionServer {}: Flushed {} regions for table {}", t.getRegionServer().getServerName().toString(), serverRegions.size(), Bytes.toStringBinary(tableName));
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) ArrayList(java.util.ArrayList) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster)

Example 39 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project cdap by caskdata.

the class HBaseTestBase method forceRegionCompact.

/**
   * Force and block on a compaction on all regions of table {@code tableName}.
   * @param tableName The table whose regions should be compacted.
   * @param majorCompact Whether a major compaction should be requested.
   */
public void forceRegionCompact(byte[] tableName, boolean majorCompact) throws IOException {
    MiniHBaseCluster hbaseCluster = getHBaseCluster();
    if (hbaseCluster != null) {
        TableName qualifiedTableName = TableName.valueOf(tableName);
        for (JVMClusterUtil.RegionServerThread t : hbaseCluster.getRegionServerThreads()) {
            List<HRegion> serverRegions = t.getRegionServer().getOnlineRegions(qualifiedTableName);
            List<Runnable> compacters = new ArrayList<>();
            for (HRegion region : serverRegions) {
                compacters.add(createCompactRegion(region, majorCompact));
            }
            parallelRun(compacters);
            LOG.info("RegionServer {}: Compacted {} regions for table {}", t.getRegionServer().getServerName().toString(), serverRegions.size(), Bytes.toStringBinary(tableName));
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) ArrayList(java.util.ArrayList) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster)

Example 40 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project cdap by caskdata.

the class HBase10CDHTest method forEachRegion.

@Override
public <T> Map<byte[], T> forEachRegion(byte[] tableName, Function<HRegion, T> function) {
    MiniHBaseCluster hbaseCluster = getHBaseCluster();
    Map<byte[], T> results = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    // make sure consumer config cache is updated
    for (JVMClusterUtil.RegionServerThread t : hbaseCluster.getRegionServerThreads()) {
        List<HRegion> serverRegions = t.getRegionServer().getOnlineRegions(TableName.valueOf(tableName));
        for (HRegion region : serverRegions) {
            results.put(region.getRegionName(), function.apply(region));
        }
    }
    return results;
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) TreeMap(java.util.TreeMap)

Aggregations

MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)86 Test (org.junit.Test)58 TableName (org.apache.hadoop.hbase.TableName)32 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)25 Table (org.apache.hadoop.hbase.client.Table)23 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)21 HMaster (org.apache.hadoop.hbase.master.HMaster)21 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)20 ServerName (org.apache.hadoop.hbase.ServerName)19 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)19 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)18 JVMClusterUtil (org.apache.hadoop.hbase.util.JVMClusterUtil)14 Admin (org.apache.hadoop.hbase.client.Admin)12 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)12 IOException (java.io.IOException)11 Region (org.apache.hadoop.hbase.regionserver.Region)11 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)10 Put (org.apache.hadoop.hbase.client.Put)8 TreeMap (java.util.TreeMap)7 Waiter (org.apache.hadoop.hbase.Waiter)7