HDFS-6044. Merging change r1574622 from trunk

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1574624 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brandon Li 2014-03-05 19:05:44 +00:00
parent b7c98f4912
commit 5e096ccac7
3 changed files with 48 additions and 5 deletions

View File

@ -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<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

View File

@ -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);
}
}

View File

@ -135,6 +135,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