|
@@ -50,6 +50,7 @@ public class Groups {
|
|
|
private final Map<String, CachedGroups> userToGroupsMap =
|
|
|
new ConcurrentHashMap<String, CachedGroups>();
|
|
|
private final long cacheTimeout;
|
|
|
+ private final long warningDeltaMs;
|
|
|
|
|
|
public Groups(Configuration conf) {
|
|
|
impl =
|
|
@@ -60,11 +61,16 @@ public class Groups {
|
|
|
conf);
|
|
|
|
|
|
cacheTimeout =
|
|
|
- conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_SECS, 5*60) * 1000;
|
|
|
+ conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_SECS,
|
|
|
+ CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_SECS_DEFAULT) * 1000;
|
|
|
+ warningDeltaMs =
|
|
|
+ conf.getLong(CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS,
|
|
|
+ CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_WARN_AFTER_MS_DEFAULT);
|
|
|
|
|
|
if(LOG.isDebugEnabled())
|
|
|
LOG.debug("Group mapping impl=" + impl.getClass().getName() +
|
|
|
- "; cacheTimeout=" + cacheTimeout);
|
|
|
+ "; cacheTimeout=" + cacheTimeout + "; warningDeltaMs=" +
|
|
|
+ warningDeltaMs);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -76,17 +82,24 @@ public class Groups {
|
|
|
public List<String> getGroups(String user) throws IOException {
|
|
|
// Return cached value if available
|
|
|
CachedGroups groups = userToGroupsMap.get(user);
|
|
|
- long now = Time.now();
|
|
|
+ long startMs = Time.monotonicNow();
|
|
|
// if cache has a value and it hasn't expired
|
|
|
- if (groups != null && (groups.getTimestamp() + cacheTimeout > now)) {
|
|
|
+ if (groups != null && (groups.getTimestamp() + cacheTimeout > startMs)) {
|
|
|
if(LOG.isDebugEnabled()) {
|
|
|
LOG.debug("Returning cached groups for '" + user + "'");
|
|
|
}
|
|
|
return groups.getGroups();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Create and cache user's groups
|
|
|
- groups = new CachedGroups(impl.getGroups(user));
|
|
|
+ List<String> groupList = impl.getGroups(user);
|
|
|
+ long endMs = Time.monotonicNow();
|
|
|
+ long deltaMs = endMs - startMs ;
|
|
|
+ if (deltaMs > warningDeltaMs) {
|
|
|
+ LOG.warn("Potential performance problem: getGroups(user=" + user +") " +
|
|
|
+ "took " + deltaMs + " milliseconds.");
|
|
|
+ }
|
|
|
+ groups = new CachedGroups(groupList, endMs);
|
|
|
if (groups.getGroups().isEmpty()) {
|
|
|
throw new IOException("No groups found for user " + user);
|
|
|
}
|
|
@@ -133,9 +146,9 @@ public class Groups {
|
|
|
/**
|
|
|
* Create and initialize group cache
|
|
|
*/
|
|
|
- CachedGroups(List<String> groups) {
|
|
|
+ CachedGroups(List<String> groups, long timestamp) {
|
|
|
this.groups = groups;
|
|
|
- this.timestamp = Time.now();
|
|
|
+ this.timestamp = timestamp;
|
|
|
}
|
|
|
|
|
|
/**
|