/** * 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 void visitMeta(final RegionStateVisitor visitor) throws IOException { MetaTableAccessor.fullScanRegions(master.getConnection(), new MetaTableAccessor.Visitor() { final boolean isDebugEnabled = LOG.isDebugEnabled(); @Override public boolean visit(final Result r) throws IOException { if (r != null && !r.isEmpty()) { long st = 0; if (LOG.isTraceEnabled()) { st = System.currentTimeMillis(); } visitMetaEntry(visitor, r); if (LOG.isTraceEnabled()) { long et = System.currentTimeMillis(); LOG.trace("[T] LOAD META PERF " + StringUtils.humanTimeDiff(et - st)); } } else if (isDebugEnabled) { LOG.debug("NULL result from meta - ignoring but this is strange."); } return true; } }); }
/** * Sets the number of reduce tasks for the given job configuration to the * number of regions the given table has. * * @param table The table to get the region count for. * @param job The current job to adjust. * @throws IOException When retrieving the table details fails. */ public static void setNumReduceTasks(String table, Job job) throws IOException { job.setNumReduceTasks(MetaTableAccessor.getRegionCount(job.getConfiguration(), TableName.valueOf(table))); }
/** * Put the passed <code>p</code> to the <code>hbase:meta</code> table. * @param connection connection we're using * @param p Put to add to hbase:meta */ private static void putToMetaTable(Connection connection, Put p) throws IOException { try (Table table = getMetaHTable(connection)) { put(table, p); } }
/** * Delete the passed <code>deletes</code> from the <code>hbase:meta</code> table. * @param connection connection we're using * @param deletes Deletes to add to hbase:meta This list should support #remove. */ private static void deleteFromMetaTable(final Connection connection, final List<Delete> deletes) throws IOException { try (Table t = getMetaHTable(connection)) { debugLogMutations(deletes); t.delete(deletes); } }
/** * Gets the result in hbase:meta for the specified region. * @param connection connection we're using * @param regionName region we're looking for * @return result of the specified region */ public static Result getRegionResult(Connection connection, byte[] regionName) throws IOException { Get get = new Get(regionName); get.addFamily(HConstants.CATALOG_FAMILY); return get(getMetaHTable(connection), get); }
@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; } };
.setRegionId(regionId).setReplicaId(0).build(); Table meta = MetaTableAccessor.getMetaHTable(connection); try { List<RegionInfo> regionInfos = Lists.newArrayList(primary); MetaTableAccessor.addRegionsToMeta(connection, regionInfos, 3); MetaTableAccessor.removeRegionReplicasFromMeta(Sets.newHashSet(primary.getRegionName()), 1, 2, connection); Get get = new Get(primary.getRegionName()); for (int replicaId = 0; replicaId < 3; replicaId++) { Cell serverCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(replicaId)); Cell startCodeCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getStartCodeColumn(replicaId)); Cell stateCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getRegionStateColumn(replicaId)); Cell snCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerNameColumn(replicaId)); if (replicaId == 0) { assertNotNull(stateCell);
try (Table meta = MetaTableAccessor.getMetaHTable(connection)) { List<RegionInfo> regionInfos = Lists.newArrayList(regionInfo); MetaTableAccessor.addRegionsToMeta(connection, regionInfos, 1); MetaTableAccessor.updateRegionLocation(connection, regionInfo, sn, 1, masterSystemTime); MetaTableAccessor.getServerColumn(0)); Cell startCodeCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getStartCodeColumn(0)); Cell seqNumCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getSeqNumColumn(0)); assertNotNull(serverCell); assertNotNull(startCodeCell);
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionName region we're looking for * @return HRegionLocation for the given region */ public static HRegionLocation getRegionLocation(Connection connection, byte[] regionName) throws IOException { byte[] row = regionName; RegionInfo parsedInfo = null; try { parsedInfo = parseRegionInfoFromRegionName(regionName); row = getMetaKeyForRegion(parsedInfo); } catch (Exception parseEx) { // Ignore. This is used with tableName passed as regionName. } Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); RegionLocations locations = getRegionLocations(r); return locations == null ? null : locations.getRegionLocation(parsedInfo == null ? 0 : parsedInfo.getReplicaId()); }
.build(); Table meta = MetaTableAccessor.getMetaHTable(connection); try { List<RegionInfo> regionInfos = Lists.newArrayList(parent); MetaTableAccessor.addRegionsToMeta(connection, regionInfos, 3); MetaTableAccessor.splitRegion(connection, parent, -1L, splitA, splitB, serverName0, 3); Get get1 = new Get(splitA.getRegionName()); Result resultA = meta.get(get1); Cell serverCellA = resultA.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(splitA.getReplicaId())); Cell startCodeCellA = resultA.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getStartCodeColumn(splitA.getReplicaId())); assertNull(serverCellA); assertNull(startCodeCellA); Result resultB = meta.get(get2); Cell serverCellB = resultB.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(splitB.getReplicaId())); Cell startCodeCellB = resultB.getColumnLatestCell(HConstants.CATALOG_FAMILY, MetaTableAccessor.getStartCodeColumn(splitB.getReplicaId())); assertNull(serverCellB); assertNull(startCodeCellB);
/** * 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 */ public static HRegionLocation getRegionLocation(Connection connection, RegionInfo 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()); }
@Override protected Boolean rpcCall(int callTimeout) throws Exception { return MetaTableAccessor.tableExists(connection, tableName); } });
validateNumberOfRowsInMeta(tableName, numRegions, ADMIN.getConnection()); List<RegionInfo> hris = MetaTableAccessor.getTableRegions(ADMIN.getConnection(), tableName); assert(hris.size() == numRegions * numReplica); List<Result> metaRows = MetaTableAccessor.fullScanRegions(ADMIN.getConnection()); int numRows = 0; for (Result result : metaRows) { RegionLocations locations = MetaTableAccessor.getRegionLocations(result); RegionInfo hri = locations.getRegionLocation().getRegionInfo(); if (!hri.getTable().equals(tableName)) continue; assert(regions.size() == numRegions * numReplica); hris = MetaTableAccessor.getTableRegions(ADMIN.getConnection(), tableName); assert(hris.size() == numRegions * numReplica);
/** * Gets all of the regions of the specified table. Do not use this method * to get meta table regions, use methods in MetaTableLocator instead. * @param connection connection we're using * @param tableName table we're looking for * @return Ordered list of {@link RegionInfo}. */ public static List<RegionInfo> getTableRegions(Connection connection, TableName tableName) throws IOException { return getTableRegions(connection, tableName, false); }
/** * @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; } }
/** * Returns the HRegionLocation parsed from the given meta row Result * for the given regionInfo and replicaId. The regionInfo can be the default region info * for the replica. * @param r the meta row result * @param regionInfo RegionInfo for default replica * @param replicaId the replicaId for the HRegionLocation * @return HRegionLocation parsed from the given meta row Result for the given replicaId */ private static HRegionLocation getRegionLocation(final Result r, final RegionInfo regionInfo, final int replicaId) { ServerName serverName = getServerName(r, replicaId); long seqNum = getSeqNumDuringOpen(r, replicaId); RegionInfo replicaInfo = RegionReplicaUtil.getRegionInfoForReplica(regionInfo, replicaId); return new HRegionLocation(replicaInfo, serverName, seqNum); }
/** * 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); }
private static List<RegionInfo> testGettingTableRegions(final Connection connection, final TableName name, final int regionCount) throws IOException, InterruptedException { List<RegionInfo> regions = MetaTableAccessor.getTableRegions(connection, name); assertEquals(regionCount, regions.size()); Pair<RegionInfo, ServerName> pair = MetaTableAccessor.getRegion(connection, regions.get(0).getRegionName()); assertEquals(regions.get(0).getEncodedName(), pair.getFirst().getEncodedName()); return regions; }
throw new IllegalArgumentException("Pass a table name or region name"); Pair<RegionInfo, ServerName> pair = MetaTableAccessor.getRegion(connection, regionName); if (pair == null) { final AtomicReference<Pair<RegionInfo, ServerName>> result = new AtomicReference<>(null); MetaTableAccessor.fullScanRegions(connection, visitor); pair = result.get();