HDFS-6044. Add property for setting the NFS look up time for users. Contributed by Brandon Li
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1574622 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8e84dedd4c
commit
206e2b0cd2
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.collect.BiMap;
|
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_USERS_CMD = "dscl . -list /Users UniqueID";
|
||||||
static final String MAC_GET_ALL_GROUPS_CMD = "dscl . -list /Groups PrimaryGroupID";
|
static final String MAC_GET_ALL_GROUPS_CMD = "dscl . -list /Groups PrimaryGroupID";
|
||||||
|
|
||||||
// Do update every 15 minutes
|
// Do update every 15 minutes by default
|
||||||
final static long TIMEOUT = 15 * 60 * 1000; // ms
|
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
|
// Maps for id to name map. Guarded by this object monitor lock
|
||||||
private BiMap<Integer, String> uidNameMap = HashBiMap.create();
|
private BiMap<Integer, String> uidNameMap = HashBiMap.create();
|
||||||
private BiMap<Integer, String> gidNameMap = 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
|
private long lastUpdateTime = 0; // Last time maps were updated
|
||||||
|
|
||||||
public IdUserGroup() throws IOException {
|
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();
|
updateMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isExpired() {
|
@VisibleForTesting
|
||||||
return lastUpdateTime - System.currentTimeMillis() > TIMEOUT;
|
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
|
// If can't update the maps, will keep using the old ones
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
@ -64,4 +65,20 @@ public void testDuplicates() throws IOException {
|
|||||||
assertEquals(gMap.get(497), "mapred");
|
assertEquals(gMap.get(497), "mapred");
|
||||||
assertEquals(gMap.get(498), "mapred3");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,6 +524,9 @@ Release 2.4.0 - UNRELEASED
|
|||||||
|
|
||||||
HDFS-6043. Give HDFS daemons NFS3 and Portmap their own OPTS (brandonli)
|
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
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HDFS-5790. LeaseManager.findPath is very slow when many leases need recovery
|
HDFS-5790. LeaseManager.findPath is very slow when many leases need recovery
|
||||||
|
Loading…
Reference in New Issue
Block a user