diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java index bf2b542d85..b81890189b 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/IdUserGroup.java @@ -23,6 +23,7 @@ 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 uidNameMap = HashBiMap.create(); private BiMap 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 diff --git a/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java b/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java index 4331238b16..3adb308c33 100644 --- a/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java +++ b/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/nfs3/TestIdUserGroup.java @@ -21,6 +21,7 @@ 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 void testDuplicates() throws IOException { 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); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index bc2df46372..13fc4d335f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -524,6 +524,9 @@ Release 2.4.0 - UNRELEASED HDFS-6043. Give HDFS daemons NFS3 and Portmap their own OPTS (brandonli) + HDFS-6044. Add property for setting the NFS look up time for users + (brandonli) + OPTIMIZATIONS HDFS-5790. LeaseManager.findPath is very slow when many leases need recovery