HBASE-3657 reduce copying of HRegionInfo's

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1082686 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-03-17 20:46:57 +00:00
parent 4723e3b017
commit c980f1d16a
5 changed files with 10 additions and 9 deletions

View File

@ -79,6 +79,7 @@ Release 0.91.0 - Unreleased
HBASE-3440 Clean out load_table.rb and make sure all roads lead to HBASE-3440 Clean out load_table.rb and make sure all roads lead to
completebulkload tool (Vidhyashankar Venkataraman via Stack) completebulkload tool (Vidhyashankar Venkataraman via Stack)
HBASE-3653 Parallelize Server Requests on HBase Client HBASE-3653 Parallelize Server Requests on HBase Client
HBASE-3657 reduce copying of HRegionInfo's (Ted Yu via Stack)
TASK TASK
HBASE-3559 Move report of split to master OFF the heartbeat channel HBASE-3559 Move report of split to master OFF the heartbeat channel

View File

@ -1343,13 +1343,13 @@ public class AssignmentManager extends ZooKeeperListener {
* @throws InterruptedException * @throws InterruptedException
* @throws IOException * @throws IOException
*/ */
public void assignUserRegions(List<HRegionInfo> regions, List<HServerInfo> servers) throws IOException, InterruptedException { public void assignUserRegions(HRegionInfo[] regions, List<HServerInfo> servers) throws IOException, InterruptedException {
if (regions == null) if (regions == null)
return; return;
Map<HServerInfo, List<HRegionInfo>> bulkPlan = null; Map<HServerInfo, List<HRegionInfo>> bulkPlan = null;
// Generate a round-robin bulk assignment plan // Generate a round-robin bulk assignment plan
bulkPlan = LoadBalancer.roundRobinAssignment(regions, servers); bulkPlan = LoadBalancer.roundRobinAssignment(regions, servers);
LOG.info("Bulk assigning " + regions.size() + " region(s) round-robin across " + LOG.info("Bulk assigning " + regions.length + " region(s) round-robin across " +
servers.size() + " server(s)"); servers.size() + " server(s)");
// Use fixed count thread pool assigning. // Use fixed count thread pool assigning.
BulkAssigner ba = new BulkStartupAssigner(this.master, bulkPlan, this); BulkAssigner ba = new BulkStartupAssigner(this.master, bulkPlan, this);
@ -1385,7 +1385,7 @@ public class AssignmentManager extends ZooKeeperListener {
bulkPlan = LoadBalancer.retainAssignment(allRegions, servers); bulkPlan = LoadBalancer.retainAssignment(allRegions, servers);
} else { } else {
// assign regions in round-robin fashion // assign regions in round-robin fashion
assignUserRegions(new ArrayList<HRegionInfo>(allRegions.keySet()), servers); assignUserRegions(allRegions.keySet().toArray(new HRegionInfo[allRegions.size()]), servers);
return; return;
} }
LOG.info("Bulk assigning " + allRegions.size() + " region(s) across " + LOG.info("Bulk assigning " + allRegions.size() + " region(s) across " +

View File

@ -866,7 +866,7 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server {
// 5. Trigger immediate assignment of the regions in round-robin fashion // 5. Trigger immediate assignment of the regions in round-robin fashion
List<HServerInfo> servers = serverManager.getOnlineServersList(); List<HServerInfo> servers = serverManager.getOnlineServersList();
try { try {
this.assignmentManager.assignUserRegions(Arrays.asList(newRegions), servers); this.assignmentManager.assignUserRegions(newRegions, servers);
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
LOG.error("Caught " + ie + " during round-robin assignment"); LOG.error("Caught " + ie + " during round-robin assignment");
throw new IOException(ie); throw new IOException(ie);

View File

@ -392,13 +392,13 @@ public class LoadBalancer {
* assignment is possible (ie. no regions or no servers) * assignment is possible (ie. no regions or no servers)
*/ */
public static Map<HServerInfo,List<HRegionInfo>> roundRobinAssignment( public static Map<HServerInfo,List<HRegionInfo>> roundRobinAssignment(
List<HRegionInfo> regions, List<HServerInfo> servers) { HRegionInfo[] regions, List<HServerInfo> servers) {
if(regions.size() == 0 || servers.size() == 0) { if(regions.length == 0 || servers.size() == 0) {
return null; return null;
} }
Map<HServerInfo,List<HRegionInfo>> assignments = Map<HServerInfo,List<HRegionInfo>> assignments =
new TreeMap<HServerInfo,List<HRegionInfo>>(); new TreeMap<HServerInfo,List<HRegionInfo>>();
int numRegions = regions.size(); int numRegions = regions.length;
int numServers = servers.size(); int numServers = servers.size();
int max = (int)Math.ceil((float)numRegions/numServers); int max = (int)Math.ceil((float)numRegions/numServers);
int serverIdx = 0; int serverIdx = 0;
@ -410,7 +410,7 @@ public class LoadBalancer {
HServerInfo server = servers.get((j+serverIdx) % numServers); HServerInfo server = servers.get((j+serverIdx) % numServers);
List<HRegionInfo> serverRegions = new ArrayList<HRegionInfo>(max); List<HRegionInfo> serverRegions = new ArrayList<HRegionInfo>(max);
for (int i=regionIdx; i<numRegions; i += numServers) { for (int i=regionIdx; i<numRegions; i += numServers) {
serverRegions.add(regions.get(i % numRegions)); serverRegions.add(regions[i % numRegions]);
} }
assignments.put(server, serverRegions); assignments.put(server, serverRegions);
regionIdx++; regionIdx++;

View File

@ -276,7 +276,7 @@ public class TestLoadBalancer {
List<HRegionInfo> regions = randomRegions(mock[0]); List<HRegionInfo> regions = randomRegions(mock[0]);
List<HServerInfo> servers = randomServers(mock[1], 0); List<HServerInfo> servers = randomServers(mock[1], 0);
Map<HServerInfo,List<HRegionInfo>> assignments = Map<HServerInfo,List<HRegionInfo>> assignments =
LoadBalancer.roundRobinAssignment(regions, servers); LoadBalancer.roundRobinAssignment(regions.toArray(new HRegionInfo[regions.size()]), servers);
float average = (float)regions.size()/servers.size(); float average = (float)regions.size()/servers.size();
int min = (int)Math.floor(average); int min = (int)Math.floor(average);
int max = (int)Math.ceil(average); int max = (int)Math.ceil(average);