HBASE-8160 HMaster#move doesn't check if master initialized
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1459580 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
89cc0b54eb
commit
3ce9acc3e7
|
@ -293,8 +293,11 @@ Server {
|
|||
private volatile boolean abort = false;
|
||||
// flag set after we become the active master (used for testing)
|
||||
private volatile boolean isActiveMaster = false;
|
||||
// flag set after we complete initialization once active (used for testing)
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
// flag set after we complete initialization once active,
|
||||
// it is not private since it's used in unit tests
|
||||
volatile boolean initialized = false;
|
||||
|
||||
// flag set after we complete assignMeta.
|
||||
private volatile boolean serverShutdownHandlerEnabled = false;
|
||||
|
||||
|
@ -1397,11 +1400,21 @@ Server {
|
|||
LOG.warn("moveRegion specifier type: expected: " + RegionSpecifierType.ENCODED_REGION_NAME
|
||||
+ " actual: " + type);
|
||||
}
|
||||
|
||||
try {
|
||||
move(encodedRegionName, destServerName);
|
||||
} catch (IOException ioe) {
|
||||
throw new ServiceException(ioe);
|
||||
}
|
||||
return mrr;
|
||||
}
|
||||
|
||||
void move(final byte[] encodedRegionName,
|
||||
final byte[] destServerName) throws UnknownRegionException {
|
||||
RegionState regionState = assignmentManager.getRegionStates().
|
||||
getRegionState(Bytes.toString(encodedRegionName));
|
||||
if (regionState == null) {
|
||||
throw new ServiceException(
|
||||
new UnknownRegionException(Bytes.toStringBinary(encodedRegionName)));
|
||||
throw new UnknownRegionException(Bytes.toStringBinary(encodedRegionName));
|
||||
}
|
||||
|
||||
HRegionInfo hri = regionState.getRegion();
|
||||
|
@ -1417,7 +1430,7 @@ Server {
|
|||
if (dest.equals(regionState.getServerName())) {
|
||||
LOG.debug("Skipping move of region " + hri.getRegionNameAsString()
|
||||
+ " because region already assigned to the same server " + dest + ".");
|
||||
return mrr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1425,9 +1438,10 @@ Server {
|
|||
RegionPlan rp = new RegionPlan(hri, regionState.getServerName(), dest);
|
||||
|
||||
try {
|
||||
checkInitialized();
|
||||
if (this.cpHost != null) {
|
||||
if (this.cpHost.preMove(hri, rp.getSource(), rp.getDestination())) {
|
||||
return mrr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG.info("Added move plan " + rp + ", running balancer");
|
||||
|
@ -1439,9 +1453,8 @@ Server {
|
|||
UnknownRegionException ure = new UnknownRegionException(
|
||||
Bytes.toStringBinary(encodedRegionName));
|
||||
ure.initCause(ioe);
|
||||
throw new ServiceException(ure);
|
||||
throw ure;
|
||||
}
|
||||
return mrr;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,12 +23,14 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.apache.hadoop.hbase.*;
|
||||
import org.apache.hadoop.hbase.catalog.MetaReader;
|
||||
import org.apache.hadoop.hbase.client.HTable;
|
||||
import org.apache.hadoop.hbase.exceptions.PleaseHoldException;
|
||||
import org.apache.hadoop.hbase.executor.EventHandler;
|
||||
import org.apache.hadoop.hbase.executor.EventHandler.EventHandlerListener;
|
||||
import org.apache.hadoop.hbase.executor.EventType;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.util.Pair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -52,7 +54,7 @@ public class TestMaster {
|
|||
@BeforeClass
|
||||
public static void beforeAllTests() throws Exception {
|
||||
// Start a cluster of two regionservers.
|
||||
TEST_UTIL.startMiniCluster(1);
|
||||
TEST_UTIL.startMiniCluster(2);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -113,6 +115,22 @@ public class TestMaster {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveRegionWhenNotInitialized() {
|
||||
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
|
||||
HMaster m = cluster.getMaster();
|
||||
try {
|
||||
m.initialized = false; // fake it, set back later
|
||||
HRegionInfo meta = HRegionInfo.FIRST_META_REGIONINFO;
|
||||
m.move(meta.getEncodedNameAsBytes(), null);
|
||||
fail("Region should not be moved since master is not initialized");
|
||||
} catch (IOException ioe) {
|
||||
assertTrue(ioe.getCause() instanceof PleaseHoldException);
|
||||
} finally {
|
||||
m.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
static class RegionSplitListener implements EventHandlerListener {
|
||||
CountDownLatch split, proceed;
|
||||
|
||||
|
|
Loading…
Reference in New Issue