/** * Returns RegionInfo object from the column * HConstants.CATALOG_FAMILY:HConstants.REGIONINFO_QUALIFIER of the catalog * table Result. * @param data a Result object from the catalog table scan * @return RegionInfo or null */ public static RegionInfo getRegionInfo(Result data) { return getRegionInfo(data, HConstants.REGIONINFO_QUALIFIER); }
public static RegionLocations getRegionLocations(final Result r) { if (r == null) return null; RegionInfo regionInfo = getRegionInfo(r, getRegionInfoColumn()); if (regionInfo == null) return null;
/** * Returns the merge regions by reading the corresponding columns of the catalog table * Result. * @param data a Result object from the catalog table scan * @return a pair of RegionInfo or PairOfSameType(null, null) if the region is not a split * parent */ public static PairOfSameType<RegionInfo> getMergeRegions(Result data) { RegionInfo mergeA = getRegionInfo(data, HConstants.MERGEA_QUALIFIER); RegionInfo mergeB = getRegionInfo(data, HConstants.MERGEB_QUALIFIER); return new PairOfSameType<>(mergeA, mergeB); }
/** * Returns the daughter regions by reading the corresponding columns of the catalog table * Result. * @param data a Result object from the catalog table scan * @return a pair of RegionInfo or PairOfSameType(null, null) if the region is not a split * parent */ public static PairOfSameType<RegionInfo> getDaughterRegions(Result data) { RegionInfo splitA = getRegionInfo(data, HConstants.SPLITA_QUALIFIER); RegionInfo splitB = getRegionInfo(data, HConstants.SPLITB_QUALIFIER); return new PairOfSameType<>(splitA, splitB); }
/** * Get regions from the merge qualifier of the specified merged region * @return null if it doesn't contain merge qualifier, else two merge regions */ @Nullable public static Pair<RegionInfo, RegionInfo> getRegionsFromMergeQualifier( Connection connection, byte[] regionName) throws IOException { Result result = getRegionResult(connection, regionName); RegionInfo mergeA = getRegionInfo(result, HConstants.MERGEA_QUALIFIER); RegionInfo mergeB = getRegionInfo(result, HConstants.MERGEB_QUALIFIER); if (mergeA == null && mergeB == null) { return null; } return new Pair<>(mergeA, mergeB); }
@Override public boolean visit(Result r) throws IOException { if (r == null || r.isEmpty()) return true; count.incrementAndGet(); RegionInfo info = MetaTableAccessor.getRegionInfo(r); if (info == null) return true; // Keep scanning if (isTableSpecified && info.getTable().compareTo(tableName) > 0) { // Another table, stop scanning return false; } if (LOG.isTraceEnabled()) LOG.trace("" + info + " IS-SPLIT_PARENT=" + info.isSplitParent()); if (info.isSplitParent()) splitParents.put(info, r); if (r.getValue(HConstants.CATALOG_FAMILY, HConstants.MERGEA_QUALIFIER) != null) { mergedRegions.put(info, r); } // Returning true means "keep scanning" return true; } };
@Override public final boolean visit(Result rowResult) throws IOException { RegionInfo info = getRegionInfo(rowResult); if (info == null) { return true; } if (!(info.getTable().equals(tableName))) { return false; } return super.visit(rowResult); } }
@Override public boolean visit(Result rowResult) throws IOException { RegionInfo info = getRegionInfo(rowResult); if (info == null) { return true; } //skip over offline and split regions if (!(info.isOffline() || info.isSplit())) { return visitInternal(rowResult); } return true; } }
.stream() .filter(result -> !result.isEmpty()) .filter(result -> MetaTableAccessor.getRegionInfo(result) != null) .forEach( result -> {
@Override public boolean visit(Result r) throws IOException { if (MetaTableAccessor.getRegionInfo(r).getTable().equals(table)) count.incrementAndGet(); return true; } };
@Override public boolean visit(Result data) throws IOException { RegionInfo info = MetaTableAccessor.getRegionInfo(data); if (info == null) { LOG.warn("No serialized HRegionInfo in " + data); return true; } RegionLocations rl = MetaTableAccessor.getRegionLocations(data); boolean matched = false; ServerName sn = null; if (rl != null) { for (HRegionLocation h : rl.getRegionLocations()) { if (h != null && encodedName.equals(h.getRegionInfo().getEncodedName())) { sn = h.getServerName(); info = h.getRegionInfo(); matched = true; } } } if (!matched) return true; result.set(new Pair<>(info, sn)); return false; // found the region, stop } };
/** * Returns all rows from the hbase:meta table for a given user table * * @throws IOException When reading the rows fails. */ public List<byte[]> getMetaTableRows(TableName tableName) throws IOException { // TODO: Redo using MetaTableAccessor. Table t = getConnection().getTable(TableName.META_TABLE_NAME); List<byte[]> rows = new ArrayList<>(); ResultScanner s = t.getScanner(new Scan()); for (Result result : s) { RegionInfo info = MetaTableAccessor.getRegionInfo(result); if (info == null) { LOG.error("No region info for row " + Bytes.toString(result.getRow())); // TODO figure out what to do for this new hosed case. continue; } if (info.getTable().equals(tableName)) { LOG.info("getMetaTableRows: row -> " + Bytes.toStringBinary(result.getRow()) + info); rows.add(result.getRow()); } } s.close(); t.close(); return rows; }
@Test public void testGetHRegionInfo() throws IOException { assertNull(MetaTableAccessor.getRegionInfo(new Result())); List<Cell> kvs = new ArrayList<>(); Result r = Result.create(kvs); assertNull(MetaTableAccessor.getRegionInfo(r)); byte [] f = HConstants.CATALOG_FAMILY; // Make a key value that doesn't have the expected qualifier. kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.SERVER_QUALIFIER, f)); r = Result.create(kvs); assertNull(MetaTableAccessor.getRegionInfo(r)); // Make a key that does not have a regioninfo value. kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER, f)); RegionInfo hri = MetaTableAccessor.getRegionInfo(Result.create(kvs)); assertTrue(hri == null); // OK, give it what it expects kvs.clear(); kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER, RegionInfo.toByteArray(RegionInfoBuilder.FIRST_META_REGIONINFO))); hri = MetaTableAccessor.getRegionInfo(Result.create(kvs)); assertNotNull(hri); assertTrue(RegionInfo.COMPARATOR.compare(hri, RegionInfoBuilder.FIRST_META_REGIONINFO) == 0); }
protected void wipeOutMeta() throws IOException { // Mess it up by blowing up meta. Admin admin = TEST_UTIL.getAdmin(); Scan s = new Scan(); Table meta = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME); ResultScanner scanner = meta.getScanner(s); List<Delete> dels = new ArrayList<>(); for (Result r : scanner) { RegionInfo info = MetaTableAccessor.getRegionInfo(r); if(info != null && !info.getTable().getNamespaceAsString() .equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) { Delete d = new Delete(r.getRow()); dels.add(d); admin.unassign(r.getRow(), true); } } meta.delete(dels); scanner.close(); meta.close(); }
RegionInfo regionInfo = MetaTableAccessor.getRegionInfo(startRowResult); if (regionInfo == null) { throw new IOException("RegionInfo REGIONINFO was null or " +
@Override public boolean visit(Result data) throws IOException { if (data == null || data.size() <= 0) { return true; } Pair<RegionInfo, ServerName> pair = new Pair<>(MetaTableAccessor.getRegionInfo(data), MetaTableAccessor.getServerName(data, 0)); if (!pair.getFirst().getTable().equals(tableName)) { return false; } result.set(pair); return true; } };
try { @SuppressWarnings("deprecation") RegionInfo info = MetaTableAccessor.getRegionInfo(result); if(info.getTable().getNamespaceAsString() .equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR)) {
private PairOfSameType<RegionInfo> waitOnDaughters(final RegionInfo r) throws IOException { long start = System.currentTimeMillis(); PairOfSameType<RegionInfo> pair = null; try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()); Table metaTable = conn.getTable(TableName.META_TABLE_NAME)) { Result result = null; RegionInfo region = null; while ((System.currentTimeMillis() - start) < 60000) { result = metaTable.get(new Get(r.getRegionName())); if (result == null) { break; } region = MetaTableAccessor.getRegionInfo(result); if (region.isSplitParent()) { LOG.debug(region.toString() + " IS a parent!"); pair = MetaTableAccessor.getDaughterRegions(result); break; } Threads.sleep(100); } if (pair.getFirst() == null || pair.getSecond() == null) { throw new IOException("Failed to get daughters, for parent region: " + r); } return pair; } } }
/** * @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, 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 = getRegionInfo(result); if (regionInfo == null) { throw new IOException("RegionInfo was null or empty in Meta for " + tableName + ", row=" + Bytes.toStringBinary(row)); } return regionInfo; } }
private static int addToEachStartKey(final int expected) throws IOException { Table t = TEST_UTIL.getConnection().getTable(TABLENAME); Table meta = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME); int rows = 0; Scan scan = new Scan(); scan.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); ResultScanner s = meta.getScanner(scan); for (Result r = null; (r = s.next()) != null;) { RegionInfo hri = MetaTableAccessor.getRegionInfo(r); if (hri == null) break; if (!hri.getTable().equals(TABLENAME)) { continue; } // If start key, add 'aaa'. if(!hri.getTable().equals(TABLENAME)) { continue; } byte [] row = getStartKey(hri); Put p = new Put(row); p.setDurability(Durability.SKIP_WAL); p.addColumn(getTestFamily(), getTestQualifier(), row); t.put(p); rows++; } s.close(); Assert.assertEquals(expected, rows); t.close(); meta.close(); return rows; }