/** * Returns the regions hosted by the specified server. * <p/> * Notice that, for SCP, after we submit the SCP, no one can change the region list for the * ServerStateNode so we do not need any locks here. And for other usage, this can only give you a * snapshot of the current region list for this server, which means, right after you get the * region list, new regions may be moved to this server or some regions may be moved out from this * server, so you should not use it critically if you need strong consistency. */ public List<RegionInfo> getRegionsOnServer(ServerName serverName) { ServerStateNode serverInfo = regionStates.getServerNode(serverName); if (serverInfo == null) { return Collections.emptyList(); } return serverInfo.getRegionInfoList(); }
/** * This is an EXPENSIVE clone. Cloning though is the safest thing to do. * Can't let out original since it can change and at least the load balancer * wants to iterate this exported list. We need to synchronize on regions * since all access to this.servers is under a lock on this.regions. * @param forceByCluster a flag to force to aggregate the server-load to the cluster level * @return A clone of current assignments by table. */ public Map<TableName, Map<ServerName, List<RegionInfo>>> getAssignmentsByTable( final boolean forceByCluster) { if (!forceByCluster) return getAssignmentsByTable(); final HashMap<ServerName, List<RegionInfo>> ensemble = new HashMap<ServerName, List<RegionInfo>>(serverMap.size()); for (ServerStateNode serverNode: serverMap.values()) { ensemble.put(serverNode.getServerName(), serverNode.getRegionInfoList()); } // TODO: can we use Collections.singletonMap(HConstants.ENSEMBLE_TABLE_NAME, ensemble)? final Map<TableName, Map<ServerName, List<RegionInfo>>> result = new HashMap<TableName, Map<ServerName, List<RegionInfo>>>(1); result.put(HConstants.ENSEMBLE_TABLE_NAME, ensemble); return result; }