Return-Path: Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: (qmail 97259 invoked from network); 1 Apr 2010 20:58:33 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Apr 2010 20:58:33 -0000 Received: (qmail 24409 invoked by uid 500); 1 Apr 2010 20:58:33 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 24245 invoked by uid 500); 1 Apr 2010 20:58:32 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 24238 invoked by uid 99); 1 Apr 2010 20:58:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Apr 2010 20:58:32 +0000 X-ASF-Spam-Status: No, hits=-1295.0 required=10.0 tests=ALL_TRUSTED,AWL 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, 01 Apr 2010 20:58:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3B03E23888EC; Thu, 1 Apr 2010 20:58:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r930096 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FileSystem.java src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java Date: Thu, 01 Apr 2010 20:58:11 -0000 To: common-commits@hadoop.apache.org From: hairong@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100401205811.3B03E23888EC@eris.apache.org> Author: hairong Date: Thu Apr 1 20:58:10 2010 New Revision: 930096 URL: http://svn.apache.org/viewvc?rev=930096&view=rev Log: HADOOP-6640. FileSystem.get() does RPC retries within a static synchronized block. Contributed by Hairong Kuang. Modified: hadoop/common/trunk/CHANGES.txt hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java Modified: hadoop/common/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=930096&r1=930095&r2=930096&view=diff ============================================================================== --- hadoop/common/trunk/CHANGES.txt (original) +++ hadoop/common/trunk/CHANGES.txt Thu Apr 1 20:58:10 2010 @@ -306,6 +306,9 @@ Trunk (unreleased changes) HADOOP-6654. Fix code example in WritableComparable javadoc. (Tom White via szetszwo) + HADOOP-6640. FileSystem.get() does RPC retries within a static + synchronized block. (hairong) + Release 0.21.0 - Unreleased INCOMPATIBLE CHANGES Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java?rev=930096&r1=930095&r2=930096&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java Thu Apr 1 20:58:10 2010 @@ -1758,32 +1758,45 @@ public abstract class FileSystem extends /** A variable that makes all objects in the cache unique */ private static AtomicLong unique = new AtomicLong(1); - synchronized FileSystem get(URI uri, Configuration conf) throws IOException{ + FileSystem get(URI uri, Configuration conf) throws IOException{ Key key = new Key(uri, conf); return getInternal(uri, conf, key); } /** The objects inserted into the cache using this method are all unique */ - synchronized FileSystem getUnique(URI uri, Configuration conf) throws IOException{ + FileSystem getUnique(URI uri, Configuration conf) throws IOException{ Key key = new Key(uri, conf, unique.getAndIncrement()); return getInternal(uri, conf, key); } private FileSystem getInternal(URI uri, Configuration conf, Key key) throws IOException{ - FileSystem fs = map.get(key); - if (fs == null) { - fs = createFileSystem(uri, conf); + FileSystem fs; + synchronized (this) { + fs = map.get(key); + } + if (fs != null) { + return fs; + } + + fs = createFileSystem(uri, conf); + synchronized (this) { // refetch the lock again + FileSystem oldfs = map.get(key); + if (oldfs != null) { // a file system is created while lock is releasing + fs.close(); // close the new file system + return oldfs; // return the old file system + } + + // now insert the new file system into the map if (map.isEmpty() && !clientFinalizer.isAlive()) { Runtime.getRuntime().addShutdownHook(clientFinalizer); } fs.key = key; map.put(key, fs); - if (conf.getBoolean("fs.automatic.close", true)) { toAutoClose.add(key); } + return fs; } - return fs; } synchronized void remove(Key key, FileSystem fs) { Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java?rev=930096&r1=930095&r2=930096&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java Thu Apr 1 20:58:10 2010 @@ -21,7 +21,9 @@ package org.apache.hadoop.fs; import static junit.framework.Assert.assertSame; import static junit.framework.Assert.assertNotSame; +import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.UserGroupInformation; @@ -46,6 +48,49 @@ public class TestFileSystemCaching { assertSame(fs1, fs2); } + public static class InitializeForeverFileSystem extends LocalFileSystem { + public void initialize(URI uri, Configuration conf) throws IOException { + // notify that InitializeForeverFileSystem started initialization + synchronized (conf) { + conf.notify(); + } + try { + while (true) { + Thread.sleep(1000); + } + } catch (InterruptedException e) { + return; + } + } + } + + @Test + public void testCacheEnabledWithInitializeForeverFS() throws Exception { + final Configuration conf = new Configuration(); + Thread t = new Thread() { + public void run() { + conf.set("fs.localfs1.impl", "org.apache.hadoop.fs." + + "TestFileSystemCaching$InitializeForeverFileSystem"); + try { + FileSystem.get(new URI("localfs1://a"), conf); + } catch (IOException e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } + }; + t.start(); + // wait for InitializeForeverFileSystem to start initialization + synchronized (conf) { + conf.wait(); + } + conf.set("fs.cachedfile.impl", conf.get("fs.file.impl")); + FileSystem.get(new URI("cachedfile://a"), conf); + t.interrupt(); + t.join(); + } + @Test public void testCacheDisabled() throws Exception { Configuration conf = new Configuration();