From e20615b91720c1ed90e616c4b6c9f80bab634f1c Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Fri, 15 Oct 2010 20:46:13 +0000 Subject: [PATCH] HBASE-3113 Don't reassign regions if cluster is being shutdown; part 2 git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1023107 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/master/AssignmentManager.java | 31 ++++++++++++++++--- .../hbase/regionserver/HRegionServer.java | 1 + .../RegionServerClosedException.java | 29 +++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerClosedException.java diff --git a/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java b/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java index 1c6a9692d67..716e6569d82 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java +++ b/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java @@ -682,6 +682,7 @@ public class AssignmentManager extends ZooKeeperListener { private void assign(final RegionState state) { if (!setOfflineInZooKeeper(state)) return; RegionPlan plan = getRegionPlan(state); + if (plan == null) return; // Should get reassigned later when RIT times out. try { LOG.debug("Assigning region " + state.getRegion().getRegionNameAsString() + " to " + plan.getDestination().getServerName()); @@ -696,6 +697,10 @@ public class AssignmentManager extends ZooKeeperListener { // Clean out plan we failed execute and one that doesn't look like it'll // succeed anyways; we need a new plan! this.regionPlans.remove(state.getRegion().getEncodedName()); + // Put in place a new plan and reassign. Calling getRegionPlan will add + // a plan if none exists (We removed it in line above). + if (getRegionPlan(state) == null) return; + assign(state); } } @@ -729,14 +734,32 @@ public class AssignmentManager extends ZooKeeperListener { /** * @param state - * @return Plan for passed state (If none currently, it creates one) + * @return Plan for passed state (If none currently, it creates one or + * if no servers to assign, it returns null). */ RegionPlan getRegionPlan(final RegionState state) { + return getRegionPlan(state, null); + } + + /** + * @param state + * @param serverToExclude Server to exclude (we know its bad). Pass null if + * all servers are thought to be assignable. + * @return Plan for passed state (If none currently, it creates one or + * if no servers to assign, it returns null). + */ + RegionPlan getRegionPlan(final RegionState state, + final HServerInfo serverToExclude) { // Pickup existing plan or make a new one String encodedName = state.getRegion().getEncodedName(); + List servers = this.serverManager.getOnlineServersList(); + // The remove below hinges on the fact that the call to + // serverManager.getOnlineServersList() returns a copy + if (serverToExclude != null) servers.remove(serverToExclude); + if (servers.size() < 0) return null; RegionPlan newPlan = new RegionPlan(state.getRegion(), null, - LoadBalancer.randomAssignment(serverManager.getOnlineServersList())); - RegionPlan existingPlan = regionPlans.putIfAbsent(encodedName, newPlan); + LoadBalancer.randomAssignment(servers)); + RegionPlan existingPlan = this.regionPlans.putIfAbsent(encodedName, newPlan); RegionPlan plan = null; if (existingPlan == null) { LOG.debug("No previous transition plan for " + @@ -744,7 +767,7 @@ public class AssignmentManager extends ZooKeeperListener { " so generated a random one; " + newPlan + "; " + serverManager.countOfRegionServers() + " (online=" + serverManager.getOnlineServers().size() + - ") available servers"); + ", exclude=" + serverToExclude + ") available servers"); plan = newPlan; } else { LOG.debug("Using preexisting plan=" + existingPlan); diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index acb40ac466c..692e6573abc 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1932,6 +1932,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, public void openRegion(HRegionInfo region) { LOG.info("Received request to open region: " + region.getRegionNameAsString()); + if (this.stopped) throw new RegionServerStoppedException(); if (region.isRootRegion()) { this.service.submit(new OpenRootHandler(this, this, region)); } else if(region.isMetaRegion()) { diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerClosedException.java b/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerClosedException.java new file mode 100644 index 00000000000..e024d029543 --- /dev/null +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerClosedException.java @@ -0,0 +1,29 @@ +/** + * Copyright 2010 The Apache Software Foundation + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.regionserver; + +import org.apache.hadoop.hbase.DoNotRetryIOException; + +/** + * Thrown by the region server when it is shutting down state. + */ +@SuppressWarnings("serial") +public class RegionServerClosedException extends DoNotRetryIOException { +} \ No newline at end of file