Java Code Examples for org.apache.hadoop.hbase.client.RegionLocator#getAllRegionLocations()
The following examples show how to use
org.apache.hadoop.hbase.client.RegionLocator#getAllRegionLocations() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HBaseSplitsProvider.java From geowave with Apache License 2.0 | 6 votes |
protected static void binFullRange( final Map<HRegionLocation, Map<HRegionInfo, List<ByteArrayRange>>> binnedRanges, final RegionLocator regionLocator) throws IOException { final List<HRegionLocation> locations = regionLocator.getAllRegionLocations(); for (final HRegionLocation location : locations) { Map<HRegionInfo, List<ByteArrayRange>> regionInfoMap = binnedRanges.get(location); if (regionInfoMap == null) { regionInfoMap = new HashMap<>(); binnedRanges.put(location, regionInfoMap); } final HRegionInfo regionInfo = location.getRegionInfo(); List<ByteArrayRange> rangeList = regionInfoMap.get(regionInfo); if (rangeList == null) { rangeList = new ArrayList<>(); regionInfoMap.put(regionInfo, rangeList); } final ByteArrayRange regionRange = new ByteArrayRange(regionInfo.getStartKey(), regionInfo.getEndKey()); rangeList.add(regionRange); } }
Example 2
Source File: HBaseDataFragmenter.java From pxf with Apache License 2.0 | 5 votes |
private void addTableFragments(byte[] userData) throws IOException { RegionLocator regionLocator = connection.getRegionLocator(TableName.valueOf(context.getDataSource())); List <HRegionLocation> locations = regionLocator.getAllRegionLocations(); for (HRegionLocation location : locations) { addFragment(location, userData); } regionLocator.close(); }
Example 3
Source File: HBaseUtils.java From beam with Apache License 2.0 | 5 votes |
/** Returns a list of region locations for a given table and scan. */ static List<HRegionLocation> getRegionLocations( Connection connection, String tableId, ByteKeyRange range) throws Exception { byte[] startRow = range.getStartKey().getBytes(); byte[] stopRow = range.getEndKey().getBytes(); final List<HRegionLocation> regionLocations = new ArrayList<>(); final boolean scanWithNoLowerBound = startRow.length == 0; final boolean scanWithNoUpperBound = stopRow.length == 0; TableName tableName = TableName.valueOf(tableId); RegionLocator regionLocator = connection.getRegionLocator(tableName); List<HRegionLocation> tableRegionInfos = regionLocator.getAllRegionLocations(); for (HRegionLocation regionLocation : tableRegionInfos) { final byte[] startKey = regionLocation.getRegionInfo().getStartKey(); final byte[] endKey = regionLocation.getRegionInfo().getEndKey(); boolean isLastRegion = endKey.length == 0; // filters regions who are part of the scan if ((scanWithNoLowerBound || isLastRegion || Bytes.compareTo(startRow, endKey) < 0) && (scanWithNoUpperBound || Bytes.compareTo(stopRow, startKey) > 0)) { regionLocations.add(regionLocation); } } return regionLocations; }
Example 4
Source File: RegionSizeCalculator.java From tajo with Apache License 2.0 | 5 votes |
private void init(RegionLocator regionLocator, Admin admin) throws IOException { if (!enabled(admin.getConfiguration())) { LOG.info("Region size calculation disabled."); return; } LOG.info("Calculating region sizes for table \"" + regionLocator.getName() + "\"."); //get regions for table List<HRegionLocation> tableRegionInfos = regionLocator.getAllRegionLocations(); Set<byte[]> tableRegions = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR); for (HRegionLocation regionInfo : tableRegionInfos) { tableRegions.add(regionInfo.getRegionInfo().getRegionName()); } ClusterStatus clusterStatus = admin.getClusterStatus(); Collection<ServerName> servers = clusterStatus.getServers(); final long megaByte = 1024L * 1024L; //iterate all cluster regions, filter regions from our table and compute their size for (ServerName serverName: servers) { ServerLoad serverLoad = clusterStatus.getLoad(serverName); for (RegionLoad regionLoad: serverLoad.getRegionsLoad().values()) { byte[] regionId = regionLoad.getName(); if (tableRegions.contains(regionId)) { long regionSizeBytes = (regionLoad.getStorefileSizeMB() + regionLoad.getMemStoreSizeMB()) * megaByte; sizeMap.put(regionId, regionSizeBytes); if (LOG.isDebugEnabled()) { LOG.debug("Region " + regionLoad.getNameAsString() + " has size " + regionSizeBytes); } } } } LOG.debug("Region sizes calculated"); }
Example 5
Source File: TestCatalogJanitorInMemoryStates.java From hbase with Apache License 2.0 | 5 votes |
/** * Test clearing a split parent from memory. */ @Test public void testInMemoryParentCleanup() throws IOException, InterruptedException, ExecutionException { final AssignmentManager am = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager(); final ServerManager sm = TEST_UTIL.getHBaseCluster().getMaster().getServerManager(); final CatalogJanitor janitor = TEST_UTIL.getHBaseCluster().getMaster().getCatalogJanitor(); Admin admin = TEST_UTIL.getAdmin(); admin.catalogJanitorSwitch(false); final TableName tableName = TableName.valueOf(name.getMethodName()); Table t = TEST_UTIL.createTable(tableName, FAMILY); int rowCount = TEST_UTIL.loadTable(t, FAMILY, false); RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName); List<HRegionLocation> allRegionLocations = locator.getAllRegionLocations(); // We need to create a valid split with daughter regions HRegionLocation parent = allRegionLocations.get(0); List<HRegionLocation> daughters = splitRegion(parent.getRegion()); LOG.info("Parent region: " + parent); LOG.info("Daughter regions: " + daughters); assertNotNull("Should have found daughter regions for " + parent, daughters); assertTrue("Parent region should exist in RegionStates", am.getRegionStates().isRegionInRegionStates(parent.getRegion())); assertTrue("Parent region should exist in ServerManager", sm.isRegionInServerManagerStates(parent.getRegion())); // clean the parent Result r = MetaMockingUtil.getMetaTableRowResult(parent.getRegion(), null, daughters.get(0).getRegion(), daughters.get(1).getRegion()); janitor.cleanParent(parent.getRegion(), r); assertFalse("Parent region should have been removed from RegionStates", am.getRegionStates().isRegionInRegionStates(parent.getRegion())); assertFalse("Parent region should have been removed from ServerManager", sm.isRegionInServerManagerStates(parent.getRegion())); }
Example 6
Source File: RegionSizeCalculator.java From hbase with Apache License 2.0 | 5 votes |
private Set<ServerName> getRegionServersOfTable(RegionLocator regionLocator) throws IOException { Set<ServerName> tableServers = Sets.newHashSet(); for (HRegionLocation regionLocation : regionLocator.getAllRegionLocations()) { tableServers.add(regionLocation.getServerName()); } return tableServers; }
Example 7
Source File: HBaseRegionSizeCalculator.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
/** * Computes size of each region for table and given column families. * */ public HBaseRegionSizeCalculator(String tableName, Connection hbaseConnection) throws IOException { Table table = null; Admin admin = null; try { table = hbaseConnection.getTable(TableName.valueOf(tableName)); admin = hbaseConnection.getAdmin(); if (!enabled(table.getConfiguration())) { logger.info("Region size calculation disabled."); return; } logger.info("Calculating region sizes for table \"" + table.getName() + "\"."); // Get regions for table. RegionLocator regionLocator = hbaseConnection.getRegionLocator(table.getName()); List<HRegionLocation> regionLocationList = regionLocator.getAllRegionLocations(); Set<byte[]> tableRegions = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR); for (HRegionLocation hRegionLocation : regionLocationList) { tableRegions.add(hRegionLocation.getRegionInfo().getRegionName()); } ClusterStatus clusterStatus = admin.getClusterStatus(); Collection<ServerName> servers = clusterStatus.getServers(); final long megaByte = 1024L * 1024L; // Iterate all cluster regions, filter regions from our table and // compute their size. for (ServerName serverName : servers) { ServerLoad serverLoad = clusterStatus.getLoad(serverName); for (RegionLoad regionLoad : serverLoad.getRegionsLoad().values()) { byte[] regionId = regionLoad.getName(); if (tableRegions.contains(regionId)) { long regionSizeBytes = regionLoad.getStorefileSizeMB() * megaByte; sizeMap.put(regionId, regionSizeBytes); countMap.put(regionId, new Pair<>(regionLoad.getStores(), regionLoad.getStorefiles())); if (regionSizeBytes == 0L) { logger.info("Region " + regionLoad.getNameAsString() + " has size " + regionSizeBytes); } } } } } finally { IOUtils.closeQuietly(admin); } }
Example 8
Source File: HBaseRegionSizeCalculator.java From kylin with Apache License 2.0 | 4 votes |
/** * Computes size of each region for table and given column families. * */ public HBaseRegionSizeCalculator(String tableName, Connection hbaseConnection) throws IOException { Table table = null; Admin admin = null; try { table = hbaseConnection.getTable(TableName.valueOf(tableName)); admin = hbaseConnection.getAdmin(); if (!enabled(table.getConfiguration())) { logger.info("Region size calculation disabled."); return; } logger.info("Calculating region sizes for table \"" + table.getName() + "\"."); // Get regions for table. RegionLocator regionLocator = hbaseConnection.getRegionLocator(table.getName()); List<HRegionLocation> regionLocationList = regionLocator.getAllRegionLocations(); Set<byte[]> tableRegions = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR); for (HRegionLocation hRegionLocation : regionLocationList) { tableRegions.add(hRegionLocation.getRegionInfo().getRegionName()); } ClusterStatus clusterStatus = admin.getClusterStatus(); Collection<ServerName> servers = clusterStatus.getServers(); final long megaByte = 1024L * 1024L; // Iterate all cluster regions, filter regions from our table and // compute their size. for (ServerName serverName : servers) { ServerLoad serverLoad = clusterStatus.getLoad(serverName); for (RegionLoad regionLoad : serverLoad.getRegionsLoad().values()) { byte[] regionId = regionLoad.getName(); if (tableRegions.contains(regionId)) { long regionSizeBytes = regionLoad.getStorefileSizeMB() * megaByte; sizeMap.put(regionId, regionSizeBytes); countMap.put(regionId, new Pair<>(regionLoad.getStores(), regionLoad.getStorefiles())); if (regionSizeBytes == 0L) { logger.info("Region " + regionLoad.getNameAsString() + " has size " + regionSizeBytes); } } } } } finally { IOUtils.closeQuietly(admin); } }
Example 9
Source File: TestTableResource.java From hbase with Apache License 2.0 | 4 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(3); REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration()); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); context = JAXBContext.newInstance( TableModel.class, TableInfoModel.class, TableListModel.class, TableRegionModel.class); TEST_UTIL.createMultiRegionTable(TABLE, Bytes.toBytes(COLUMN_FAMILY), NUM_REGIONS); byte[] k = new byte[3]; byte [][] famAndQf = CellUtil.parseColumn(Bytes.toBytes(COLUMN)); List<Put> puts = new ArrayList<>(); for (byte b1 = 'a'; b1 < 'z'; b1++) { for (byte b2 = 'a'; b2 < 'z'; b2++) { for (byte b3 = 'a'; b3 < 'z'; b3++) { k[0] = b1; k[1] = b2; k[2] = b3; Put put = new Put(k); put.setDurability(Durability.SKIP_WAL); put.addColumn(famAndQf[0], famAndQf[1], k); puts.add(put); } } } Connection connection = TEST_UTIL.getConnection(); Table table = connection.getTable(TABLE); table.put(puts); table.close(); RegionLocator regionLocator = connection.getRegionLocator(TABLE); List<HRegionLocation> m = regionLocator.getAllRegionLocations(); // should have four regions now assertEquals(NUM_REGIONS, m.size()); regionMap = m; LOG.error("regions: " + regionMap); regionLocator.close(); }