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 ha...@apache.org on 2008/04/04 21:14:17 UTC
svn commit: r644829 - in /hadoop/core/trunk: CHANGES.txt
src/java/org/apache/hadoop/fs/FileSystem.java
src/java/org/apache/hadoop/security/UserGroupInformation.java
src/test/org/apache/hadoop/fs/TestFileSystem.java
Author: hairong
Date: Fri Apr 4 12:14:16 2008
New Revision: 644829
URL: http://svn.apache.org/viewvc?rev=644829&view=rev
Log:
HADOOP-3159. Avoid file system cache being overwritten whenever configuration is modifiedi. Contributed by Tsz Wo (Nicholas), SZE
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java
hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestFileSystem.java
Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=644829&r1=644828&r2=644829&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Fri Apr 4 12:14:16 2008
@@ -693,6 +693,9 @@
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
Modified: hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java?rev=644829&r1=644828&r2=644829&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java Fri Apr 4 12:14:16 2008
@@ -23,6 +23,8 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
+import javax.security.auth.login.LoginException;
+
import org.apache.commons.logging.*;
import org.apache.hadoop.dfs.*;
@@ -1351,6 +1353,13 @@
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();
}
Modified: hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java?rev=644829&r1=644828&r2=644829&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java Fri Apr 4 12:14:16 2008
@@ -30,6 +30,7 @@
*/
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>();
@@ -58,6 +59,15 @@
* @return an array of group names
*/
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
Modified: hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestFileSystem.java?rev=644829&r1=644828&r2=644829&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestFileSystem.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestFileSystem.java Fri Apr 4 12:14:16 2008
@@ -23,12 +23,14 @@
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;
@@ -468,18 +470,36 @@
}
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();
}
}