/** * 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); }
@Override public List<RegionInfo> getRegions(TableName tableName) throws IOException { if (TableName.isMetaTableName(tableName)) { return Arrays.asList(RegionInfoBuilder.FIRST_META_REGIONINFO); } else { return MetaTableAccessor.getTableRegions(connection, tableName, true); } }
/** verify region boundaries obtained from MetaScanner */ void verifyRegionsUsingMetaTableAccessor() throws Exception { List<RegionInfo> regionList = MetaTableAccessor.getTableRegions(connection, tableName, true); verifyTableRegions(regionList.stream() .collect(Collectors.toCollection(() -> new TreeSet<>(RegionInfo.COMPARATOR)))); regionList = MetaTableAccessor.getAllRegions(connection, true); verifyTableRegions(regionList.stream() .collect(Collectors.toCollection(() -> new TreeSet<>(RegionInfo.COMPARATOR)))); }
@Override public List<HRegionLocation> locateRegions(TableName tableName, boolean useCache, boolean offlined) throws IOException { List<RegionInfo> regions; if (TableName.isMetaTableName(tableName)) { regions = Collections.singletonList(RegionInfoBuilder.FIRST_META_REGIONINFO); } else { regions = MetaTableAccessor.getTableRegions(this, tableName, !offlined); } List<HRegionLocation> locations = new ArrayList<>(); for (RegionInfo regionInfo : regions) { if (!RegionReplicaUtil.isDefaultReplica(regionInfo)) { continue; } RegionLocations list = locateRegion(tableName, regionInfo.getStartKey(), useCache, true); if (list != null) { for (HRegionLocation loc : list.getRegionLocations()) { if (loc != null) { locations.add(loc); } } } } return locations; }
+ " descriptor: " + orig); LOG.debug("Finished copying tableinfo."); List<RegionInfo> regions = MetaTableAccessor.getTableRegions(conn, table);
/** * Initialize namespace state cache by scanning meta table. */ private void initialize() throws IOException { List<NamespaceDescriptor> namespaces = this.master.getClusterSchema().getNamespaces(); for (NamespaceDescriptor namespace : namespaces) { addNamespace(namespace.getName()); List<TableName> tables = this.master.listTableNamesByNamespace(namespace.getName()); for (TableName table : tables) { if (table.isSystemTable()) { continue; } List<RegionInfo> regions = MetaTableAccessor.getTableRegions(this.master.getConnection(), table, true); addTable(table, regions.size()); } } LOG.info("Finished updating state of " + nsStateCache.size() + " namespaces. "); initialized = true; }
@Test public void testScanMetaForTable() throws IOException, InterruptedException { final TableName tableName = TableName.valueOf(name.getMethodName()); LOG.info("Started " + tableName); /** Create 2 tables - testScanMetaForTable - testScanMetaForTablf **/ UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); // name that is +1 greater than the first one (e+1=f) TableName greaterName = TableName.valueOf("testScanMetaForTablf"); UTIL.createTable(greaterName, HConstants.CATALOG_FAMILY); // Now make sure we only get the regions from 1 of the tables at a time assertEquals(1, MetaTableAccessor.getTableRegions(connection, tableName).size()); assertEquals(1, MetaTableAccessor.getTableRegions(connection, greaterName).size()); }
regions = MetaTableLocator.getMetaRegions(services.getZooKeeper()); } else { regions = MetaTableAccessor.getTableRegions(services.getConnection(), tableName);
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; }
@Test public void testCreateTableWithSingleReplica() throws Exception { final int numRegions = 3; final int numReplica = 1; final TableName tableName = TableName.valueOf(name.getMethodName()); try { HTableDescriptor desc = new HTableDescriptor(tableName); desc.setRegionReplication(numReplica); desc.addFamily(new HColumnDescriptor("family")); ADMIN.createTable(desc, Bytes.toBytes("A"), Bytes.toBytes("Z"), numRegions); validateNumberOfRowsInMeta(tableName, numRegions, ADMIN.getConnection()); List<RegionInfo> hris = MetaTableAccessor.getTableRegions( ADMIN.getConnection(), tableName); assert(hris.size() == numRegions * numReplica); } finally { ADMIN.disableTable(tableName); ADMIN.deleteTable(tableName); } }
@Test public void testSplitShouldNotHappenIfSplitIsDisabledForTable() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor("f")); htd.setRegionSplitPolicyClassName(DisabledRegionSplitPolicy.class.getName()); Table table = TEST_UTIL.createTable(htd, null); for(int i = 0; i < 10; i++) { Put p = new Put(Bytes.toBytes("row"+i)); byte[] q1 = Bytes.toBytes("q1"); byte[] v1 = Bytes.toBytes("v1"); p.addColumn(Bytes.toBytes("f"), q1, v1); table.put(p); } this.admin.flush(tableName); try { this.admin.split(tableName, Bytes.toBytes("row5")); Threads.sleep(10000); } catch (Exception e) { // Nothing to do. } // Split should not happen. List<RegionInfo> allRegions = MetaTableAccessor.getTableRegions( this.admin.getConnection(), tableName, true); assertEquals(1, allRegions.size()); }
/** * 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); }
MetaTableAccessor.getTableRegions(connection, getTableName());
Random random = new Random(); for (int i = 0; i < 5; i++) { List<RegionInfo> regions = MetaTableAccessor.getTableRegions(connection, tableName, true); if (regions.isEmpty()) { continue;
TEST_UTIL.waitTableEnabled(tableName); Set<byte[]> tableRows = new HashSet<>(); List<RegionInfo> hris = MetaTableAccessor.getTableRegions(ADMIN.getConnection(), tableName); for (RegionInfo hri : hris) { tableRows.add(hri.getRegionName());
Thread.sleep(conf.getInt(StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, 30000) * 6); List<RegionInfo> regions = MetaTableAccessor.getTableRegions(c, TABLE); HRegionLocation hrl = MetaTableAccessor.getRegionLocation(c, regions.get(0));
@Override public List<RegionInfo> getRegions(TableName tableName) throws IOException { if (TableName.isMetaTableName(tableName)) { return Arrays.asList(RegionInfoBuilder.FIRST_META_REGIONINFO); } else { return MetaTableAccessor.getTableRegions(connection, tableName, true); } }
List<RegionInfo> regionInfos = MetaTableAccessor.getTableRegions(connection, tableName); for (RegionInfo regionInfo : regionInfos) { if (Bytes.equals(regionInfo.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) { regionInfos = MetaTableAccessor.getTableRegions(connection, tableName); assertTrue(regionInfos.size() >= 1);
validateNumberOfRowsInMeta(tableName, numRegions, ADMIN.getConnection()); List<RegionInfo> hris = MetaTableAccessor.getTableRegions(ADMIN.getConnection(), tableName); assert(hris.size() == numRegions * numReplica); assert(regions.size() == numRegions * numReplica); hris = MetaTableAccessor.getTableRegions(ADMIN.getConnection(), tableName); assert(hris.size() == numRegions * numReplica);
@Override public List<HRegionLocation> locateRegions(TableName tableName, boolean useCache, boolean offlined) throws IOException { List<RegionInfo> regions; if (TableName.isMetaTableName(tableName)) { regions = Collections.singletonList(RegionInfoBuilder.FIRST_META_REGIONINFO); } else { regions = MetaTableAccessor.getTableRegions(this, tableName, !offlined); } List<HRegionLocation> locations = new ArrayList<>(); for (RegionInfo regionInfo : regions) { if (!RegionReplicaUtil.isDefaultReplica(regionInfo)) { continue; } RegionLocations list = locateRegion(tableName, regionInfo.getStartKey(), useCache, true); if (list != null) { for (HRegionLocation loc : list.getRegionLocations()) { if (loc != null) { locations.add(loc); } } } } return locations; }