HBASE-8173 HMaster#move wraps IOException in UnknownRegionException

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1460793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jxiang 2013-03-25 17:57:06 +00:00
parent 0abf9afff6
commit 3d6dee2c3c
5 changed files with 62 additions and 15 deletions

View File

@ -50,6 +50,7 @@ import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitorBase;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.exceptions.FailedLogCloseException;
import org.apache.hadoop.hbase.exceptions.HBaseIOException;
import org.apache.hadoop.hbase.exceptions.HBaseSnapshotException;
import org.apache.hadoop.hbase.exceptions.MasterNotRunningException;
import org.apache.hadoop.hbase.exceptions.NotServingRegionException;
@ -1516,15 +1517,15 @@ public class HBaseAdmin implements Abortable, Closeable {
* @throws MasterNotRunningException
*/
public void move(final byte [] encodedRegionName, final byte [] destServerName)
throws UnknownRegionException, MasterNotRunningException, ZooKeeperConnectionException {
throws HBaseIOException, MasterNotRunningException, ZooKeeperConnectionException {
MasterAdminKeepAliveConnection master = connection.getKeepAliveMasterAdmin();
try {
MoveRegionRequest request = RequestConverter.buildMoveRegionRequest(encodedRegionName, destServerName);
master.moveRegion(null,request);
} catch (ServiceException se) {
IOException ioe = ProtobufUtil.getRemoteException(se);
if (ioe instanceof UnknownRegionException) {
throw (UnknownRegionException)ioe;
if (ioe instanceof HBaseIOException) {
throw (HBaseIOException)ioe;
}
LOG.error("Unexpected exception: " + se + " from calling HMaster.moveRegion");
} catch (DeserializationException de) {

View File

@ -21,14 +21,13 @@ package org.apache.hadoop.hbase.exceptions;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import java.io.IOException;
/**
* Thrown when something happens related to region handling.
* Subclasses have to be more specific.
*/
@InterfaceAudience.Public
@InterfaceStability.Stable
public class RegionException extends IOException {
public class RegionException extends HBaseIOException {
private static final long serialVersionUID = 1473510258071111371L;
/** default constructor */

View File

@ -69,6 +69,7 @@ import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitorBase;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.exceptions.HBaseIOException;
import org.apache.hadoop.hbase.exceptions.MasterNotRunningException;
import org.apache.hadoop.hbase.exceptions.NotAllMetaRegionsOnlineException;
import org.apache.hadoop.hbase.exceptions.PleaseHoldException;
@ -1465,14 +1466,14 @@ Server {
try {
move(encodedRegionName, destServerName);
} catch (IOException ioe) {
} catch (HBaseIOException ioe) {
throw new ServiceException(ioe);
}
return mrr;
}
void move(final byte[] encodedRegionName,
final byte[] destServerName) throws UnknownRegionException {
final byte[] destServerName) throws HBaseIOException {
RegionState regionState = assignmentManager.getRegionStates().
getRegionState(Bytes.toString(encodedRegionName));
if (regionState == null) {
@ -1512,10 +1513,10 @@ Server {
this.cpHost.postMove(hri, rp.getSource(), rp.getDestination());
}
} catch (IOException ioe) {
UnknownRegionException ure = new UnknownRegionException(
Bytes.toStringBinary(encodedRegionName));
ure.initCause(ioe);
throw ure;
if (ioe instanceof HBaseIOException) {
throw (HBaseIOException)ioe;
}
throw new HBaseIOException(ioe);
}
}

View File

@ -22,8 +22,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.catalog.MetaReader;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.exceptions.PleaseHoldException;
import org.apache.hadoop.hbase.exceptions.UnknownRegionException;
import org.apache.hadoop.hbase.executor.EventHandler;
import org.apache.hadoop.hbase.executor.EventHandler.EventHandlerListener;
import org.apache.hadoop.hbase.executor.EventType;
@ -50,11 +52,13 @@ public class TestMaster {
private static final Log LOG = LogFactory.getLog(TestMaster.class);
private static final byte[] TABLENAME = Bytes.toBytes("TestMaster");
private static final byte[] FAMILYNAME = Bytes.toBytes("fam");
private static HBaseAdmin admin;
@BeforeClass
public static void beforeAllTests() throws Exception {
// Start a cluster of two regionservers.
TEST_UTIL.startMiniCluster(2);
admin = TEST_UTIL.getHBaseAdmin();
}
@AfterClass
@ -125,12 +129,55 @@ public class TestMaster {
m.move(meta.getEncodedNameAsBytes(), null);
fail("Region should not be moved since master is not initialized");
} catch (IOException ioe) {
assertTrue(ioe.getCause() instanceof PleaseHoldException);
assertTrue(ioe instanceof PleaseHoldException);
} finally {
m.initialized = true;
}
}
@Test
public void testMoveThrowsUnknownRegionException() throws IOException {
byte[] tableName = Bytes.toBytes("testMoveThrowsUnknownRegionException");
HTableDescriptor htd = new HTableDescriptor(tableName);
HColumnDescriptor hcd = new HColumnDescriptor("value");
htd.addFamily(hcd);
admin.createTable(htd, null);
try {
HRegionInfo hri = new HRegionInfo(
tableName, Bytes.toBytes("A"), Bytes.toBytes("Z"));
admin.move(hri.getEncodedNameAsBytes(), null);
fail("Region should not be moved since it is fake");
} catch (IOException ioe) {
assertTrue(ioe instanceof UnknownRegionException);
} finally {
TEST_UTIL.deleteTable(tableName);
}
}
@Test
public void testMoveThrowsPleaseHoldException() throws IOException {
byte[] tableName = Bytes.toBytes("testMoveThrowsPleaseHoldException");
HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
HTableDescriptor htd = new HTableDescriptor(tableName);
HColumnDescriptor hcd = new HColumnDescriptor("value");
htd.addFamily(hcd);
admin.createTable(htd, null);
try {
List<HRegionInfo> tableRegions = admin.getTableRegions(tableName);
master.initialized = false; // fake it, set back later
admin.move(tableRegions.get(0).getEncodedNameAsBytes(), null);
fail("Region should not be moved since master is not initialized");
} catch (IOException ioe) {
assertTrue(ioe instanceof PleaseHoldException);
} finally {
master.initialized = true;
TEST_UTIL.deleteTable(tableName);
}
}
static class RegionSplitListener implements EventHandlerListener {
CountDownLatch split, proceed;

View File

@ -35,10 +35,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.LargeTests;
import org.apache.hadoop.hbase.MiniHBaseCluster;
import org.apache.hadoop.hbase.RegionTransition;
@ -50,6 +48,7 @@ import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.exceptions.HBaseIOException;
import org.apache.hadoop.hbase.exceptions.MasterNotRunningException;
import org.apache.hadoop.hbase.exceptions.UnknownRegionException;
import org.apache.hadoop.hbase.exceptions.ZooKeeperConnectionException;
@ -811,7 +810,7 @@ public class TestSplitTransactionOnCluster {
*/
private int ensureTableRegionNotOnSameServerAsMeta(final HBaseAdmin admin,
final HRegionInfo hri)
throws UnknownRegionException, MasterNotRunningException,
throws HBaseIOException, MasterNotRunningException,
ZooKeeperConnectionException, InterruptedException {
// Now make sure that the table region is not on same server as that hosting
// .META. We don't want .META. replay polluting our test when we later crash