فهرست منبع

Merge -r 644828:644829 from trunk to main to fix HADOOP-3159

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.16@644838 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang 17 سال پیش
والد
کامیت
c844973a06

+ 3 - 0
CHANGES.txt

@@ -211,6 +211,9 @@ Release 0.16.1 - 2008-03-13
     HADOOP-2813. TestDU unit test uses its own directory to run its
     sequence of tests.  (Mahadev Konar via dhruba)
 
+    HADOOP-3159. Avoid file system cache being overwritten whenever
+    configuration is modified. (Tsz Wo (Nicholas), SZE via hairong)
+
 Release 0.16.0 - 2008-02-07
 
   INCOMPATIBLE CHANGES

+ 9 - 0
src/java/org/apache/hadoop/fs/FileSystem.java

@@ -22,6 +22,8 @@ import java.net.*;
 import java.util.*;
 import java.util.regex.Pattern;
 
+import javax.security.auth.login.LoginException;
+
 import org.apache.commons.logging.*;
 
 import org.apache.hadoop.dfs.*;
@@ -1255,6 +1257,13 @@ public abstract class FileSystem extends Configured implements Closeable {
         scheme = uri.getScheme();
         authority = uri.getAuthority();
         UserGroupInformation ugi = UserGroupInformation.readFrom(conf);
+        if (ugi == null) {
+          try {
+            ugi = UserGroupInformation.login(conf);
+          } catch(LoginException e) {
+            LOG.warn("uri=" + uri, e);
+          }
+        }
         username = ugi == null? null: ugi.getUserName();
       }
 

+ 10 - 0
src/java/org/apache/hadoop/security/UserGroupInformation.java

@@ -30,6 +30,7 @@ import org.apache.hadoop.io.Writable;
  */
 public abstract class UserGroupInformation implements Writable {
   public static final Log LOG = LogFactory.getLog(UserGroupInformation.class);
+  private static UserGroupInformation LOGIN_UGI = null;
 
   private static final ThreadLocal<UserGroupInformation> currentUGI
     = new ThreadLocal<UserGroupInformation>();
@@ -59,6 +60,15 @@ public abstract class UserGroupInformation implements Writable {
    */
   public abstract String[] getGroupNames();
 
+  /** Login and return a UserGroupInformation object. */
+  public static UserGroupInformation login(Configuration conf
+      ) throws LoginException {
+    if (LOGIN_UGI == null) {
+      LOGIN_UGI = UnixUserGroupInformation.login(conf);
+    }
+    return LOGIN_UGI;
+  }
+
   /** Read a {@link UserGroupInformation} from conf */
   public static UserGroupInformation readFrom(Configuration conf
       ) throws IOException {

+ 31 - 11
src/test/org/apache/hadoop/fs/TestFileSystem.java

@@ -23,12 +23,14 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Arrays;
 import java.util.Random;
+import java.net.URI;
 
 import junit.framework.TestCase;
 
 import org.apache.commons.logging.Log;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.dfs.MiniDFSCluster;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.SequenceFile;
 import org.apache.hadoop.io.UTF8;
@@ -472,18 +474,36 @@ public class TestFileSystem extends TestCase {
   }
 
   public void testFsCache() throws Exception {
-    long now = System.currentTimeMillis();
-    Configuration[] conf = {new Configuration(),
-        createConf4Testing("foo" + now), createConf4Testing("bar" + now)};
-    FileSystem[] fs = new FileSystem[conf.length];
-
-    for(int i = 0; i < conf.length; i++) {
-      fs[i] = FileSystem.get(conf[i]);
-      assertEquals(fs[i], FileSystem.get(conf[i]));
-      for(int j = 0; j < i; j++) {
-        assertFalse(fs[j] == fs[i]);
+    {
+      long now = System.currentTimeMillis();
+      Configuration[] conf = {new Configuration(),
+          createConf4Testing("foo" + now), createConf4Testing("bar" + now)};
+      FileSystem[] fs = new FileSystem[conf.length];
+  
+      for(int i = 0; i < conf.length; i++) {
+        fs[i] = FileSystem.get(conf[i]);
+        assertEquals(fs[i], FileSystem.get(conf[i]));
+        for(int j = 0; j < i; j++) {
+          assertFalse(fs[j] == fs[i]);
+        }
+      }
+      FileSystem.closeAll();
+    }
+    
+    {
+      MiniDFSCluster cluster = null;
+      try {
+        cluster = new MiniDFSCluster(new Configuration(), 2, true, null);
+        URI uri = cluster.getFileSystem().getUri();
+        FileSystem.get(uri, new Configuration());
+        int n = Thread.activeCount();
+        for(int i = 0; i < 100; i++) {
+          FileSystem.get(uri, new Configuration());
+          assertTrue(n >= Thread.activeCount());
+        }
+      } finally {
+        cluster.shutdown(); 
       }
     }
-    FileSystem.closeAll();
   }
 }