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;
}
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());
}
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;
}
}
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;
}
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);
}
Aggregations