use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.
the class RSGroupBasedLoadBalancer method retainAssignment.
@Override
@NonNull
public Map<ServerName, List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions, List<ServerName> servers) throws HBaseIOException {
try {
Map<ServerName, List<RegionInfo>> assignments = new TreeMap<>();
List<Pair<List<RegionInfo>, List<ServerName>>> pairs = generateGroupAssignments(Lists.newArrayList(regions.keySet()), servers);
for (Pair<List<RegionInfo>, List<ServerName>> pair : pairs) {
List<RegionInfo> regionList = pair.getFirst();
Map<RegionInfo, ServerName> currentAssignmentMap = Maps.newTreeMap();
regionList.forEach(r -> currentAssignmentMap.put(r, regions.get(r)));
Map<ServerName, List<RegionInfo>> pairResult = this.internalBalancer.retainAssignment(currentAssignmentMap, pair.getSecond());
pairResult.forEach((server, rs) -> assignments.computeIfAbsent(server, s -> Lists.newArrayList()).addAll(rs));
}
return assignments;
} catch (IOException e) {
throw new HBaseIOException("Failed to do online retain assignment", e);
}
}
use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.
the class RSGroupBasedLoadBalancer method initialize.
@Override
public void initialize() throws IOException {
if (rsGroupInfoManager == null) {
rsGroupInfoManager = masterServices.getRSGroupInfoManager();
if (rsGroupInfoManager == null) {
String msg = "RSGroupInfoManager hasn't been initialized";
LOG.error(msg);
throw new HBaseIOException(msg);
}
rsGroupInfoManager.start();
}
// Create the balancer
Configuration conf = masterServices.getConfiguration();
Class<? extends LoadBalancer> balancerClass;
@SuppressWarnings("deprecation") String balancerClassName = conf.get(HBASE_RSGROUP_LOADBALANCER_CLASS);
if (balancerClassName == null) {
balancerClass = conf.getClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, LoadBalancerFactory.getDefaultLoadBalancerClass(), LoadBalancer.class);
} else {
try {
balancerClass = Class.forName(balancerClassName).asSubclass(LoadBalancer.class);
} catch (ClassNotFoundException e) {
throw new IOException(e);
}
}
this.provider = new MasterClusterInfoProvider(masterServices);
// avoid infinite nesting
if (getClass().isAssignableFrom(balancerClass)) {
balancerClass = LoadBalancerFactory.getDefaultLoadBalancerClass();
}
internalBalancer = ReflectionUtils.newInstance(balancerClass);
internalBalancer.setClusterInfoProvider(provider);
// special handling for favor node balancers
if (internalBalancer instanceof FavoredNodesPromoter) {
favoredNodesManager = new FavoredNodesManager(provider);
((FavoredNodesPromoter) internalBalancer).setFavoredNodesManager(favoredNodesManager);
}
internalBalancer.initialize();
// init fallback groups
this.fallbackEnabled = conf.getBoolean(FALLBACK_GROUP_ENABLE_KEY, false);
}
use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.
the class HMaster method executeRegionPlansWithThrottling.
/**
* Execute region plans with throttling
* @param plans to execute
* @return succeeded plans
*/
public List<RegionPlan> executeRegionPlansWithThrottling(List<RegionPlan> plans) {
List<RegionPlan> successRegionPlans = new ArrayList<>();
int maxRegionsInTransition = getMaxRegionsInTransition();
long balanceStartTime = EnvironmentEdgeManager.currentTime();
long cutoffTime = balanceStartTime + this.maxBalancingTime;
// number of RegionPlans balanced so far
int rpCount = 0;
if (plans != null && !plans.isEmpty()) {
int balanceInterval = this.maxBalancingTime / plans.size();
LOG.info("Balancer plans size is " + plans.size() + ", the balance interval is " + balanceInterval + " ms, and the max number regions in transition is " + maxRegionsInTransition);
for (RegionPlan plan : plans) {
LOG.info("balance " + plan);
// TODO: bulk assign
try {
this.assignmentManager.balance(plan);
} catch (HBaseIOException hioe) {
// should ignore failed plans here, avoiding the whole balance plans be aborted
// later calls of balance() can fetch up the failed and skipped plans
LOG.warn("Failed balance plan {}, skipping...", plan, hioe);
}
// rpCount records balance plans processed, does not care if a plan succeeds
rpCount++;
successRegionPlans.add(plan);
if (this.maxBalancingTime > 0) {
balanceThrottling(balanceStartTime + rpCount * balanceInterval, maxRegionsInTransition, cutoffTime);
}
// if performing next balance exceeds cutoff time, exit the loop
if (this.maxBalancingTime > 0 && rpCount < plans.size() && EnvironmentEdgeManager.currentTime() > cutoffTime) {
// TODO: After balance, there should not be a cutoff time (keeping it as
// a security net for now)
LOG.debug("No more balancing till next balance run; maxBalanceTime=" + this.maxBalancingTime);
break;
}
}
}
LOG.debug("Balancer is going into sleep until next period in {}ms", getConfiguration().getInt(HConstants.HBASE_BALANCER_PERIOD, HConstants.DEFAULT_HBASE_BALANCER_PERIOD));
return successRegionPlans;
}
use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.
the class HMaster method decommissionRegionServers.
/**
* Mark region server(s) as decommissioned (previously called 'draining') to prevent additional
* regions from getting assigned to them. Also unload the regions on the servers asynchronously.0
* @param servers Region servers to decommission.
*/
public void decommissionRegionServers(final List<ServerName> servers, final boolean offload) throws IOException {
List<ServerName> serversAdded = new ArrayList<>(servers.size());
// Place the decommission marker first.
String parentZnode = getZooKeeper().getZNodePaths().drainingZNode;
for (ServerName server : servers) {
try {
String node = ZNodePaths.joinZNode(parentZnode, server.getServerName());
ZKUtil.createAndFailSilent(getZooKeeper(), node);
} catch (KeeperException ke) {
throw new HBaseIOException(this.zooKeeper.prefix("Unable to decommission '" + server.getServerName() + "'."), ke);
}
if (this.serverManager.addServerToDrainList(server)) {
serversAdded.add(server);
}
}
// Move the regions off the decommissioned servers.
if (offload) {
final List<ServerName> destServers = this.serverManager.createDestinationServersList();
for (ServerName server : serversAdded) {
final List<RegionInfo> regionsOnServer = this.assignmentManager.getRegionsOnServer(server);
for (RegionInfo hri : regionsOnServer) {
ServerName dest = balancer.randomAssignment(hri, destServers);
if (dest == null) {
throw new HBaseIOException("Unable to determine a plan to move " + hri);
}
RegionPlan rp = new RegionPlan(hri, server, dest);
this.assignmentManager.moveAsync(rp);
}
}
}
}
use of org.apache.hadoop.hbase.HBaseIOException in project hbase by apache.
the class MasterRegion method createWAL.
private static WAL createWAL(WALFactory walFactory, MasterRegionWALRoller walRoller, String serverName, FileSystem walFs, Path walRootDir, RegionInfo regionInfo) throws IOException {
String logName = AbstractFSWALProvider.getWALDirectoryName(serverName);
Path walDir = new Path(walRootDir, logName);
LOG.debug("WALDir={}", walDir);
if (walFs.exists(walDir)) {
throw new HBaseIOException("Already created wal directory at " + walDir + " for local region " + regionInfo);
}
if (!walFs.mkdirs(walDir)) {
throw new IOException("Can not create wal directory " + walDir + " for local region " + regionInfo);
}
WAL wal = walFactory.getWAL(regionInfo);
walRoller.addWAL(wal);
return wal;
}
Aggregations