You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by at...@apache.org on 2013/02/05 04:18:15 UTC
svn commit: r1442461 - in
/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs: CHANGES.txt
src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java
Author: atm
Date: Tue Feb 5 03:18:14 2013
New Revision: 1442461
URL: http://svn.apache.org/viewvc?rev=1442461&view=rev
Log:
HDFS-4404. Create file failure when the machine of first attempted NameNode is down. Contributed by Todd Lipcon.
Modified:
hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java
Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1442461&r1=1442460&r2=1442461&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Tue Feb 5 03:18:14 2013
@@ -756,6 +756,9 @@ Release 2.0.3-alpha - Unreleased
HDFS-4462. 2NN will fail to checkpoint after an HDFS upgrade from a
pre-federation version of HDFS. (atm)
+ HDFS-4404. Create file failure when the machine of first attempted NameNode
+ is down. (Todd Lipcon via atm)
+
BREAKDOWN OF HDFS-3077 SUBTASKS
HDFS-3077. Quorum-based protocol for reading and writing edit logs.
Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java?rev=1442461&r1=1442460&r2=1442461&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java (original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientFailover.java Tue Feb 5 03:18:14 2013
@@ -23,22 +23,34 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
+import javax.net.SocketFactory;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider;
import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil;
+import org.apache.hadoop.io.IOUtils;
+import org.apache.hadoop.net.ConnectTimeoutException;
+import org.apache.hadoop.net.StandardSocketFactory;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.StringUtils;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
public class TestDFSClientFailover {
@@ -92,6 +104,63 @@ public class TestDFSClientFailover {
}
/**
+ * Test that even a non-idempotent method will properly fail-over if the
+ * first IPC attempt times out trying to connect. Regression test for
+ * HDFS-4404.
+ */
+ @Test
+ public void testFailoverOnConnectTimeout() throws Exception {
+ conf.setClass(CommonConfigurationKeysPublic.HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY,
+ InjectingSocketFactory.class, SocketFactory.class);
+ // Set up the InjectingSocketFactory to throw a ConnectTimeoutException
+ // when connecting to the first NN.
+ InjectingSocketFactory.portToInjectOn = cluster.getNameNodePort(0);
+
+ FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
+
+ // Make the second NN the active one.
+ cluster.shutdownNameNode(0);
+ cluster.transitionToActive(1);
+
+ // Call a non-idempotent method, and ensure the failover of the call proceeds
+ // successfully.
+ IOUtils.closeStream(fs.create(TEST_FILE));
+ }
+
+ private static class InjectingSocketFactory extends StandardSocketFactory {
+
+ static SocketFactory defaultFactory = SocketFactory.getDefault();
+
+ static int portToInjectOn;
+
+ @Override
+ public Socket createSocket() throws IOException {
+ Socket spy = Mockito.spy(defaultFactory.createSocket());
+ // Simplify our spying job by not having to also spy on the channel
+ Mockito.doReturn(null).when(spy).getChannel();
+ // Throw a ConnectTimeoutException when connecting to our target "bad"
+ // host.
+ Mockito.doThrow(new ConnectTimeoutException("injected"))
+ .when(spy).connect(
+ Mockito.argThat(new MatchesPort()),
+ Mockito.anyInt());
+ return spy;
+ }
+
+ private class MatchesPort extends BaseMatcher<SocketAddress> {
+ @Override
+ public boolean matches(Object arg0) {
+ return ((InetSocketAddress)arg0).getPort() == portToInjectOn;
+ }
+
+ @Override
+ public void describeTo(Description desc) {
+ desc.appendText("matches port " + portToInjectOn);
+ }
+ }
+ }
+
+ /**
* Regression test for HDFS-2683.
*/
@Test