diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 0e17a96d194..20277aaae64 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -2627,6 +2627,21 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { return rows; } + /* + * Find any other region server which is different from the one identified by parameter + * @param rs + * @return another region server + */ + public HRegionServer getOtherRegionServer(HRegionServer rs) { + for (JVMClusterUtil.RegionServerThread rst : + getMiniHBaseCluster().getRegionServerThreads()) { + if (!(rst.getRegionServer() == rs)) { + return rst.getRegionServer(); + } + } + return null; + } + /** * Tool to get the reference to the region server object that holds the * region of the specified user table. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionInDeadRegionServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionInDeadRegionServer.java index cebae4f8fb2..879823b944b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionInDeadRegionServer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionInDeadRegionServer.java @@ -21,7 +21,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.HBaseTestingUtility; @@ -49,6 +52,7 @@ import org.junit.experimental.categories.Category; */ @Category({ RegionServerTests.class, LargeTests.class }) public class TestCompactionInDeadRegionServer { + private static final Log LOG = LogFactory.getLog(TestCompactionInDeadRegionServer.class); private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); @@ -104,8 +108,21 @@ public class TestCompactionInDeadRegionServer { @Test public void test() throws Exception { + HRegionServer regionSvr = UTIL.getRSForFirstRegionInTable(TABLE_NAME); + Region region = regionSvr.getOnlineRegions(TABLE_NAME).get(0); + String regName = region.getRegionInfo().getEncodedName(); + List metaRegs = regionSvr.getOnlineRegions(TableName.META_TABLE_NAME); + if (metaRegs != null && !metaRegs.isEmpty()) { + LOG.info("meta is on the same server: " + regionSvr); + // when region is on same server as hbase:meta, reassigning meta would abort the server + // since WAL is broken. + // so the region is moved to a different server + HRegionServer otherRs = UTIL.getOtherRegionServer(regionSvr); + UTIL.moveRegionAndWait(region.getRegionInfo(), otherRs.getServerName()); + LOG.info("Moved region: " + regName + " to " + otherRs.getServerName()); + } final HRegionServer rsToSuspend = UTIL.getRSForFirstRegionInTable(TABLE_NAME); - HRegion region = (HRegion) rsToSuspend.getOnlineRegions(TABLE_NAME).get(0); + region = (HRegion) rsToSuspend.getOnlineRegions(TABLE_NAME).get(0); ZooKeeperWatcher watcher = UTIL.getZooKeeperWatcher(); watcher.getRecoverableZooKeeper() .delete(ZKUtil.joinZNode(watcher.rsZNode, rsToSuspend.getServerName().toString()), -1); @@ -128,11 +145,11 @@ public class TestCompactionInDeadRegionServer { } }); try { - region.compact(true); + ((HRegion)region).compact(true); fail("Should fail as our wal file has already been closed, " + "and walDir has also been renamed"); } catch (Exception e) { - // expected + LOG.debug("expected exception: ", e); } Table table = UTIL.getConnection().getTable(TABLE_NAME); // should not hit FNFE