Prechádzať zdrojové kódy

HADOOP-3785. Fix FileSystem cache to be case-insensitive for scheme and
authority. Contributed by Bill de hOra.


git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@688935 13f79535-47bb-0310-9956-ffa450edef68

Christopher Douglas 17 rokov pred
rodič
commit
c9e948de2f

+ 3 - 0
CHANGES.txt

@@ -362,6 +362,9 @@ Trunk (unreleased changes)
 
     HADOOP-3964. Fix javadoc warnings introduced by FailMon. (dhruba)
 
+    HADOOP-3785. Fix FileSystem cache to be case-insensitive for scheme and
+    authority. (Bill de hOra via cdouglas)
+
 Release 0.18.0 - 2008-08-19
 
   INCOMPATIBLE CHANGES

+ 4 - 4
src/core/org/apache/hadoop/fs/FileSystem.java

@@ -1323,7 +1323,7 @@ public abstract class FileSystem extends Configured implements Closeable {
   }
 
   /** Caching FileSystem objects */
-  private static class Cache {
+  static class Cache {
     private final Map<Key, FileSystem> map = new HashMap<Key, FileSystem>();
 
     synchronized FileSystem get(URI uri, Configuration conf) throws IOException{
@@ -1378,14 +1378,14 @@ public abstract class FileSystem extends Configured implements Closeable {
     }
 
     /** FileSystem.Cache.Key */
-    private static class Key {
+    static class Key {
       final String scheme;
       final String authority;
       final String username;
 
       Key(URI uri, Configuration conf) throws IOException {
-        scheme = uri.getScheme();
-        authority = uri.getAuthority();
+        scheme = uri.getScheme()==null?"":uri.getScheme().toLowerCase();
+        authority = uri.getAuthority()==null?"":uri.getAuthority().toLowerCase();
         UserGroupInformation ugi = UserGroupInformation.readFrom(conf);
         if (ugi == null) {
           try {

+ 39 - 0
src/test/org/apache/hadoop/fs/TestFileSystem.java

@@ -23,6 +23,12 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Arrays;
 import java.util.Random;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
 import java.net.InetSocketAddress;
 import java.net.URI;
 
@@ -579,4 +585,37 @@ public class TestFileSystem extends TestCase {
       FileSystem.closeAll();
     }
   }
+
+
+  public void testCacheKeysAreCaseInsensitive()
+    throws Exception
+  {
+    Configuration conf = new Configuration();
+    
+    // check basic equality
+    FileSystem.Cache.Key lowercaseCachekey1 = new FileSystem.Cache.Key(new URI("hftp://localhost:12345/"), conf);
+    FileSystem.Cache.Key lowercaseCachekey2 = new FileSystem.Cache.Key(new URI("hftp://localhost:12345/"), conf);
+    assertEquals( lowercaseCachekey1, lowercaseCachekey2 );
+
+    // check insensitive equality    
+    FileSystem.Cache.Key uppercaseCachekey = new FileSystem.Cache.Key(new URI("HFTP://Localhost:12345/"), conf);
+    assertEquals( lowercaseCachekey2, uppercaseCachekey );
+
+    // check behaviour with collections
+    List<FileSystem.Cache.Key> list = new ArrayList<FileSystem.Cache.Key>();
+    list.add(uppercaseCachekey);
+    assertTrue(list.contains(uppercaseCachekey));
+    assertTrue(list.contains(lowercaseCachekey2));
+
+    Set<FileSystem.Cache.Key> set = new HashSet<FileSystem.Cache.Key>();
+    set.add(uppercaseCachekey);
+    assertTrue(set.contains(uppercaseCachekey));
+    assertTrue(set.contains(lowercaseCachekey2));
+
+    Map<FileSystem.Cache.Key, String> map = new HashMap<FileSystem.Cache.Key, String>();
+    map.put(uppercaseCachekey, "");
+    assertTrue(map.containsKey(uppercaseCachekey));
+    assertTrue(map.containsKey(lowercaseCachekey2));    
+
+  }
 }