Search in sources :

Example 86 with RegionInfo

use of org.apache.hadoop.hbase.client.RegionInfo in project hbase by apache.

the class FlushRandomRegionOfTableAction method perform.

@Override
public void perform() throws Exception {
    HBaseTestingUtil util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getAdmin();
    getLogger().info("Performing action: Flush 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 flush");
        return;
    }
    RegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(regions.toArray(new RegionInfo[0]));
    getLogger().debug("Flushing region " + region.getRegionNameAsString());
    try {
        admin.flushRegion(region.getRegionName());
    } catch (Exception ex) {
        getLogger().warn("Flush 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 87 with RegionInfo

use of org.apache.hadoop.hbase.client.RegionInfo in project hbase by apache.

the class MoveRandomRegionOfTableAction method perform.

@Override
public void perform() throws Exception {
    if (sleepTime > 0) {
        Thread.sleep(sleepTime);
    }
    HBaseTestingUtil util = context.getHBaseIntegrationTestingUtility();
    Admin admin = util.getAdmin();
    getLogger().info("Performing action: Move 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 move");
        return;
    }
    RegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(regions.toArray(new RegionInfo[0]));
    getLogger().debug("Move random region {}", region.getRegionNameAsString());
    // Use facility over in MoveRegionsOfTableAction...
    MoveRegionsOfTableAction.moveRegion(admin, MoveRegionsOfTableAction.getServers(admin), region, getLogger());
    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 88 with RegionInfo

use of org.apache.hadoop.hbase.client.RegionInfo in project hbase by apache.

the class TestTableRegionModel method testGetName.

@Test
public void testGetName() {
    TableRegionModel model = buildTestModel();
    String modelName = model.getName();
    RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(TABLE)).setStartKey(START_KEY).setEndKey(END_KEY).setRegionId(ID).build();
    assertEquals(modelName, hri.getRegionNameAsString());
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Example 89 with RegionInfo

use of org.apache.hadoop.hbase.client.RegionInfo in project hbase by apache.

the class MetaTableAccessor method scanMeta.

/**
 * Performs a scan of META table for given table starting from given row.
 * @param connection connection we're using
 * @param visitor visitor to call
 * @param tableName table withing we scan
 * @param row start scan from this row
 * @param rowLimit max number of rows to return
 */
public static void scanMeta(Connection connection, final ClientMetaTableAccessor.Visitor visitor, final TableName tableName, final byte[] row, final int rowLimit) throws IOException {
    byte[] startRow = null;
    byte[] stopRow = null;
    if (tableName != null) {
        startRow = ClientMetaTableAccessor.getTableStartRowForMeta(tableName, QueryType.REGION);
        if (row != null) {
            RegionInfo closestRi = getClosestRegionInfo(connection, tableName, row);
            startRow = RegionInfo.createRegionName(tableName, closestRi.getStartKey(), HConstants.ZEROES, false);
        }
        stopRow = ClientMetaTableAccessor.getTableStopRowForMeta(tableName, QueryType.REGION);
    }
    scanMeta(connection, startRow, stopRow, QueryType.REGION, rowLimit, visitor);
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

Example 90 with RegionInfo

use of org.apache.hadoop.hbase.client.RegionInfo in project hbase by apache.

the class MetaTableAccessor method getClosestRegionInfo.

/**
 * @return Get closest metatable region row to passed <code>row</code>
 */
@NonNull
private static RegionInfo getClosestRegionInfo(Connection connection, @NonNull final TableName tableName, @NonNull final byte[] row) throws IOException {
    byte[] searchRow = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false);
    Scan scan = getMetaScan(connection.getConfiguration(), 1);
    scan.setReversed(true);
    scan.withStartRow(searchRow);
    try (ResultScanner resultScanner = getMetaHTable(connection).getScanner(scan)) {
        Result result = resultScanner.next();
        if (result == null) {
            throw new TableNotFoundException("Cannot find row in META " + " for table: " + tableName + ", row=" + Bytes.toStringBinary(row));
        }
        RegionInfo regionInfo = CatalogFamilyFormat.getRegionInfo(result);
        if (regionInfo == null) {
            throw new IOException("RegionInfo was null or empty in Meta for " + tableName + ", row=" + Bytes.toStringBinary(row));
        }
        return regionInfo;
    }
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)824 Test (org.junit.Test)416 TableName (org.apache.hadoop.hbase.TableName)311 ServerName (org.apache.hadoop.hbase.ServerName)191 ArrayList (java.util.ArrayList)175 IOException (java.io.IOException)174 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)174 Path (org.apache.hadoop.fs.Path)141 List (java.util.List)118 HashMap (java.util.HashMap)90 Table (org.apache.hadoop.hbase.client.Table)90 Map (java.util.Map)81 Put (org.apache.hadoop.hbase.client.Put)81 Configuration (org.apache.hadoop.conf.Configuration)80 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)67 TreeMap (java.util.TreeMap)66 Result (org.apache.hadoop.hbase.client.Result)59 FileSystem (org.apache.hadoop.fs.FileSystem)58 Cell (org.apache.hadoop.hbase.Cell)50 Scan (org.apache.hadoop.hbase.client.Scan)46