/** * Lists all of the regions currently in META. * @param conf * @return List of all user-space regions. * @throws IOException */ public static List<HRegionInfo> listAllRegions(Configuration conf) throws IOException { return listAllRegions(conf, true); }
/** * Scans the meta table and calls a visitor on each RowResult and uses a empty * start row value as table name. * * @param configuration conf * @param visitor A custom visitor * @throws IOException e */ public static void metaScan(Configuration configuration, MetaScannerVisitor visitor) throws IOException { metaScan(configuration, visitor, null); }
/** * Lists all of the table regions currently in META. * @param conf * @param offlined True if we are to include offlined regions, false and we'll * leave out offlined regions from returned list. * @return Map of all user-space regions to servers * @throws IOException * @deprecated Use {@link #allTableRegions(Connection, TableName)} instead */ @Deprecated public static NavigableMap<HRegionInfo, ServerName> allTableRegions(Configuration conf, Connection connection, final TableName tableName, boolean offlined) throws IOException { return allTableRegions(connection, tableName); }
if (row != null) { Result startRowResult = getClosestRowOrBefore(metaTable, tableName, row, connection.getConfiguration().getBoolean(HConstants.USE_META_REPLICAS, HConstants.DEFAULT_USE_META_REPLICAS)); " for table: " + tableName + ", row=" + Bytes.toStringBinary(row)); HRegionInfo regionInfo = getHRegionInfo(startRowResult); if (regionInfo == null) { throw new IOException("HRegionInfo was null or empty in Meta for " +
@Override public final boolean processRow(Result rowResult) throws IOException { HRegionInfo info = getHRegionInfo(rowResult); if (info == null) { return true; } if (!(info.getTable().equals(tableName))) { return false; } return super.processRow(rowResult); } }
@VisibleForTesting List<RegionLocations> listRegionLocations() throws IOException { return MetaScanner.listTableRegionLocations(getConfiguration(), this.connection, getName()); }
@Override public boolean processRow(Result rowResult) throws IOException { HRegionInfo info = getHRegionInfo(rowResult); if (info == null) { return true; } //skip over offline and split regions if (!(info.isOffline() || info.isSplit())) { return processRowInternal(rowResult); } return true; } }
/** * Scans the meta table and calls a visitor on each RowResult. Uses a table * name to locate meta regions. * * @param configuration config * @param visitor visitor object * @param userTableName User table name in meta table to start scan at. Pass * null if not interested in a particular table. * @throws IOException e */ public static void metaScan(Configuration configuration, MetaScannerVisitor visitor, byte [] userTableName) throws IOException { metaScan(configuration, visitor, userTableName, null, Integer.MAX_VALUE); }
/** * Gets all the regions and their address for this table. * <p> * This is mainly useful for the MapReduce integration. * @return A map of HRegionInfo with it's server address * @throws IOException if a remote or network exception occurs * @deprecated This is no longer a public API. Use {@link #getAllRegionLocations()} instead. */ @Deprecated public NavigableMap<HRegionInfo, ServerName> getRegionLocations() throws IOException { // TODO: Odd that this returns a Map of HRI to SN whereas getRegionLocator, singular, returns an HRegionLocation. return MetaScanner.allTableRegions(this.connection, getName()); }
@Override public HTableDescriptor[] listTables(String regex) throws IOException { Set<TableName> tableNameSet = new TreeSet<>(); for (HRegionInfo hRegionInfo : MetaScanner.listAllRegions(getConfiguration(), true)) { TableName tableName = hRegionInfo.getTable(); if (!tableName.getNameAsString().startsWith("hbase:")) { if (regex == null) { tableNameSet.add(tableName); } else { if (tableName.getNameAsString().matches(regex)) tableNameSet.add(tableName); } } } HTableDescriptor[] hTableDescriptors = new HTableDescriptor[tableNameSet.size()]; int i = 0; for (TableName tableName : tableNameSet) { hTableDescriptors[i++] = new HTableDescriptor(tableName); } return hTableDescriptors; }
@Override public boolean processRow(Result row) throws IOException { HRegionInfo info = MetaScanner.getHRegionInfo(row); if (info != null && !info.isSplitParent()) { if (tableName.equals(info.getTable())) { ServerName server = HRegionInfo.getServerName(row); if (server == null) { available.set(false); return false; } regionCount.incrementAndGet(); } else if (tableName.compareTo(info.getTable()) < 0) { // Return if we are done with the current table return false; } } return true; } };
/** * Scans the meta table and calls a visitor on each RowResult. Uses a table * name to locate meta regions. * * @param connection connection to use internally (null to use a new instance) * @param visitor visitor object * @param userTableName User table name in meta table to start scan at. Pass * null if not interested in a particular table. * @throws IOException e */ public static void metaScan(Connection connection, MetaScannerVisitor visitor, TableName userTableName) throws IOException { metaScan(connection, visitor, userTableName, null, Integer.MAX_VALUE, TableName.META_TABLE_NAME); }
@Override public List<HRegionLocation> getAllRegionLocations() throws IOException { NavigableMap<HRegionInfo, ServerName> locations = MetaScanner.allTableRegions(this.connection, getName()); ArrayList<HRegionLocation> regions = new ArrayList<>(locations.size()); for (Entry<HRegionInfo, ServerName> entry : locations.entrySet()) { regions.add(new HRegionLocation(entry.getKey(), entry.getValue())); } return regions; }
public void checkRegionBoundaries() { try { ByteArrayComparator comparator = new ByteArrayComparator(); List<HRegionInfo> regions = MetaScanner.listAllRegions(getConf(), connection, false); final RegionBoundariesInformation currentRegionBoundariesInformation = new RegionBoundariesInformation();
@Override public boolean processRow(Result row) throws IOException { HRegionInfo info = MetaScanner.getHRegionInfo(row); if (info != null && !info.isSplitParent()) { if (tableName.equals(info.getTable())) { ServerName server = HRegionInfo.getServerName(row); if (server == null) { available.set(false); return false; } if (!Bytes.equals(info.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) { for (byte[] splitKey : splitKeys) { // Just check if the splitkey is available if (Bytes.equals(info.getStartKey(), splitKey)) { regionCount.incrementAndGet(); break; } } } else { // Always empty start row should be counted regionCount.incrementAndGet(); } } else if (tableName.compareTo(info.getTable()) < 0) { // Return if we are done with the current table return false; } } return true; } };
/** * Scans the meta table and calls a visitor on each RowResult. Uses a table * name and a row name to locate meta regions. And it only scans at most * <code>rowLimit</code> of rows. * * @param configuration HBase configuration. * @param visitor Visitor object. * @param userTableName User table name in meta table to start scan at. Pass * null if not interested in a particular table. * @param row Name of the row at the user table. The scan will start from * the region row where the row resides. * @param rowLimit Max of processed rows. If it is less than 0, it * will be set to default value <code>Integer.MAX_VALUE</code>. * @throws IOException e */ public static void metaScan(Configuration configuration, MetaScannerVisitor visitor, byte [] userTableName, byte[] row, int rowLimit) throws IOException { metaScan(configuration, visitor, userTableName, row, rowLimit, HConstants.META_TABLE_NAME); }
/** * Gets all the regions and their address for this table. * <p> * This is mainly useful for the MapReduce integration. * @return A map of HRegionInfo with it's server address * @throws IOException if a remote or network exception occurs */ public NavigableMap<HRegionInfo, ServerName> getRegionLocations() throws IOException { return MetaScanner.allTableRegions(getConfiguration(), getTableName(), false); }
/** * Lists table regions and locations grouped by region range from META. */ public static List<RegionLocations> listTableRegionLocations(Configuration conf, Connection connection, final TableName tableName) throws IOException { final List<RegionLocations> regions = new ArrayList<RegionLocations>(); MetaScannerVisitor visitor = new TableMetaScannerVisitor(tableName) { @Override public boolean processRowInternal(Result result) throws IOException { RegionLocations locations = MetaTableAccessor.getRegionLocations(result); if (locations == null) return true; regions.add(locations); return true; } }; metaScan(connection, visitor, tableName); return regions; }
@Override public List<HRegionLocation> locateRegions(final TableName tableName, final boolean useCache, final boolean offlined) throws IOException { NavigableMap<HRegionInfo, ServerName> regions = MetaScanner.allTableRegions(this, tableName); final List<HRegionLocation> locations = new ArrayList<HRegionLocation>(); for (HRegionInfo regionInfo : regions.keySet()) { RegionLocations list = locateRegion(tableName, regionInfo.getStartKey(), useCache, true); if (list != null) { for (HRegionLocation loc : list.getRegionLocations()) { if (loc != null) { locations.add(loc); } } } } return locations; }
/** * Lists all of the table regions currently in META. * @param connection * @param tableName * @return Map of all user-space regions to servers * @throws IOException */ public static NavigableMap<HRegionInfo, ServerName> allTableRegions( Connection connection, final TableName tableName) throws IOException { final NavigableMap<HRegionInfo, ServerName> regions = new TreeMap<HRegionInfo, ServerName>(); MetaScannerVisitor visitor = new TableMetaScannerVisitor(tableName) { @Override public boolean processRowInternal(Result result) throws IOException { RegionLocations locations = MetaTableAccessor.getRegionLocations(result); if (locations == null) return true; for (HRegionLocation loc : locations.getRegionLocations()) { if (loc != null) { HRegionInfo regionInfo = loc.getRegionInfo(); regions.put(new UnmodifyableHRegionInfo(regionInfo), loc.getServerName()); } } return true; } }; metaScan(connection, visitor, tableName); return regions; }