Author: stack
Date: Sat Sep 10 17:48:17 2011
New Revision: 1167567
URL: http://svn.apache.org/viewvc?rev=1167567&view=rev
Log:
HBASE-4270 IOE ignored during flush-on-close causes dataloss
Added:
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockRegionServerServices.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockServer.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestCloseRegionHandler.java
Added:
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockRegionServerServices.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockRegionServerServices.java?rev=1167567&view=auto
==============================================================================
---
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockRegionServerServices.java
(added)
+++
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockRegionServerServices.java
Sat Sep 10 17:48:17 2011
@@ -0,0 +1,135 @@
+/**
+ * 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.handler;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.catalog.CatalogTracker;
+import org.apache.hadoop.hbase.ipc.HBaseRpcMetrics;
+import org.apache.hadoop.hbase.regionserver.CompactionRequestor;
+import org.apache.hadoop.hbase.regionserver.FlushRequester;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.RegionServerAccounting;
+import org.apache.hadoop.hbase.regionserver.RegionServerServices;
+import org.apache.hadoop.hbase.regionserver.wal.HLog;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.zookeeper.KeeperException;
+
+/**
+ * Basic mock region server services.
+ */
+class MockRegionServerServices implements RegionServerServices {
+ private final Map<String, HRegion> regions = new HashMap<String, HRegion>();
+ private boolean stopping = false;
+ private final Set<byte[]> rit = new HashSet<byte[]>();
+
+ @Override
+ public boolean removeFromOnlineRegions(String encodedRegionName) {
+ return this.regions.remove(encodedRegionName) != null;
+ }
+
+ @Override
+ public HRegion getFromOnlineRegions(String encodedRegionName) {
+ return this.regions.get(encodedRegionName);
+ }
+
+ @Override
+ public void addToOnlineRegions(HRegion r) {
+ this.regions.put(r.getRegionInfo().getEncodedName(), r);
+ }
+
+ @Override
+ public void postOpenDeployTasks(HRegion r, CatalogTracker ct, boolean
daughter)
+ throws KeeperException, IOException {
+ }
+
+ @Override
+ public boolean isStopping() {
+ return this.stopping;
+ }
+
+ @Override
+ public HLog getWAL() {
+ return null;
+ }
+
+ @Override
+ public HBaseRpcMetrics getRpcMetrics() {
+ return null;
+ }
+
+ @Override
+ public Set<byte[]> getRegionsInTransitionInRS() {
+ return rit;
+ }
+
+ @Override
+ public FlushRequester getFlushRequester() {
+ return null;
+ }
+
+ @Override
+ public CompactionRequestor getCompactionRequester() {
+ return null;
+ }
+
+ @Override
+ public CatalogTracker getCatalogTracker() {
+ return null;
+ }
+
+ @Override
+ public ZooKeeperWatcher getZooKeeper() {
+ return null;
+ }
+
+ public RegionServerAccounting getRegionServerAccounting() {
+ return null;
+ }
+
+ @Override
+ public ServerName getServerName() {
+ return null;
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ return null;
+ }
+
+ @Override
+ public void abort(String why, Throwable e) {
+ //no-op
+ }
+
+ @Override
+ public void stop(String why) {
+ //no-op
+ }
+
+ @Override
+ public boolean isStopped() {
+ return false;
+ }
+}
\ No newline at end of file
Added:
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockServer.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockServer.java?rev=1167567&view=auto
==============================================================================
---
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockServer.java
(added)
+++
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/MockServer.java
Sat Sep 10 17:48:17 2011
@@ -0,0 +1,103 @@
+/**
+ * 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.handler;
+
+import java.io.IOException;
+
+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.Server;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.ZooKeeperConnectionException;
+import org.apache.hadoop.hbase.catalog.CatalogTracker;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+
+/**
+ * Basic mock Server for handler tests.
+ */
+class MockServer implements Server {
+ static final Log LOG = LogFactory.getLog(MockServer.class);
+ boolean stopped = false;
+ final static ServerName NAME = new ServerName("MockServer", 123, -1);
+ final ZooKeeperWatcher zk;
+ final HBaseTestingUtility htu;
+
+ @SuppressWarnings("unused")
+ private MockServer() throws ZooKeeperConnectionException, IOException {
+ // Shutdown default constructor by making it private.
+ this(null);
+ }
+
+ MockServer(final HBaseTestingUtility htu)
+ throws ZooKeeperConnectionException, IOException {
+ this(htu, true);
+ }
+
+ /**
+ * @param htu Testing utility to use
+ * @param zkw If true, create a zkw.
+ * @throws ZooKeeperConnectionException
+ * @throws IOException
+ */
+ MockServer(final HBaseTestingUtility htu, final boolean zkw)
+ throws ZooKeeperConnectionException, IOException {
+ this.htu = htu;
+ this.zk = zkw?
+ new ZooKeeperWatcher(htu.getConfiguration(), NAME.toString(), this,
true):
+ null;
+ }
+
+ @Override
+ public void abort(String why, Throwable e) {
+ LOG.fatal("Abort why=" + why, e);
+ this.stopped = true;
+ }
+
+ @Override
+ public void stop(String why) {
+ LOG.debug("Stop why=" + why);
+ this.stopped = true;
+ }
+
+ @Override
+ public boolean isStopped() {
+ return this.stopped;
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ return this.htu.getConfiguration();
+ }
+
+ @Override
+ public ZooKeeperWatcher getZooKeeper() {
+ return this.zk;
+ }
+
+ @Override
+ public CatalogTracker getCatalogTracker() {
+ return null;
+ }
+
+ @Override
+ public ServerName getServerName() {
+ return NAME;
+ }
+}
Added:
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestCloseRegionHandler.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestCloseRegionHandler.java?rev=1167567&view=auto
==============================================================================
---
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestCloseRegionHandler.java
(added)
+++
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestCloseRegionHandler.java
Sat Sep 10 17:48:17 2011
@@ -0,0 +1,89 @@
+/**
+ * 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.handler;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.Server;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.RegionServerServices;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.KeeperException.NodeExistsException;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Test of the {@link CloseRegionHandler}.
+ */
+public class TestCloseRegionHandler {
+ static final Log LOG = LogFactory.getLog(TestCloseRegionHandler.class);
+ private final static HBaseTestingUtility HTU = new HBaseTestingUtility();
+
+ /**
+ * Test that if we fail a flush, abort gets set on close.
+ * @see <a
href="https://issues.apache.org/jira/browse/HBASE-4270">HBASE-4270</a>
+ * @throws IOException
+ * @throws NodeExistsException
+ * @throws KeeperException
+ */
+ @Test public void testFailedFlushAborts()
+ throws IOException, NodeExistsException, KeeperException {
+ final Server server = new MockServer(HTU, false);
+ final RegionServerServices rss = new MockRegionServerServices();
+ HTableDescriptor htd = new HTableDescriptor("testFailedFlushAborts");
+ final HRegionInfo hri =
+ new HRegionInfo(htd.getName(), HConstants.EMPTY_END_ROW,
+ HConstants.EMPTY_END_ROW);
+ HRegion region =
+ HRegion.createHRegion(hri, HBaseTestingUtility.getTestDir(),
+ HTU.getConfiguration(), htd);
+ assertNotNull(region);
+ // Spy on the region so can throw exception when close is called.
+ HRegion spy = Mockito.spy(region);
+ final boolean abort = false;
+ Mockito.when(spy.close(abort)).
+ thenThrow(new RuntimeException("Mocked failed close!"));
+ // The CloseRegionHandler will try to get an HRegion that corresponds
+ // to the passed hri -- so insert the region into the online region Set.
+ rss.addToOnlineRegions(spy);
+ // Assert the Server is NOT stopped before we call close region.
+ assertFalse(server.isStopped());
+ CloseRegionHandler handler =
+ new CloseRegionHandler(server, rss, hri, false, false);
+ boolean throwable = false;
+ try {
+ handler.process();
+ } catch (Throwable t) {
+ throwable = true;
+ } finally {
+ assertTrue(throwable);
+ // Abort calls stop so stopped flag should be set.
+ assertTrue(server.isStopped());
+ }
+ }
+}
\ No newline at end of file