Merge "Improve method and variable names related to group inclusion caches"
This commit is contained in:
@@ -21,14 +21,14 @@ import java.util.Set;
|
||||
/** Tracks group inclusions in memory for efficient access. */
|
||||
public interface GroupIncludeCache {
|
||||
/** @return groups directly a member of the passed group. */
|
||||
public Set<AccountGroup.UUID> membersOf(AccountGroup.UUID group);
|
||||
public Set<AccountGroup.UUID> subgroupsOf(AccountGroup.UUID group);
|
||||
|
||||
/** @return any groups the passed group belongs to. */
|
||||
public Set<AccountGroup.UUID> memberIn(AccountGroup.UUID groupId);
|
||||
public Set<AccountGroup.UUID> parentGroupsOf(AccountGroup.UUID groupId);
|
||||
|
||||
/** @return set of any UUIDs that are not internal groups. */
|
||||
public Set<AccountGroup.UUID> allExternalMembers();
|
||||
|
||||
public void evictMembersOf(AccountGroup.UUID groupId);
|
||||
public void evictMemberIn(AccountGroup.UUID groupId);
|
||||
public void evictSubgroupsOf(AccountGroup.UUID groupId);
|
||||
public void evictParentGroupsOf(AccountGroup.UUID groupId);
|
||||
}
|
||||
|
@@ -42,23 +42,23 @@ import java.util.concurrent.ExecutionException;
|
||||
public class GroupIncludeCacheImpl implements GroupIncludeCache {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(GroupIncludeCacheImpl.class);
|
||||
private static final String BYINCLUDE_NAME = "groups_byinclude";
|
||||
private static final String MEMBERS_NAME = "groups_members";
|
||||
private static final String PARENT_GROUPS_NAME = "groups_byinclude";
|
||||
private static final String SUBGROUPS_NAME = "groups_members";
|
||||
private static final String EXTERNAL_NAME = "groups_external";
|
||||
|
||||
public static Module module() {
|
||||
return new CacheModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
cache(BYINCLUDE_NAME,
|
||||
cache(PARENT_GROUPS_NAME,
|
||||
AccountGroup.UUID.class,
|
||||
new TypeLiteral<Set<AccountGroup.UUID>>() {})
|
||||
.loader(MemberInLoader.class);
|
||||
.loader(parentGroupsLoader.class);
|
||||
|
||||
cache(MEMBERS_NAME,
|
||||
cache(SUBGROUPS_NAME,
|
||||
AccountGroup.UUID.class,
|
||||
new TypeLiteral<Set<AccountGroup.UUID>>() {})
|
||||
.loader(MembersOfLoader.class);
|
||||
.loader(subgroupsLoader.class);
|
||||
|
||||
cache(EXTERNAL_NAME,
|
||||
String.class,
|
||||
@@ -71,24 +71,24 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
|
||||
};
|
||||
}
|
||||
|
||||
private final LoadingCache<AccountGroup.UUID, Set<AccountGroup.UUID>> membersOf;
|
||||
private final LoadingCache<AccountGroup.UUID, Set<AccountGroup.UUID>> memberIn;
|
||||
private final LoadingCache<AccountGroup.UUID, Set<AccountGroup.UUID>> subgroups;
|
||||
private final LoadingCache<AccountGroup.UUID, Set<AccountGroup.UUID>> parentGroups;
|
||||
private final LoadingCache<String, Set<AccountGroup.UUID>> external;
|
||||
|
||||
@Inject
|
||||
GroupIncludeCacheImpl(
|
||||
@Named(MEMBERS_NAME) LoadingCache<AccountGroup.UUID, Set<AccountGroup.UUID>> membersOf,
|
||||
@Named(BYINCLUDE_NAME) LoadingCache<AccountGroup.UUID, Set<AccountGroup.UUID>> memberIn,
|
||||
@Named(SUBGROUPS_NAME) LoadingCache<AccountGroup.UUID, Set<AccountGroup.UUID>> subgroups,
|
||||
@Named(PARENT_GROUPS_NAME) LoadingCache<AccountGroup.UUID, Set<AccountGroup.UUID>> parentGroups,
|
||||
@Named(EXTERNAL_NAME) LoadingCache<String, Set<AccountGroup.UUID>> external) {
|
||||
this.membersOf = membersOf;
|
||||
this.memberIn = memberIn;
|
||||
this.subgroups = subgroups;
|
||||
this.parentGroups = parentGroups;
|
||||
this.external = external;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<AccountGroup.UUID> membersOf(AccountGroup.UUID groupId) {
|
||||
public Set<AccountGroup.UUID> subgroupsOf(AccountGroup.UUID groupId) {
|
||||
try {
|
||||
return membersOf.get(groupId);
|
||||
return subgroups.get(groupId);
|
||||
} catch (ExecutionException e) {
|
||||
log.warn("Cannot load members of group", e);
|
||||
return Collections.emptySet();
|
||||
@@ -96,9 +96,9 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<AccountGroup.UUID> memberIn(AccountGroup.UUID groupId) {
|
||||
public Set<AccountGroup.UUID> parentGroupsOf(AccountGroup.UUID groupId) {
|
||||
try {
|
||||
return memberIn.get(groupId);
|
||||
return parentGroups.get(groupId);
|
||||
} catch (ExecutionException e) {
|
||||
log.warn("Cannot load included groups", e);
|
||||
return Collections.emptySet();
|
||||
@@ -106,16 +106,16 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evictMembersOf(AccountGroup.UUID groupId) {
|
||||
public void evictSubgroupsOf(AccountGroup.UUID groupId) {
|
||||
if (groupId != null) {
|
||||
membersOf.invalidate(groupId);
|
||||
subgroups.invalidate(groupId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evictMemberIn(AccountGroup.UUID groupId) {
|
||||
public void evictParentGroupsOf(AccountGroup.UUID groupId) {
|
||||
if (groupId != null) {
|
||||
memberIn.invalidate(groupId);
|
||||
parentGroups.invalidate(groupId);
|
||||
|
||||
if (!AccountGroup.isInternalGroup(groupId)) {
|
||||
external.invalidate(EXTERNAL_NAME);
|
||||
@@ -133,12 +133,12 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
|
||||
}
|
||||
}
|
||||
|
||||
static class MembersOfLoader extends
|
||||
static class subgroupsLoader extends
|
||||
CacheLoader<AccountGroup.UUID, Set<AccountGroup.UUID>> {
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
|
||||
@Inject
|
||||
MembersOfLoader(final SchemaFactory<ReviewDb> sf) {
|
||||
subgroupsLoader(final SchemaFactory<ReviewDb> sf) {
|
||||
schema = sf;
|
||||
}
|
||||
|
||||
@@ -163,12 +163,12 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
|
||||
}
|
||||
}
|
||||
|
||||
static class MemberInLoader extends
|
||||
static class parentGroupsLoader extends
|
||||
CacheLoader<AccountGroup.UUID, Set<AccountGroup.UUID>> {
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
|
||||
@Inject
|
||||
MemberInLoader(final SchemaFactory<ReviewDb> sf) {
|
||||
parentGroupsLoader(final SchemaFactory<ReviewDb> sf) {
|
||||
schema = sf;
|
||||
}
|
||||
|
||||
|
@@ -90,7 +90,7 @@ public class IncludingGroupMembership implements GroupMembership {
|
||||
}
|
||||
|
||||
memberOf.put(id, false);
|
||||
if (search(includeCache.membersOf(id))) {
|
||||
if (search(includeCache.subgroupsOf(id))) {
|
||||
memberOf.put(id, true);
|
||||
return true;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public class IncludingGroupMembership implements GroupMembership {
|
||||
|
||||
while (!q.isEmpty()) {
|
||||
AccountGroup.UUID id = q.remove(q.size() - 1);
|
||||
for (AccountGroup.UUID g : includeCache.memberIn(id)) {
|
||||
for (AccountGroup.UUID g : includeCache.parentGroupsOf(id)) {
|
||||
if (g != null && r.add(g)) {
|
||||
q.add(g);
|
||||
memberOf.put(g, true);
|
||||
|
@@ -116,7 +116,7 @@ public class PerformCreateGroup {
|
||||
|
||||
if (createGroupArgs.initialGroups != null) {
|
||||
addGroups(groupId, createGroupArgs.initialGroups);
|
||||
groupIncludeCache.evictMembersOf(uuid);
|
||||
groupIncludeCache.evictSubgroupsOf(uuid);
|
||||
}
|
||||
|
||||
groupCache.onCreateGroup(createGroupArgs.getGroup());
|
||||
@@ -152,7 +152,7 @@ public class PerformCreateGroup {
|
||||
auditService.dispatchAddGroupsToGroup(currentUser.getAccountId(), includeList);
|
||||
|
||||
for (AccountGroup.UUID uuid : groups) {
|
||||
groupIncludeCache.evictMemberIn(uuid);
|
||||
groupIncludeCache.evictParentGroupsOf(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -96,7 +96,7 @@ import javax.security.auth.login.LoginException;
|
||||
return null;
|
||||
}
|
||||
|
||||
private final Cache<String, ImmutableSet<String>> groupsByInclude;
|
||||
private final Cache<String, ImmutableSet<String>> parentGroups;
|
||||
private final Config config;
|
||||
private final String server;
|
||||
private final String username;
|
||||
@@ -110,8 +110,8 @@ import javax.security.auth.login.LoginException;
|
||||
|
||||
@Inject
|
||||
Helper(@GerritServerConfig final Config config,
|
||||
@Named(LdapModule.GROUPS_BYINCLUDE_CACHE)
|
||||
Cache<String, ImmutableSet<String>> groupsByInclude) {
|
||||
@Named(LdapModule.PARENT_GROUPS_CACHE)
|
||||
Cache<String, ImmutableSet<String>> parentGroups) {
|
||||
this.config = config;
|
||||
this.server = LdapRealm.optional(config, "server");
|
||||
this.username = LdapRealm.optional(config, "username");
|
||||
@@ -128,7 +128,7 @@ import javax.security.auth.login.LoginException;
|
||||
} else {
|
||||
readTimeOutMillis = null;
|
||||
}
|
||||
this.groupsByInclude = groupsByInclude;
|
||||
this.parentGroups = parentGroups;
|
||||
this.connectionPoolConfig = getPoolProperties(config);
|
||||
}
|
||||
|
||||
@@ -303,8 +303,8 @@ import javax.security.auth.login.LoginException;
|
||||
private void recursivelyExpandGroups(final Set<String> groupDNs,
|
||||
final LdapSchema schema, final DirContext ctx, final String groupDN) {
|
||||
if (groupDNs.add(groupDN) && schema.accountMemberField != null) {
|
||||
ImmutableSet<String> cachedGroupDNs = groupsByInclude.getIfPresent(groupDN);
|
||||
if (cachedGroupDNs == null) {
|
||||
ImmutableSet<String> cachedParentsDNs = parentGroups.getIfPresent(groupDN);
|
||||
if (cachedParentsDNs == null) {
|
||||
// Recursively identify the groups it is a member of.
|
||||
ImmutableSet.Builder<String> dns = ImmutableSet.builder();
|
||||
try {
|
||||
@@ -323,10 +323,10 @@ import javax.security.auth.login.LoginException;
|
||||
} catch (NamingException e) {
|
||||
LdapRealm.log.warn("Could not find group " + groupDN, e);
|
||||
}
|
||||
cachedGroupDNs = dns.build();
|
||||
groupsByInclude.put(groupDN, cachedGroupDNs);
|
||||
cachedParentsDNs = dns.build();
|
||||
parentGroups.put(groupDN, cachedParentsDNs);
|
||||
}
|
||||
for (String dn : cachedGroupDNs) {
|
||||
for (String dn : cachedParentsDNs) {
|
||||
recursivelyExpandGroups(groupDNs, schema, ctx, dn);
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ public class LdapModule extends CacheModule {
|
||||
static final String USERNAME_CACHE = "ldap_usernames";
|
||||
static final String GROUP_CACHE = "ldap_groups";
|
||||
static final String GROUP_EXIST_CACHE = "ldap_group_existence";
|
||||
static final String GROUPS_BYINCLUDE_CACHE = "ldap_groups_byinclude";
|
||||
static final String PARENT_GROUPS_CACHE = "ldap_groups_byinclude";
|
||||
|
||||
|
||||
@Override
|
||||
@@ -55,7 +55,7 @@ public class LdapModule extends CacheModule {
|
||||
.expireAfterWrite(1, HOURS)
|
||||
.loader(LdapRealm.ExistenceLoader.class);
|
||||
|
||||
cache(GROUPS_BYINCLUDE_CACHE,
|
||||
cache(PARENT_GROUPS_CACHE,
|
||||
String.class,
|
||||
new TypeLiteral<ImmutableSet<String>>() {})
|
||||
.expireAfterWrite(1, HOURS);
|
||||
|
@@ -126,9 +126,9 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
|
||||
auditService.dispatchAddGroupsToGroup(me, newIncludedGroups.values());
|
||||
db.get().accountGroupById().insert(newIncludedGroups.values());
|
||||
for (AccountGroupById agi : newIncludedGroups.values()) {
|
||||
groupIncludeCache.evictMemberIn(agi.getIncludeUUID());
|
||||
groupIncludeCache.evictParentGroupsOf(agi.getIncludeUUID());
|
||||
}
|
||||
groupIncludeCache.evictMembersOf(group.getGroupUUID());
|
||||
groupIncludeCache.evictSubgroupsOf(group.getGroupUUID());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -91,9 +91,9 @@ public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input
|
||||
writeAudits(toRemove);
|
||||
db.get().accountGroupById().delete(toRemove);
|
||||
for (final AccountGroupById g : toRemove) {
|
||||
groupIncludeCache.evictMemberIn(g.getIncludeUUID());
|
||||
groupIncludeCache.evictParentGroupsOf(g.getIncludeUUID());
|
||||
}
|
||||
groupIncludeCache.evictMembersOf(internalGroup.getGroupUUID());
|
||||
groupIncludeCache.evictSubgroupsOf(internalGroup.getGroupUUID());
|
||||
}
|
||||
|
||||
return Response.none();
|
||||
|
@@ -166,7 +166,7 @@ public class ProjectWatch {
|
||||
for (AccountGroupMember m : db.accountGroupMembers().byGroup(ig.getId())) {
|
||||
matching.accounts.add(m.getAccountId());
|
||||
}
|
||||
for (AccountGroup.UUID m : args.groupIncludes.membersOf(uuid)) {
|
||||
for (AccountGroup.UUID m : args.groupIncludes.subgroupsOf(uuid)) {
|
||||
if (seen.add(m)) {
|
||||
q.add(m);
|
||||
}
|
||||
|
Reference in New Issue
Block a user