HBASE-12167 NPE in AssignmentManager

This commit is contained in:
Jimmy Xiang 2014-10-03 09:29:00 -07:00
parent 566686d9e9
commit c452942f57
3 changed files with 28 additions and 7 deletions

View File

@ -2586,6 +2586,9 @@ public class AssignmentManager extends ZooKeeperListener {
// Reuse existing assignment info // Reuse existing assignment info
Map<ServerName, List<HRegionInfo>> bulkPlan = Map<ServerName, List<HRegionInfo>> bulkPlan =
balancer.retainAssignment(regions, servers); balancer.retainAssignment(regions, servers);
if (bulkPlan == null) {
throw new IOException("Unable to determine a plan to assign region(s)");
}
assign(regions.size(), servers.size(), assign(regions.size(), servers.size(),
"retainAssignment=true", bulkPlan); "retainAssignment=true", bulkPlan);
@ -2613,8 +2616,11 @@ public class AssignmentManager extends ZooKeeperListener {
// Generate a round-robin bulk assignment plan // Generate a round-robin bulk assignment plan
Map<ServerName, List<HRegionInfo>> bulkPlan Map<ServerName, List<HRegionInfo>> bulkPlan
= balancer.roundRobinAssignment(regions, servers); = balancer.roundRobinAssignment(regions, servers);
processFavoredNodes(regions); if (bulkPlan == null) {
throw new IOException("Unable to determine a plan to assign region(s)");
}
processFavoredNodes(regions);
assign(regions.size(), servers.size(), assign(regions.size(), servers.size(),
"round-robin=true", bulkPlan); "round-robin=true", bulkPlan);
} }

View File

@ -1073,13 +1073,28 @@ public class HMaster extends HRegionServer implements MasterServices, Server {
final List<ServerName> destServers = this.serverManager.createDestinationServersList( final List<ServerName> destServers = this.serverManager.createDestinationServersList(
regionState.getServerName()); regionState.getServerName());
dest = balancer.randomAssignment(hri, destServers); dest = balancer.randomAssignment(hri, destServers);
} else { if (dest == null) {
dest = ServerName.valueOf(Bytes.toString(destServerName)); LOG.debug("Unable to determine a plan to assign " + hri);
if (dest.equals(regionState.getServerName())) {
LOG.debug("Skipping move of region " + hri.getRegionNameAsString()
+ " because region already assigned to the same server " + dest + ".");
return; return;
} }
} else {
dest = ServerName.valueOf(Bytes.toString(destServerName));
if (dest.equals(serverName) && balancer instanceof BaseLoadBalancer
&& !((BaseLoadBalancer)balancer).shouldBeOnMaster(hri)) {
// To avoid unnecessary region moving later by balancer. Don't put user
// regions on master. Regions on master could be put on other region
// server intentionally by test however.
LOG.debug("Skipping move of region " + hri.getRegionNameAsString()
+ " to avoid unnecessary region moving later by load balancer,"
+ " because it should not be on master");
return;
}
}
if (dest.equals(regionState.getServerName())) {
LOG.debug("Skipping move of region " + hri.getRegionNameAsString()
+ " because region already assigned to the same server " + dest + ".");
return;
} }
// Now we can do the move // Now we can do the move

View File

@ -843,7 +843,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
* Check if a region belongs to some small system table. * Check if a region belongs to some small system table.
* If so, it may be expected to be put on the master regionserver. * If so, it may be expected to be put on the master regionserver.
*/ */
protected boolean shouldBeOnMaster(HRegionInfo region) { public boolean shouldBeOnMaster(HRegionInfo region) {
return tablesOnMaster.contains(region.getTable().getNameAsString()); return tablesOnMaster.contains(region.getTable().getNameAsString());
} }