Return-Path: X-Original-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 24C9D693A for ; Fri, 20 May 2011 03:26:27 +0000 (UTC) Received: (qmail 37250 invoked by uid 500); 20 May 2011 03:26:26 -0000 Delivered-To: apmail-hadoop-hdfs-commits-archive@hadoop.apache.org Received: (qmail 37223 invoked by uid 500); 20 May 2011 03:26:26 -0000 Mailing-List: contact hdfs-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hdfs-dev@hadoop.apache.org Delivered-To: mailing list hdfs-commits@hadoop.apache.org Received: (qmail 37215 invoked by uid 99); 20 May 2011 03:26:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 May 2011 03:26:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 May 2011 03:26:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6BC5923888DD; Fri, 20 May 2011 03:26:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1125217 - in /hadoop/hdfs/trunk: CHANGES.txt src/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLog.java Date: Fri, 20 May 2011 03:26:01 -0000 To: hdfs-commits@hadoop.apache.org From: todd@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110520032601.6BC5923888DD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: todd Date: Fri May 20 03:26:00 2011 New Revision: 1125217 URL: http://svn.apache.org/viewvc?rev=1125217&view=rev Log: HDFS-1952. FSEditLog.open() appears to succeed even if all EDITS directories fail. Contributed by Andrew Wang. Modified: hadoop/hdfs/trunk/CHANGES.txt hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLog.java Modified: hadoop/hdfs/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=1125217&r1=1125216&r2=1125217&view=diff ============================================================================== --- hadoop/hdfs/trunk/CHANGES.txt (original) +++ hadoop/hdfs/trunk/CHANGES.txt Fri May 20 03:26:00 2011 @@ -1042,6 +1042,9 @@ Release 0.22.0 - Unreleased HDFS-1575. Viewing block from web UI is broken. (Aaron T. Myers via todd) + HDFS-1952. FSEditLog.open() appears to succeed even if all EDITS + directories fail. (Andrew Wang via todd) + Release 0.21.1 - Unreleased HDFS-1466. TestFcHdfsSymlink relies on /tmp/test not existing. (eli) Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java?rev=1125217&r1=1125216&r2=1125217&view=diff ============================================================================== --- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java (original) +++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/FSEditLog.java Fri May 20 03:26:00 2011 @@ -178,11 +178,18 @@ public class FSEditLog implements NNStor // Remove the directory from list of storage directories if(al == null) al = new ArrayList(1); al.add(sd); - } } - if(al != null) storage.reportErrorsOnDirectories(al); + if (al != null) + storage.reportErrorsOnDirectories(al); + + // If there was an error in every storage dir, each one will have + // been removed from the list of storage directories. + if (storage.getNumStorageDirs(NameNodeDirType.EDITS) == 0) { + throw new IOException( + "Failed to initialize edits log in any storage directory."); + } } Modified: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLog.java URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLog.java?rev=1125217&r1=1125216&r2=1125217&view=diff ============================================================================== --- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLog.java (original) +++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLog.java Fri May 20 03:26:00 2011 @@ -24,25 +24,40 @@ import java.util.Iterator; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.ChecksumException; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.*; +import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; +import org.apache.hadoop.hdfs.protocol.FSConstants.SafeModeAction; import org.apache.hadoop.hdfs.server.namenode.EditLogFileInputStream; +import org.apache.hadoop.hdfs.server.common.HdfsConstants.NamenodeRole; import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory; import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeDirType; import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile; import org.apache.hadoop.hdfs.server.namenode.metrics.NameNodeMetrics; +import org.mockito.Mockito; + import static org.apache.hadoop.test.MetricsAsserts.*; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.spy; /** * This class tests the creation and validation of a checkpoint. */ public class TestEditLog extends TestCase { + private static final Log LOG = LogFactory.getLog(TestEditLog.class); + static final int NUM_DATA_NODES = 0; // This test creates NUM_THREADS threads and each thread does @@ -335,4 +350,54 @@ public class TestEditLog extends TestCas e.getCause().getClass(), ChecksumException.class); } } + + public void testFailedOpen() throws Exception { + Configuration conf = new HdfsConfiguration(); + MiniDFSCluster cluster = null; + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(NUM_DATA_NODES).build(); + cluster.waitActive(); + final FSNamesystem fsn = cluster.getNamesystem(); + + // Set up spys + final FSImage originalImage = fsn.getFSImage(); + NNStorage storage = originalImage.getStorage(); + NNStorage spyStorage = spy(storage); + originalImage.storage = spyStorage; + + final FSEditLog editLog = originalImage.getEditLog(); + FSEditLog spyLog = spy(editLog); + + FSImage spyImage = spy(originalImage); + fsn.dir.fsImage = spyImage; + spyImage.storage.setStorageDirectories( + FSNamesystem.getNamespaceDirs(conf), + FSNamesystem.getNamespaceEditsDirs(conf)); + + // Fail every attempt to open a new edit file + doThrow(new IOException("Injected fault: open")). + when(spyLog).addNewEditLogStream((File)anyObject()); + + try { + spyLog.close(); + spyLog.open(); + fail("open did not fail even when all directories failed!"); + } catch(IOException ioe) { + LOG.info("Got expected exception", ioe); + } finally { + spyLog.close(); + } + + // Reset and try it with a working open + Mockito.reset(spyLog); + spyImage.storage.setStorageDirectories( + FSNamesystem.getNamespaceDirs(conf), + FSNamesystem.getNamespaceEditsDirs(conf)); + spyLog.open(); + + // Close everything off + spyLog.close(); + originalImage.close(); + fsn.close(); + } + }