Search in sources :

Example 6 with Result

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

the class MetaTableAccessor method getSerialReplicationDaughterRegion.

/**
   * Get daughter region(s) for a region, only used in serial replication.
   * @param connection connection we're using
   * @param encodedName region's encoded name
   * @throws IOException
   */
public static String getSerialReplicationDaughterRegion(Connection connection, byte[] encodedName) throws IOException {
    Get get = new Get(encodedName);
    get.addColumn(HConstants.REPLICATION_META_FAMILY, daughterNameCq);
    Result result = get(getMetaHTable(connection), get);
    if (!result.isEmpty()) {
        Cell c = result.rawCells()[0];
        return Bytes.toString(c.getValueArray(), c.getValueOffset(), c.getValueLength());
    }
    return null;
}
Also used : Get(org.apache.hadoop.hbase.client.Get) Result(org.apache.hadoop.hbase.client.Result)

Example 7 with Result

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

the class MetaTableAccessor method getRegionLocation.

/**
   * Returns the HRegionLocation from meta for the given region
   * @param connection connection we're using
   * @param regionInfo region information
   * @return HRegionLocation for the given region
   * @throws IOException
   */
public static HRegionLocation getRegionLocation(Connection connection, HRegionInfo regionInfo) throws IOException {
    byte[] row = getMetaKeyForRegion(regionInfo);
    Get get = new Get(row);
    get.addFamily(HConstants.CATALOG_FAMILY);
    Result r = get(getMetaHTable(connection), get);
    return getRegionLocation(r, regionInfo, regionInfo.getReplicaId());
}
Also used : Get(org.apache.hadoop.hbase.client.Get) Result(org.apache.hadoop.hbase.client.Result)

Example 8 with Result

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

the class MetaTableAccessor method getClosestRegionInfo.

/**
   * @return Get closest metatable region row to passed <code>row</code>
   * @throws java.io.IOException
   */
@NonNull
public static HRegionInfo getClosestRegionInfo(Connection connection, @NonNull final TableName tableName, @NonNull final byte[] row) throws IOException {
    byte[] searchRow = HRegionInfo.createRegionName(tableName, row, HConstants.NINES, false);
    Scan scan = getMetaScan(connection, 1);
    scan.setReversed(true);
    scan.setStartRow(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));
        }
        HRegionInfo regionInfo = getHRegionInfo(result);
        if (regionInfo == null) {
            throw new IOException("HRegionInfo 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) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 9 with Result

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

the class MetaTableAccessor method getAllBarriers.

/**
   * Get all barriers in all regions.
   * @return a map of barrier lists in all regions
   * @throws IOException
   */
public static Map<String, List<Long>> getAllBarriers(Connection connection) throws IOException {
    Map<String, List<Long>> map = new HashMap<>();
    Scan scan = new Scan();
    scan.addFamily(HConstants.REPLICATION_BARRIER_FAMILY);
    try (Table t = getMetaHTable(connection);
        ResultScanner scanner = t.getScanner(scan)) {
        Result result;
        while ((result = scanner.next()) != null) {
            String key = Bytes.toString(result.getRow());
            List<Long> list = new ArrayList<>(result.rawCells().length);
            for (Cell cell : result.rawCells()) {
                list.add(Bytes.toLong(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()));
            }
            map.put(key, list);
        }
    }
    return map;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Result(org.apache.hadoop.hbase.client.Result)

Example 10 with Result

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

the class TestHelloHBase method testDeleteRow.

@Test
public void testDeleteRow() throws IOException {
    Admin admin = TEST_UTIL.getAdmin();
    admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build());
    Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME);
    table.put(new Put(HelloHBase.MY_ROW_ID).addColumn(HelloHBase.MY_COLUMN_FAMILY_NAME, HelloHBase.MY_FIRST_COLUMN_QUALIFIER, Bytes.toBytes("xyz")));
    HelloHBase.deleteRow(table);
    Result row = table.get(new Get(HelloHBase.MY_ROW_ID));
    assertEquals("#deleteRow failed to delete row.", true, row.isEmpty());
    TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME);
    admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

Result (org.apache.hadoop.hbase.client.Result)715 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)286 Test (org.junit.Test)280 Scan (org.apache.hadoop.hbase.client.Scan)279 Get (org.apache.hadoop.hbase.client.Get)269 Table (org.apache.hadoop.hbase.client.Table)224 Put (org.apache.hadoop.hbase.client.Put)183 Cell (org.apache.hadoop.hbase.Cell)177 IOException (java.io.IOException)164 ArrayList (java.util.ArrayList)143 TableName (org.apache.hadoop.hbase.TableName)124 Connection (org.apache.hadoop.hbase.client.Connection)101 Delete (org.apache.hadoop.hbase.client.Delete)101 Configuration (org.apache.hadoop.conf.Configuration)70 KeyValue (org.apache.hadoop.hbase.KeyValue)70 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)62 InterruptedIOException (java.io.InterruptedIOException)58 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)50 CellScanner (org.apache.hadoop.hbase.CellScanner)47 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)45