HBASE-9191 Update Loadbalancer method to throw HBaseIOException
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1514155 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ef0a055787
commit
7170a40dec
|
@ -45,6 +45,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.Chore;
|
import org.apache.hadoop.hbase.Chore;
|
||||||
|
import org.apache.hadoop.hbase.HBaseIOException;
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.exceptions.DeserializationException;
|
import org.apache.hadoop.hbase.exceptions.DeserializationException;
|
||||||
|
@ -950,8 +951,12 @@ public class AssignmentManager extends ZooKeeperListener {
|
||||||
if (regionState != null) {
|
if (regionState != null) {
|
||||||
// When there are more than one region server a new RS is selected as the
|
// When there are more than one region server a new RS is selected as the
|
||||||
// destination and the same is updated in the regionplan. (HBASE-5546)
|
// destination and the same is updated in the regionplan. (HBASE-5546)
|
||||||
getRegionPlan(regionState.getRegion(), sn, true);
|
try {
|
||||||
new ClosedRegionHandler(server, this, regionState.getRegion()).process();
|
getRegionPlan(regionState.getRegion(), sn, true);
|
||||||
|
new ClosedRegionHandler(server, this, regionState.getRegion()).process();
|
||||||
|
} catch (HBaseIOException e) {
|
||||||
|
LOG.warn("Failed to get region plan", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1824,7 +1829,11 @@ public class AssignmentManager extends ZooKeeperListener {
|
||||||
RegionOpeningState regionOpenState;
|
RegionOpeningState regionOpenState;
|
||||||
for (int i = 1; i <= maximumAttempts && !server.isStopped(); i++) {
|
for (int i = 1; i <= maximumAttempts && !server.isStopped(); i++) {
|
||||||
if (plan == null) { // Get a server for the region at first
|
if (plan == null) { // Get a server for the region at first
|
||||||
plan = getRegionPlan(region, forceNewPlan);
|
try {
|
||||||
|
plan = getRegionPlan(region, forceNewPlan);
|
||||||
|
} catch (HBaseIOException e) {
|
||||||
|
LOG.warn("Failed to get region plan", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (plan == null) {
|
if (plan == null) {
|
||||||
LOG.warn("Unable to determine a plan to assign " + region);
|
LOG.warn("Unable to determine a plan to assign " + region);
|
||||||
|
@ -1989,8 +1998,12 @@ public class AssignmentManager extends ZooKeeperListener {
|
||||||
// The new plan could be the same as the existing plan since we don't
|
// The new plan could be the same as the existing plan since we don't
|
||||||
// exclude the server of the original plan, which should not be
|
// exclude the server of the original plan, which should not be
|
||||||
// excluded since it could be the only server up now.
|
// excluded since it could be the only server up now.
|
||||||
RegionPlan newPlan = getRegionPlan(region, true);
|
RegionPlan newPlan = null;
|
||||||
|
try {
|
||||||
|
newPlan = getRegionPlan(region, true);
|
||||||
|
} catch (HBaseIOException e) {
|
||||||
|
LOG.warn("Failed to get region plan", e);
|
||||||
|
}
|
||||||
if (newPlan == null) {
|
if (newPlan == null) {
|
||||||
if (tomActivated) {
|
if (tomActivated) {
|
||||||
this.timeoutMonitor.setAllRegionServersOffline(true);
|
this.timeoutMonitor.setAllRegionServersOffline(true);
|
||||||
|
@ -2091,7 +2104,7 @@ public class AssignmentManager extends ZooKeeperListener {
|
||||||
* if no servers to assign, it returns null).
|
* if no servers to assign, it returns null).
|
||||||
*/
|
*/
|
||||||
private RegionPlan getRegionPlan(final HRegionInfo region,
|
private RegionPlan getRegionPlan(final HRegionInfo region,
|
||||||
final boolean forceNewPlan) {
|
final boolean forceNewPlan) throws HBaseIOException {
|
||||||
return getRegionPlan(region, null, forceNewPlan);
|
return getRegionPlan(region, null, forceNewPlan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2105,7 +2118,7 @@ public class AssignmentManager extends ZooKeeperListener {
|
||||||
* if no servers to assign, it returns null).
|
* if no servers to assign, it returns null).
|
||||||
*/
|
*/
|
||||||
private RegionPlan getRegionPlan(final HRegionInfo region,
|
private RegionPlan getRegionPlan(final HRegionInfo region,
|
||||||
final ServerName serverToExclude, final boolean forceNewPlan) {
|
final ServerName serverToExclude, final boolean forceNewPlan) throws HBaseIOException {
|
||||||
// Pickup existing plan or make a new one
|
// Pickup existing plan or make a new one
|
||||||
final String encodedName = region.getEncodedName();
|
final String encodedName = region.getEncodedName();
|
||||||
final List<ServerName> destServers =
|
final List<ServerName> destServers =
|
||||||
|
|
|
@ -1479,7 +1479,7 @@ MasterServices, Server {
|
||||||
return balancerCutoffTime;
|
return balancerCutoffTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean balance() {
|
public boolean balance() throws HBaseIOException {
|
||||||
// if master not initialized, don't run balancer.
|
// if master not initialized, don't run balancer.
|
||||||
if (!this.initialized) {
|
if (!this.initialized) {
|
||||||
LOG.debug("Master has not been initialized, don't run balancer.");
|
LOG.debug("Master has not been initialized, don't run balancer.");
|
||||||
|
@ -1564,7 +1564,11 @@ MasterServices, Server {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BalanceResponse balance(RpcController c, BalanceRequest request) throws ServiceException {
|
public BalanceResponse balance(RpcController c, BalanceRequest request) throws ServiceException {
|
||||||
return BalanceResponse.newBuilder().setBalancerRan(balance()).build();
|
try {
|
||||||
|
return BalanceResponse.newBuilder().setBalancerRan(balance()).build();
|
||||||
|
} catch (HBaseIOException ex) {
|
||||||
|
throw new ServiceException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BalanceSwitchMode {
|
enum BalanceSwitchMode {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Map;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.conf.Configurable;
|
import org.apache.hadoop.conf.Configurable;
|
||||||
import org.apache.hadoop.hbase.ClusterStatus;
|
import org.apache.hadoop.hbase.ClusterStatus;
|
||||||
|
import org.apache.hadoop.hbase.HBaseIOException;
|
||||||
import org.apache.hadoop.hbase.HRegionInfo;
|
import org.apache.hadoop.hbase.HRegionInfo;
|
||||||
import org.apache.hadoop.hbase.ServerName;
|
import org.apache.hadoop.hbase.ServerName;
|
||||||
|
|
||||||
|
@ -64,7 +65,8 @@ public interface LoadBalancer extends Configurable {
|
||||||
* @param clusterState
|
* @param clusterState
|
||||||
* @return List of plans
|
* @return List of plans
|
||||||
*/
|
*/
|
||||||
List<RegionPlan> balanceCluster(Map<ServerName, List<HRegionInfo>> clusterState);
|
List<RegionPlan> balanceCluster(Map<ServerName,
|
||||||
|
List<HRegionInfo>> clusterState) throws HBaseIOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a Round Robin assignment of regions.
|
* Perform a Round Robin assignment of regions.
|
||||||
|
@ -75,7 +77,7 @@ public interface LoadBalancer extends Configurable {
|
||||||
Map<ServerName, List<HRegionInfo>> roundRobinAssignment(
|
Map<ServerName, List<HRegionInfo>> roundRobinAssignment(
|
||||||
List<HRegionInfo> regions,
|
List<HRegionInfo> regions,
|
||||||
List<ServerName> servers
|
List<ServerName> servers
|
||||||
);
|
) throws HBaseIOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign regions to the previously hosting region server
|
* Assign regions to the previously hosting region server
|
||||||
|
@ -86,7 +88,7 @@ public interface LoadBalancer extends Configurable {
|
||||||
Map<ServerName, List<HRegionInfo>> retainAssignment(
|
Map<ServerName, List<HRegionInfo>> retainAssignment(
|
||||||
Map<HRegionInfo, ServerName> regions,
|
Map<HRegionInfo, ServerName> regions,
|
||||||
List<ServerName> servers
|
List<ServerName> servers
|
||||||
);
|
) throws HBaseIOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sync assign a region
|
* Sync assign a region
|
||||||
|
@ -97,7 +99,7 @@ public interface LoadBalancer extends Configurable {
|
||||||
Map<HRegionInfo, ServerName> immediateAssignment(
|
Map<HRegionInfo, ServerName> immediateAssignment(
|
||||||
List<HRegionInfo> regions,
|
List<HRegionInfo> regions,
|
||||||
List<ServerName> servers
|
List<ServerName> servers
|
||||||
);
|
) throws HBaseIOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a random region server from the list
|
* Get a random region server from the list
|
||||||
|
@ -107,5 +109,5 @@ public interface LoadBalancer extends Configurable {
|
||||||
*/
|
*/
|
||||||
ServerName randomAssignment(
|
ServerName randomAssignment(
|
||||||
HRegionInfo regionInfo, List<ServerName> servers
|
HRegionInfo regionInfo, List<ServerName> servers
|
||||||
);
|
) throws HBaseIOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,11 @@
|
||||||
|
|
||||||
package org.apache.hadoop.hbase.master.balancer;
|
package org.apache.hadoop.hbase.master.balancer;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.hbase.Chore;
|
import org.apache.hadoop.hbase.Chore;
|
||||||
|
import org.apache.hadoop.hbase.HBaseIOException;
|
||||||
import org.apache.hadoop.hbase.master.HMaster;
|
import org.apache.hadoop.hbase.master.HMaster;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +31,7 @@ import org.apache.hadoop.hbase.master.HMaster;
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class BalancerChore extends Chore {
|
public class BalancerChore extends Chore {
|
||||||
|
private static final Log LOG = LogFactory.getLog(BalancerChore.class);
|
||||||
|
|
||||||
private final HMaster master;
|
private final HMaster master;
|
||||||
|
|
||||||
|
@ -40,6 +44,10 @@ public class BalancerChore extends Chore {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void chore() {
|
protected void chore() {
|
||||||
master.balance();
|
try {
|
||||||
|
master.balance();
|
||||||
|
} catch (HBaseIOException e) {
|
||||||
|
LOG.error("Failed to balance.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.hbase.HBaseIOException;
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||||
|
@ -93,7 +94,7 @@ public class TestRegionPlacement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFavoredNodesPresentForRoundRobinAssignment() {
|
public void testFavoredNodesPresentForRoundRobinAssignment() throws HBaseIOException {
|
||||||
LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(TEST_UTIL.getConfiguration());
|
LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(TEST_UTIL.getConfiguration());
|
||||||
balancer.setMasterServices(TEST_UTIL.getMiniHBaseCluster().getMaster());
|
balancer.setMasterServices(TEST_UTIL.getMiniHBaseCluster().getMaster());
|
||||||
List<ServerName> servers = new ArrayList<ServerName>();
|
List<ServerName> servers = new ArrayList<ServerName>();
|
||||||
|
@ -153,7 +154,7 @@ public class TestRegionPlacement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFavoredNodesPresentForRandomAssignment() {
|
public void testFavoredNodesPresentForRandomAssignment() throws HBaseIOException {
|
||||||
LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(TEST_UTIL.getConfiguration());
|
LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(TEST_UTIL.getConfiguration());
|
||||||
balancer.setMasterServices(TEST_UTIL.getMiniHBaseCluster().getMaster());
|
balancer.setMasterServices(TEST_UTIL.getMiniHBaseCluster().getMaster());
|
||||||
List<ServerName> servers = new ArrayList<ServerName>();
|
List<ServerName> servers = new ArrayList<ServerName>();
|
||||||
|
|
Loading…
Reference in New Issue