You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by om...@apache.org on 2011/03/04 05:15:40 UTC
svn commit: r1077444 - in
/hadoop/common/branches/branch-0.20-security-patches/src:
core/org/apache/hadoop/fs/FileSystem.java
test/org/apache/hadoop/fs/TestFileSystemCaching.java
Author: omalley
Date: Fri Mar 4 04:15:40 2011
New Revision: 1077444
URL: http://svn.apache.org/viewvc?rev=1077444&view=rev
Log:
commit 19318a94048818d0981efc6827a158e2263d8b69
Author: Hairong Kuang <ha...@ucdev21.inktomisearch.com>
Date: Wed May 5 23:38:06 2010 +0000
HADOOP:6640 from https://issues.apache.org/jira/secure/attachment/12443759/getFS_yahoo20s.patch
+++ b/YAHOO-CHANGES.txt
+ HADOOP-6640. FileSystem.get() does RPC retires within a static
+ synchronized block. (hairong)
+
Added:
hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestFileSystemCaching.java
Modified:
hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java
Modified: hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java?rev=1077444&r1=1077443&r2=1077444&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java Fri Mar 4 04:15:40 2011
@@ -1399,18 +1399,32 @@ public abstract class FileSystem extends
static class Cache {
private final Map<Key, FileSystem> map = new HashMap<Key, FileSystem>();
- synchronized FileSystem get(URI uri, Configuration conf) throws IOException{
+ FileSystem get(URI uri, Configuration conf) throws IOException{
Key key = new Key(uri, conf);
- FileSystem fs = map.get(key);
- if (fs == null) {
- fs = createFileSystem(uri, conf);
+ FileSystem fs = null;
+ 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);
+ return fs;
}
- return fs;
}
synchronized void remove(Key key, FileSystem fs) {
Added: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestFileSystemCaching.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestFileSystemCaching.java?rev=1077444&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestFileSystemCaching.java (added)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestFileSystemCaching.java Fri Mar 4 04:15:40 2011
@@ -0,0 +1,71 @@
+/**
+ * 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.fs;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.hadoop.conf.Configuration;
+import java.util.concurrent.Semaphore;
+
+import junit.framework.TestCase;
+
+public class TestFileSystemCaching extends TestCase {
+
+ public static class InitializeForeverFileSystem extends LocalFileSystem {
+ final static Semaphore sem = new Semaphore(0);
+ public void initialize(URI uri, Configuration conf) throws IOException {
+ // notify that InitializeForeverFileSystem started initialization
+ sem.release();
+ try {
+ while (true) {
+ Thread.sleep(1000);
+ }
+ } catch (InterruptedException e) {
+ return;
+ }
+ }
+ }
+
+ 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
+ InitializeForeverFileSystem.sem.acquire();
+
+ conf.set("fs.cachedfile.impl", conf.get("fs.file.impl"));
+ FileSystem.get(new URI("cachedfile://a"), conf);
+ t.interrupt();
+ t.join();
+ }
+}