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 D247010EF4 for ; Thu, 17 Oct 2013 20:33:07 +0000 (UTC) Received: (qmail 45027 invoked by uid 500); 17 Oct 2013 20:30:07 -0000 Delivered-To: apmail-hadoop-hdfs-commits-archive@hadoop.apache.org Received: (qmail 44263 invoked by uid 500); 17 Oct 2013 20:29: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 44166 invoked by uid 99); 17 Oct 2013 20:29:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Oct 2013 20:29:13 +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; Thu, 17 Oct 2013 20:29:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 45DB423889ED; Thu, 17 Oct 2013 20:28:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1533252 - in /hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs: CHANGES.txt src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java Date: Thu, 17 Oct 2013 20:28:52 -0000 To: hdfs-commits@hadoop.apache.org From: kihwal@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131017202852.45DB423889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kihwal Date: Thu Oct 17 20:28:51 2013 New Revision: 1533252 URL: http://svn.apache.org/r1533252 Log: HDFS-5239. Allow FSNamesystem lock fairness to be configurable. Contributed by Daryn Sharp. Modified: hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java Modified: hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1533252&r1=1533251&r2=1533252&view=diff ============================================================================== --- hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original) +++ hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Thu Oct 17 20:28:51 2013 @@ -24,6 +24,9 @@ Release 0.23.10 - UNRELEASED OPTIMIZATIONS + HDFS-5239. Allow FSNamesystem lock fairness to be configurable (daryn via + kihwal) + BUG FIXES HDFS-4984. Incorrect Quota counting in INodeFile. (jing9 via kihwal) Modified: hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1533252&r1=1533251&r2=1533252&view=diff ============================================================================== --- hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java (original) +++ hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java Thu Oct 17 20:28:51 2013 @@ -350,7 +350,7 @@ public class FSNamesystem implements Nam this.systemStart = now(); this.blockManager = new BlockManager(this, this, conf); this.datanodeStatistics = blockManager.getDatanodeManager().getDatanodeStatistics(); - this.fsLock = new ReentrantReadWriteLock(true); // fair locking + this.fsLock = createFsLock(conf); setConfigurationParameters(conf); // For testing purposes, allow the DT secret manager to be started regardless // of whether security is enabled. @@ -373,6 +373,12 @@ public class FSNamesystem implements Nam this.safeMode = new SafeModeInfo(conf); } + private static ReentrantReadWriteLock createFsLock(Configuration conf) { + boolean fair = conf.getBoolean("dfs.namenode.fslock.fair", true); + LOG.info("fsLock is fair:" + fair); + return new ReentrantReadWriteLock(fair); + } + void activateSecretManager() throws IOException { if (dtSecretManager != null) { dtSecretManager.startThreads(); @@ -472,7 +478,7 @@ public class FSNamesystem implements Nam * is stored */ FSNamesystem(FSImage fsImage, Configuration conf) throws IOException { - this.fsLock = new ReentrantReadWriteLock(true); + this.fsLock = createFsLock(conf); this.blockManager = new BlockManager(this, this, conf); setConfigurationParameters(conf); this.dir = new FSDirectory(fsImage, this, conf); @@ -4548,4 +4554,14 @@ public class FSNamesystem implements Nam public SafeModeInfo getSafeModeInfoForTests() { return safeMode; } + + @VisibleForTesting + void setFsLockForTests(ReentrantReadWriteLock lock) { + this.fsLock = lock; + } + + @VisibleForTesting + ReentrantReadWriteLock getFsLockForTests() { + return fsLock; + } } Modified: hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java?rev=1533252&r1=1533251&r2=1533252&view=diff ============================================================================== --- hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java (original) +++ hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java Thu Oct 17 20:28:51 2013 @@ -18,7 +18,7 @@ package org.apache.hadoop.hdfs.server.namenode; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.io.IOException; @@ -72,4 +72,21 @@ public class TestFSNamesystem { assertTrue("Replication queues weren't being populated after entering " + "safemode 2nd time", fsn.isPopulatingReplQueues()); } + + @Test + public void testFsLockFairness() throws IOException, InterruptedException{ + Configuration conf = new Configuration(); + + FSEditLog fsEditLog = Mockito.mock(FSEditLog.class); + FSImage fsImage = Mockito.mock(FSImage.class); + Mockito.when(fsImage.getEditLog()).thenReturn(fsEditLog); + + conf.setBoolean("dfs.namenode.fslock.fair", true); + FSNamesystem fsNamesystem = new FSNamesystem(fsImage, conf); + assertTrue(fsNamesystem.getFsLockForTests().isFair()); + + conf.setBoolean("dfs.namenode.fslock.fair", false); + fsNamesystem = new FSNamesystem(fsImage, conf); + assertFalse(fsNamesystem.getFsLockForTests().isFair()); + } }