/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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; }
/** * 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; }
metaScan(conf, visitor); return regions;
metaScan(conf, visitor, tablename); return regions;
MetaScanner.metaScan(conf, visitor, tableName, rowKey, 1); return result.get();
/** * Scans the meta table and calls a visitor on each RowResult and uses a empty * start row value as table name. * * <p>Visible for testing. Use {@link * #metaScan(Connection, MetaScannerVisitor, TableName)} instead. * * @param visitor A custom visitor * @throws IOException e */ @VisibleForTesting // Do not use. Used by tests only and hbck. public static void metaScan(Connection connection, MetaScannerVisitor visitor) throws IOException { metaScan(connection, visitor, null, null, Integer.MAX_VALUE); }
public boolean isTableAvailable(final byte[] tableName) throws IOException { final AtomicBoolean available = new AtomicBoolean(true); final AtomicInteger regionCount = new AtomicInteger(0); MetaScannerVisitor visitor = new MetaScannerVisitorBase() { @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; } }; MetaScanner.metaScan(conf, visitor); return available.get() && (regionCount.get() > 0); }
@Override public boolean isTableAvailable(final TableName tableName) throws IOException { final AtomicBoolean available = new AtomicBoolean(true); final AtomicInteger regionCount = new AtomicInteger(0); MetaScannerVisitor visitor = new MetaScannerVisitorBase() { @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; } }; MetaScanner.metaScan(this, visitor, tableName); return available.get() && (regionCount.get() > 0); }
private static NavigableMap<HRegionInfo, ServerName> regionServerMap(Args args, Configuration conf, HConnection connection, final String tableNameParam, final boolean offlined) throws IOException { long timestamp = System.currentTimeMillis(); final NavigableMap<HRegionInfo, ServerName> regions = new TreeMap<>(); TableName tableName = TableName.valueOf(tableNameParam); MetaScanner.MetaScannerVisitor visitor = new MetaScanner.TableMetaScannerVisitor(tableName) { @Override public boolean processRowInternal(Result rowResult) throws IOException { HRegionInfo info = HRegionInfo.getHRegionInfo(rowResult); ServerName serverName = HRegionInfo.getServerName(rowResult); if (info.isOffline() && !offlined) return true; regions.put(info, serverName); return true; } }; MetaScanner.metaScan(conf, connection, visitor, tableName); Util.printVerboseMessage(args, "CommandAdapter.regionServerMap", timestamp); return regions; }
@SuppressWarnings("UnusedParameters") public static NavigableMap<HRegionInfo, ServerName> regionServerMap(Args args, Configuration conf, HConnection connection, final boolean offlined) throws IOException { long timestamp = System.currentTimeMillis(); final NavigableMap<HRegionInfo, ServerName> regionServerMap = new TreeMap<>(); MetaScanner.DefaultMetaScannerVisitor visitor = new MetaScanner.DefaultMetaScannerVisitor() { @Override public boolean processRowInternal(Result rowResult) throws IOException { HRegionInfo info = HRegionInfo.getHRegionInfo(rowResult); ServerName serverName = HRegionInfo.getServerName(rowResult); if (info.getTable().getNameAsString().startsWith("hbase:")) return true; if (info.isOffline() && !offlined) return true; regionServerMap.put(info, serverName); return true; } }; MetaScanner.metaScan(conf, visitor); Util.printVerboseMessage(args, "CommandAdapter.regionServerMap", timestamp); return regionServerMap; }
/** * 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. * * <p>Visible for testing. Use {@link * #metaScan(Connection, MetaScannerVisitor, TableName)} instead. * * @param connection to scan on * @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 */ @VisibleForTesting // Do not use. Used by Master but by a method that is used testing. public static void metaScan(Connection connection, MetaScannerVisitor visitor, TableName userTableName, byte[] row, int rowLimit) throws IOException { metaScan(connection, visitor, userTableName, row, rowLimit, TableName .META_TABLE_NAME); }
MetaScanner.metaScan(clusterConnection, visitor, tableName, rowKey, 1); return result.get();
metaScan(connection, visitor); return regions;
@SuppressWarnings("UnusedParameters") public static NavigableMap<HRegionInfo, ServerName> regionServerMap(Args args, Configuration conf, HConnection connection, final Set<String> tableNames, final boolean offlined) throws IOException { long timestamp = System.currentTimeMillis(); final NavigableMap<HRegionInfo, ServerName> regionServerMap = new TreeMap<>(); if (tableNames.size() == 1) { return regionServerMap(args, conf, connection, tableNames.toArray(new String[1])[0], offlined); } else if (tableNames.size() > 1) { MetaScanner.DefaultMetaScannerVisitor visitor = new MetaScanner.DefaultMetaScannerVisitor() { @Override public boolean processRowInternal(Result rowResult) throws IOException { HRegionInfo info = HRegionInfo.getHRegionInfo(rowResult); ServerName serverName = HRegionInfo.getServerName(rowResult); String tableName = info.getTable().getNameAsString(); if (tableName.startsWith("hbase:")) return true; if (info.isOffline() && !offlined) return true; if (tableNames.contains(tableName)) regionServerMap.put(info, serverName); return true; } }; MetaScanner.metaScan(conf, visitor); } Util.printVerboseMessage(args, "CommandAdapter.regionServerMap", timestamp); return regionServerMap; }
MetaScanner.metaScan(conf, visitor); pair = result.get();
MetaScanner.metaScan(this.connection, visitor, tableName);