From fcbcad241911e0e2faa093222cec83a1c063f97b Mon Sep 17 00:00:00 2001 From: Sameet Agarwal Date: Wed, 25 Feb 2015 14:45:29 -0800 Subject: [PATCH] Schedule background thread for MovedRegionCleaner --- .../hadoop/hbase/regionserver/HRegionServer.java | 2 + .../hadoop/hbase/TestMovedRegionsCleaner.java | 118 +++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/TestMovedRegionsCleaner.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 4574a01..98e0fef 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1648,6 +1648,7 @@ public class HRegionServer extends HasThread implements if (this.healthCheckChore != null) choreService.scheduleChore(healthCheckChore); if (this.nonceManagerChore != null) choreService.scheduleChore(nonceManagerChore); if (this.storefileRefresher != null) choreService.scheduleChore(storefileRefresher); + if (this.movedRegionsCleaner != null) choreService.scheduleChore(movedRegionsCleaner); // Leases is not a Thread. Internally it runs a daemon thread. If it gets // an unhandled exception, it will just exit. @@ -2012,6 +2013,7 @@ public class HRegionServer extends HasThread implements if (this.periodicFlusher != null) periodicFlusher.cancel(true); if (this.healthCheckChore != null) healthCheckChore.cancel(true); if (this.storefileRefresher != null) storefileRefresher.cancel(true); + if (this.movedRegionsCleaner != null) movedRegionsCleaner.cancel(true); if (this.cacheFlusher != null) { this.cacheFlusher.join(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMovedRegionsCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMovedRegionsCleaner.java new file mode 100644 index 0000000..e7c473c --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMovedRegionsCleaner.java @@ -0,0 +1,118 @@ +/** + * + * 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; +import org.apache.hadoop.hbase.client.RegionLocator; +import org.apache.hadoop.hbase.master.RegionStates; +import org.apache.hadoop.hbase.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.regionserver.HRegionServer; +import org.apache.hadoop.hbase.regionserver.RSRpcServices; +import org.apache.hadoop.hbase.testclassification.FlakeyTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.apache.hadoop.hbase.testclassification.MiscTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.JVMClusterUtil; +import org.apache.hadoop.hbase.util.Threads; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + + + + +/** + * Test whether background cleanup of MovedRegion entries is happening + * + */ +@Category({MiscTests.class, LargeTests.class}) +public class TestMovedRegionsCleaner { + + public static final Log LOG = LogFactory.getLog(TestRegionRebalancing.class); + private final HBaseTestingUtility UTIL = new HBaseTestingUtility(); + + public static int numCalls = 0; + + private static class TestMockRegionServer extends MiniHBaseCluster.MiniHBaseClusterRegionServer { + + public TestMockRegionServer(Configuration conf, CoordinatedStateManager cp) + throws IOException, InterruptedException { + super(conf, cp); + } + + @Override + protected void cleanMovedRegions() { + // count the number of calls that are being made to this + // + numCalls++; + super.cleanMovedRegions(); + } + } + + + @After + public void after() throws Exception { + UTIL.shutdownMiniCluster(); + } + + @Before + public void before() throws Exception { + UTIL.getConfiguration().setStrings(HConstants.REGION_SERVER_IMPL, TestMockRegionServer.class.getName()); + UTIL.startMiniCluster(1); + } + + /** + * Start the cluster, wait for some time and verify that the background + * MovedRegion cleaner indeed gets called + * @throws IOException + * @throws InterruptedException + */ + @Test + public void testMovedRegionsCleaer() + throws IOException, InterruptedException { + // We need to sleep long enough to trigger at least one round of background calls + // to MovedRegionCleaner happen. Currently the period is set to TIMEOUT_REGION_MOVED (120s). + // Setting the sleep here for 240s just to be safe + // + Thread.sleep(240000); + + // verify that there was at least one call to the cleanMovedRegions function + // + assertTrue("cleanMovedRegions Called", numCalls > 0); + } +} -- 1.9.5