hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brando...@apache.org
Subject svn commit: r1574629 - in /hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src: main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java
Date Wed, 05 Mar 2014 19:14:38 GMT
Author: brandonli
Date: Wed Mar  5 19:14:37 2014
New Revision: 1574629

URL: http://svn.apache.org/r1574629
Log:
HDFS-6044. Merging change r1574624 from branch-2

Modified:
    hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java
    hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java

Modified: hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java?rev=1574629&r1=1574628&r2=1574629&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java
(original)
+++ hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java
Wed Mar  5 19:14:37 2014
@@ -23,6 +23,7 @@ import java.io.InputStreamReader;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.BiMap;
@@ -42,9 +43,12 @@ public class IdUserGroup {
   static final String MAC_GET_ALL_USERS_CMD = "dscl . -list /Users UniqueID";
   static final String MAC_GET_ALL_GROUPS_CMD = "dscl . -list /Groups PrimaryGroupID";
 
-  // Do update every 15 minutes
-  final static long TIMEOUT = 15 * 60 * 1000; // ms
-
+  // Do update every 15 minutes by default
+  final static long TIMEOUT_DEFAULT = 15 * 60 * 1000; // ms
+  final static long TIMEOUT_MIN = 1 * 60 * 1000; // ms
+  final private long timeout;
+  final static String NFS_USERUPDATE_MILLY = "hadoop.nfs.userupdate.milly";
+  
   // Maps for id to name map. Guarded by this object monitor lock
   private BiMap<Integer, String> uidNameMap = HashBiMap.create();
   private BiMap<Integer, String> gidNameMap = HashBiMap.create();
@@ -52,11 +56,30 @@ public class IdUserGroup {
   private long lastUpdateTime = 0; // Last time maps were updated
   
   public IdUserGroup() throws IOException {
+    timeout = TIMEOUT_DEFAULT;
+    updateMaps();
+  }
+  
+  public IdUserGroup(Configuration conf) throws IOException {
+    long updateTime = conf.getLong(NFS_USERUPDATE_MILLY, TIMEOUT_DEFAULT);
+    // Minimal interval is 1 minute
+    if (updateTime < TIMEOUT_MIN) {
+      LOG.info("User configured user account update time is less"
+          + " than 1 minute. Use 1 minute instead.");
+      timeout = TIMEOUT_MIN;
+    } else {
+      timeout = updateTime;
+    }
     updateMaps();
   }
 
-  private boolean isExpired() {
-    return lastUpdateTime - System.currentTimeMillis() > TIMEOUT;
+  @VisibleForTesting
+  public long getTimeout() {
+    return timeout;
+  }
+  
+  synchronized private boolean isExpired() {
+    return lastUpdateTime - System.currentTimeMillis() > timeout;
   }
 
   // If can't update the maps, will keep using the old ones

Modified: hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java?rev=1574629&r1=1574628&r2=1574629&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java
(original)
+++ hadoop/common/branches/branch-2.4/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java
Wed Mar  5 19:14:37 2014
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertTrue;
 import java.io.IOException;
 
+import org.apache.hadoop.conf.Configuration;
 import org.junit.Test;
 
 import com.google.common.collect.BiMap;
@@ -64,4 +65,20 @@ public class TestIdUserGroup {
     assertEquals(gMap.get(497), "mapred");
     assertEquals(gMap.get(498), "mapred3");    
   }
+  
+  @Test
+  public void testUserUpdateSetting() throws IOException {
+    IdUserGroup iug = new IdUserGroup();
+    assertEquals(iug.getTimeout(), IdUserGroup.TIMEOUT_DEFAULT);
+
+    Configuration conf = new Configuration();
+    conf.setLong(IdUserGroup.NFS_USERUPDATE_MILLY, 0);
+    iug = new IdUserGroup(conf);
+    assertEquals(iug.getTimeout(), IdUserGroup.TIMEOUT_MIN);
+
+    conf.setLong(IdUserGroup.NFS_USERUPDATE_MILLY,
+        IdUserGroup.TIMEOUT_DEFAULT * 2);
+    iug = new IdUserGroup(conf);
+    assertEquals(iug.getTimeout(), IdUserGroup.TIMEOUT_DEFAULT * 2);
+  }
 }



Mime
View raw message