/** * Performs a scan of META table for given table. * @param metaTable * @param startRow Where to start the scan * @param stopRow Where to stop the scan * @param type scanned part of meta * @param maxRows maximum rows to return * @param visitor Visitor invoked against each row */ private static CompletableFuture<Void> scanMeta(AsyncTable<AdvancedScanResultConsumer> metaTable, Optional<byte[]> startRow, Optional<byte[]> stopRow, QueryType type, int maxRows, final Visitor visitor) { int rowUpperLimit = maxRows > 0 ? maxRows : Integer.MAX_VALUE; Scan scan = getMetaScan(metaTable, rowUpperLimit); for (byte[] family : type.getFamilies()) { scan.addFamily(family); } startRow.ifPresent(scan::withStartRow); stopRow.ifPresent(scan::withStopRow); if (LOG.isDebugEnabled()) { LOG.debug("Scanning META" + " starting at row=" + Bytes.toStringBinary(scan.getStartRow()) + " stopping at row=" + Bytes.toStringBinary(scan.getStopRow()) + " for max=" + rowUpperLimit + " with caching=" + scan.getCaching()); } CompletableFuture<Void> future = new CompletableFuture<Void>(); metaTable.scan(scan, new MetaTableScanResultConsumer(rowUpperLimit, visitor, future)); return future; }
private void validateNumberOfRowsInMeta(final TableName table, int numRegions, Connection connection) throws IOException { assert(ADMIN.tableExists(table)); final AtomicInteger count = new AtomicInteger(); Visitor visitor = new Visitor() { @Override public boolean visit(Result r) throws IOException { if (HRegionInfo.getHRegionInfo(r).getTable().equals(table)) count.incrementAndGet(); return true; } }; MetaTableAccessor.fullScan(connection, visitor); assert(count.get() == numRegions); }
private void validateNumberOfRowsInMeta(final TableName table, int numRegions, Connection connection) throws IOException { assert(ADMIN.tableExists(table)); final AtomicInteger count = new AtomicInteger(); Visitor visitor = new Visitor() { @Override public boolean visit(Result r) throws IOException { if (MetaTableAccessor.getRegionInfo(r).getTable().equals(table)) count.incrementAndGet(); return true; } }; MetaTableAccessor.fullScanRegions(connection, visitor); assert(count.get() == numRegions); }
MetaTableScanResultConsumer(int rowUpperLimit, Visitor visitor, CompletableFuture<Void> future) { this.rowUpperLimit = rowUpperLimit; this.visitor = visitor; this.future = future; this.currentRowCount = 0; }
/** * Initialize the region assignment snapshot by scanning the hbase:meta table * @throws IOException */ public void initialize() throws IOException { LOG.info("Start to scan the hbase:meta for the current region assignment " + "snappshot"); // TODO: at some point this code could live in the MetaTableAccessor Visitor v = new Visitor() { @Override public boolean visit(Result result) throws IOException { try { if (result == null || result.isEmpty()) return true; RegionLocations rl = MetaTableAccessor.getRegionLocations(result); if (rl == null) return true; HRegionInfo hri = rl.getRegionLocation(0).getRegionInfo(); if (hri == null) return true; if (hri.getTable() == null) return true; if (disabledTables.contains(hri.getTable())) { return true; } // Are we to include split parents in the list? if (excludeOfflinedSplitParents && hri.isSplit()) return true; HRegionLocation[] hrls = rl.getRegionLocations(); // Add the current assignment to the snapshot for all replicas for (int i = 0; i < hrls.length; i++) { if (hrls[i] == null) continue; hri = hrls[i].getRegionInfo(); if (hri == null) continue; addAssignment(hri, hrls[i].getServerName()); addRegion(hri); } // the code below is to handle favored nodes byte[] favoredNodes = result.getValue(HConstants.CATALOG_FAMILY, FavoredNodeAssignmentHelper.FAVOREDNODES_QUALIFIER); if (favoredNodes == null) return true; // Add the favored nodes into assignment plan ServerName[] favoredServerList = FavoredNodeAssignmentHelper.getFavoredNodesList(favoredNodes); // Add the favored nodes into assignment plan existingAssignmentPlan.updateFavoredNodesMap(hri, Arrays.asList(favoredServerList)); return true; } catch (RuntimeException e) { LOG.error("Catche remote exception " + e.getMessage() + " when processing" + result); throw e; } } }; // Scan hbase:meta to pick up user regions MetaTableAccessor.fullScan(connection, v); //regionToRegionServerMap = regions; LOG.info("Finished to scan the hbase:meta for the current region assignment" + "snapshot"); }
/** * Initialize the region assignment snapshot by scanning the hbase:meta table * @throws IOException */ public void initialize() throws IOException { LOG.info("Start to scan the hbase:meta for the current region assignment " + "snappshot"); // TODO: at some point this code could live in the MetaTableAccessor Visitor v = new Visitor() { @Override public boolean visit(Result result) throws IOException { try { if (result == null || result.isEmpty()) return true; RegionLocations rl = MetaTableAccessor.getRegionLocations(result); if (rl == null) return true; RegionInfo hri = rl.getRegionLocation(0).getRegionInfo(); if (hri == null) return true; if (hri.getTable() == null) return true; if (disabledTables.contains(hri.getTable())) { return true; } // Are we to include split parents in the list? if (excludeOfflinedSplitParents && hri.isSplit()) return true; HRegionLocation[] hrls = rl.getRegionLocations(); // Add the current assignment to the snapshot for all replicas for (int i = 0; i < hrls.length; i++) { if (hrls[i] == null) continue; hri = hrls[i].getRegionInfo(); if (hri == null) continue; addAssignment(hri, hrls[i].getServerName()); addRegion(hri); } hri = rl.getRegionLocation(0).getRegionInfo(); // the code below is to handle favored nodes byte[] favoredNodes = result.getValue(HConstants.CATALOG_FAMILY, FavoredNodeAssignmentHelper.FAVOREDNODES_QUALIFIER); if (favoredNodes == null) return true; // Add the favored nodes into assignment plan ServerName[] favoredServerList = FavoredNodeAssignmentHelper.getFavoredNodesList(favoredNodes); // Add the favored nodes into assignment plan existingAssignmentPlan.updateFavoredNodesMap(hri, Arrays.asList(favoredServerList)); /* * Typically there should be FAVORED_NODES_NUM favored nodes for a region in meta. If * there is less than FAVORED_NODES_NUM, lets use as much as we can but log a warning. */ if (favoredServerList.length != FavoredNodeAssignmentHelper.FAVORED_NODES_NUM) { LOG.warn("Insufficient favored nodes for region " + hri + " fn: " + Arrays .toString(favoredServerList)); } for (int i = 0; i < favoredServerList.length; i++) { if (i == PRIMARY.ordinal()) addPrimaryAssignment(hri, favoredServerList[i]); if (i == SECONDARY.ordinal()) addSecondaryAssignment(hri, favoredServerList[i]); if (i == TERTIARY.ordinal()) addTeritiaryAssignment(hri, favoredServerList[i]); } return true; } catch (RuntimeException e) { LOG.error("Catche remote exception " + e.getMessage() + " when processing" + result); throw e; } } }; // Scan hbase:meta to pick up user regions MetaTableAccessor.fullScanRegions(connection, v); //regionToRegionServerMap = regions; LOG.info("Finished to scan the hbase:meta for the current region assignment" + "snapshot"); }
/** * Performs a scan of META table for given table. * @param metaTable * @param tableName table withing we scan * @param type scanned part of meta * @param visitor Visitor invoked against each row */ private static CompletableFuture<Void> scanMeta(AsyncTable<AdvancedScanResultConsumer> metaTable, Optional<TableName> tableName, QueryType type, final Visitor visitor) { return scanMeta(metaTable, getTableStartRowForMeta(tableName, type), getTableStopRowForMeta(tableName, type), type, Integer.MAX_VALUE, visitor); }