/** * Check if the specified region's table is disabled. */ private boolean isTableDisabled(HRegionInfo regionInfo) { return disabledTables.contains(regionInfo.getTableName()); }
/** * Gets the table name from the specified region name. * Like {@link #getTableName(byte[])} only returns a {@link TableName} rather than a byte array. * @param regionName * @return Table name * @see #getTableName(byte[]) */ public static TableName getTable(final byte [] regionName) { return TableName.valueOf(getTableName(regionName)); }
/** * @param current * @param tableName * @return True if <code>current</code> tablename is equal to * <code>tableName</code> */ static boolean isInsideTable(final HRegionInfo current, final byte [] tableName) { return Bytes.equals(tableName, current.getTableName()); }
public boolean processRow(HRegionInfo info) throws IOException { SL_LOG.debug("Testing " + info); if (Bytes.equals(info.getTableName(), HConstants.META_TABLE_NAME)) { result.add(info); return false; } return true; }}); return result;
/** * Get current table name of the region * @return byte array of table name */ public byte[] getTableName() { if (tableName == null || tableName.length == 0) { tableName = getTableName(getRegionName()); } return tableName; }
/** @return true if this region is a meta region */ public boolean isMetaRegion() { return Bytes.equals(tableName, HRegionInfo.FIRST_META_REGIONINFO.getTableName()); }
@SuppressWarnings("deprecation") public static Map<HRegionInfo, ServerName> getRegionAssignmentMap(HBaseAdmin admin, Set<String> tableNameSet) throws IOException { Map<HRegionInfo, ServerName> regionAssignmentMap = createRegionAssignmentMap(admin, tableNameSet); Map<HRegionInfo, ServerName> result = new HashMap<>(); for (Map.Entry<HRegionInfo, ServerName> entry : regionAssignmentMap.entrySet()) { if (tableNameSet.contains(Bytes.toString(entry.getKey().getTableName()))) { result.put(entry.getKey(), entry.getValue()); } } return result; }
/** @return true if this is the root region */ public boolean isRootRegion() { return Bytes.equals(tableName, HRegionInfo.ROOT_REGIONINFO.getTableName()); }
/** * Computes the Path of the HRegion * * @param rootdir qualified path of HBase root directory * @param info HRegionInfo for the region * @return qualified path of region directory */ public static Path getRegionDir(final Path rootdir, final HRegionInfo info) { return new Path( HTableDescriptor.getTableDir(rootdir, info.getTableName()), info.getEncodedName()); }
private void createRootTableInfo(Path rd) throws IOException { // Create ROOT tableInfo if required. if (!FSTableDescriptors.isTableInfoExists(fs, rd, Bytes.toString(HRegionInfo.ROOT_REGIONINFO.getTableName()))) { FSTableDescriptors.createTableDescriptor(HTableDescriptor.ROOT_TABLEDESC, this.conf); } }
@Override public boolean processRow(Result row) throws IOException { byte[] value = row.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); HRegionInfo info = Writables.getHRegionInfoOrNull(value); if (info != null) { if (Bytes.equals(tableName, info.getTableName())) { value = row.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER); if (value == null) { available.set(false); return false; } regionCount.incrementAndGet(); } } return true; } };
/** * Gets the online regions of the specified table. * This method looks at the in-memory onlineRegions. It does not go to <code>.META.</code>. * Only returns <em>online</em> regions. If a region on this table has been * closed during a disable, etc., it will not be included in the returned list. * So, the returned list may not necessarily be ALL regions in this table, its * all the ONLINE regions in the table. * @param tableName * @return Online regions from <code>tableName</code> */ public List<HRegion> getOnlineRegions(byte[] tableName) { List<HRegion> tableRegions = new ArrayList<HRegion>(); synchronized (this.onlineRegions) { for (HRegion region: this.onlineRegions.values()) { HRegionInfo regionInfo = region.getRegionInfo(); if(Bytes.equals(regionInfo.getTableName(), tableName)) { tableRegions.add(region); } } } return tableRegions; }
@Override public final boolean processRow(Result rowResult) throws IOException { HRegionInfo info = Writables.getHRegionInfoOrNull( rowResult.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER)); if (info == null) { return true; } if (!(Bytes.equals(info.getTableName(), tableName))) { return false; } return super.processRow(rowResult); }
@SuppressWarnings("deprecation") public static String getRegionInfoString(HRegionInfo regionA) { return "{TABLE => " + Bytes.toString(regionA.getTableName()) + ", ENCODED => " + regionA.getEncodedName() + ", STARTKEY => '" + Bytes.toStringBinary(regionA.getStartKey()) + "', ENDKEY => '" + Bytes.toStringBinary(regionA.getEndKey()) + "'"; }
@Override public boolean processRow(Result data) throws IOException { if (data == null || data.size() <= 0) { return true; } Pair<HRegionInfo, ServerName> pair = MetaReader.parseCatalogResult(data); if (pair == null) { return false; } if (!Bytes.equals(pair.getFirst().getTableName(), tableName)) { return false; } result.set(pair); return true; } };
/** * Cleans up all the files for a HRegion by archiving the HFiles to the * archive directory * @param conf the configuration to use * @param fs the file system object * @param info HRegionInfo for region to be deleted * @throws IOException */ public static void archiveRegion(Configuration conf, FileSystem fs, HRegionInfo info) throws IOException { Path rootDir = FSUtils.getRootDir(conf); archiveRegion(fs, rootDir, HTableDescriptor.getTableDir(rootDir, info.getTableName()), HRegion.getRegionDir(rootDir, info)); }
/** * Constructor * @param region the region * @param rsServices interface to available region server functionality * @param conf the configuration */ public RegionCoprocessorHost(final HRegion region, final RegionServerServices rsServices, final Configuration conf) { this.conf = conf; this.rsServices = rsServices; this.region = region; this.pathPrefix = Integer.toString(this.region.getRegionInfo().hashCode()); // load system default cp's from configuration. loadSystemCoprocessors(conf, REGION_COPROCESSOR_CONF_KEY); // load system default cp's for user tables from configuration. if (!HTableDescriptor.isMetaTable(region.getRegionInfo().getTableName())) { loadSystemCoprocessors(conf, USER_REGION_COPROCESSOR_CONF_KEY); } // load Coprocessor From HDFS loadTableCoprocessors(conf); }
@SuppressWarnings("deprecation") public Level createLevel(HRegionInfo hRegionInfo, TableInfo tableInfo) { if (levelClass == TableName.class) { return new Level(new TableName(Bytes.toString(hRegionInfo.getTableName()))); } else if (levelClass == RegionName.class) { return new Level(new RegionName(hRegionInfo, tableInfo.serverIndex(hRegionInfo))); } else { return new Level(tableInfo.getServer(hRegionInfo)); } }
@Override public Map<String, TableStats> getTableStats(HBaseAdmin admin) throws IOException { // The idea is to walk thru live region servers, collect table region stats and aggregate them towards table total // metrics. Map<String, TableStats> datasetStat = Maps.newHashMap(); ClusterStatus clusterStatus = admin.getClusterStatus(); for (ServerName serverName : clusterStatus.getServers()) { Map<byte[], RegionLoad> regionsLoad = clusterStatus.getLoad(serverName).getRegionsLoad(); for (RegionLoad regionLoad : regionsLoad.values()) { String tableName = Bytes.toString(HRegionInfo.getTableName(regionLoad.getName())); TableStats stat = datasetStat.get(tableName); if (stat == null) { stat = new TableStats(regionLoad.getStorefileSizeMB(), regionLoad.getMemStoreSizeMB()); datasetStat.put(tableName, stat); } else { stat.incStoreFileSizeMB(regionLoad.getStorefileSizeMB()); stat.incMemStoreSizeMB(regionLoad.getMemStoreSizeMB()); } } } return datasetStat; } }
@SuppressWarnings("deprecation") public static CompactionDescriptor toCompactionDescriptor(HRegionInfo info, byte[] regionName, byte[] family, List<Path> inputPaths, List<Path> outputPaths, Path storeDir) { // compaction descriptor contains relative paths. // input / output paths are relative to the store dir // store dir is relative to region dir CompactionDescriptor.Builder builder = CompactionDescriptor.newBuilder() .setTableName(ByteStringer.wrap(info.getTableName())) .setEncodedRegionName(ByteStringer.wrap( regionName == null ? info.getEncodedNameAsBytes() : regionName)) .setFamilyName(ByteStringer.wrap(family)) .setStoreHomeDir(storeDir.getName()); //make relative for (Path inputPath : inputPaths) { builder.addCompactionInput(inputPath.getName()); //relative path } for (Path outputPath : outputPaths) { builder.addCompactionOutput(outputPath.getName()); } builder.setRegionName(ByteStringer.wrap(info.getRegionName())); return builder.build(); }