/** * Print the assignment plan to the system output stream * @param plan */ public static void printAssignmentPlan(FavoredNodesPlan plan) { if (plan == null) return; LOG.info("========== Start to print the assignment plan ================"); // sort the map based on region info Map<HRegionInfo, List<ServerName>> assignmentMap = new TreeMap<HRegionInfo, List<ServerName>>(plan.getAssignmentMap()); for (Map.Entry<HRegionInfo, List<ServerName>> entry : assignmentMap.entrySet()) { String serverList = FavoredNodeAssignmentHelper.getFavoredNodesAsString(entry.getValue()); String regionName = entry.getKey().getRegionNameAsString(); LOG.info("Region: " + regionName ); LOG.info("Its favored nodes: " + serverList); } LOG.info("========== Finish to print the assignment plan ================"); }
/** * Update the assignment plan into hbase:meta * @param plan the assignments plan to be updated into hbase:meta * @throws IOException if cannot update assignment plan in hbase:meta */ public void updateAssignmentPlanToMeta(FavoredNodesPlan plan) throws IOException { try { LOG.info("Start to update the hbase:meta with the new assignment plan"); Map<HRegionInfo, List<ServerName>> assignmentMap = plan.getAssignmentMap(); FavoredNodeAssignmentHelper.updateMetaWithFavoredNodesInfo(assignmentMap, conf); LOG.info("Updated the hbase:meta with the new assignment plan"); } catch (Exception e) { LOG.error("Failed to update hbase:meta with the new assignment" + "plan because " + e.getMessage()); } }
void processFavoredNodes(List<HRegionInfo> regions) throws IOException { if (!shouldAssignRegionsWithFavoredNodes) return; // The AM gets the favored nodes info for each region and updates the meta // table with that info Map<HRegionInfo, List<ServerName>> regionToFavoredNodes = new HashMap<HRegionInfo, List<ServerName>>(); for (HRegionInfo region : regions) { regionToFavoredNodes.put(region, ((FavoredNodeLoadBalancer)this.balancer).getFavoredNodes(region)); } FavoredNodeAssignmentHelper.updateMetaWithFavoredNodesInfo(regionToFavoredNodes, this.server.getConnection()); }
void processFavoredNodes(List<HRegionInfo> regions) throws IOException { if (!shouldAssignRegionsWithFavoredNodes) return; // The AM gets the favored nodes info for each region and updates the meta // table with that info Map<HRegionInfo, List<ServerName>> regionToFavoredNodes = new HashMap<HRegionInfo, List<ServerName>>(); for (HRegionInfo region : regions) { regionToFavoredNodes.put(region, ((FavoredNodeLoadBalancer)this.balancer).getFavoredNodes(region)); } FavoredNodeAssignmentHelper.updateMetaWithFavoredNodesInfo(regionToFavoredNodes, catalogTracker); }
/** * 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 MetaReader Visitor v = new Visitor() { @Override public boolean visit(Result result) throws IOException { try { if (result == null || result.isEmpty()) return true; Pair<HRegionInfo, ServerName> regionAndServer = HRegionInfo.getHRegionInfoAndServerName(result); HRegionInfo hri = regionAndServer.getFirst(); 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; // Add the current assignment to the snapshot addAssignment(hri, regionAndServer.getSecond()); 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 MetaReader.fullScan(tracker, v); //regionToRegionServerMap = regions; LOG.info("Finished to scan the hbase:meta for the current region assignment" + "snapshot"); }