Search in sources :

Example 1 with GroupIndexer

use of com.google.gerrit.server.index.group.GroupIndexer in project gerrit by GerritCodeReview.

the class PeriodicGroupIndexer method run.

@Override
public synchronized void run() {
    try (Repository allUsers = repoManager.openRepository(allUsersName)) {
        ImmutableSet<AccountGroup.UUID> newGroupUuids = GroupNameNotes.loadAllGroups(allUsers).stream().map(GroupReference::getUUID).collect(toImmutableSet());
        GroupIndexer groupIndexer = groupIndexerProvider.get();
        int reindexCounter = 0;
        for (AccountGroup.UUID groupUuid : newGroupUuids) {
            if (groupIndexer.reindexIfStale(groupUuid)) {
                reindexCounter++;
            }
        }
        if (groupUuids != null) {
            // index.
            for (AccountGroup.UUID groupUuid : Sets.difference(groupUuids, newGroupUuids)) {
                groupIndexer.index(groupUuid);
                reindexCounter++;
            }
        }
        groupUuids = newGroupUuids;
        logger.atInfo().log("Run group indexer, %s groups reindexed", reindexCounter);
    } catch (Exception t) {
        logger.atSevere().withCause(t).log("Failed to reindex groups");
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupIndexer(com.google.gerrit.server.index.group.GroupIndexer)

Example 2 with GroupIndexer

use of com.google.gerrit.server.index.group.GroupIndexer in project gerrit by GerritCodeReview.

the class ProjectResetterTest method groupEviction.

@Test
public void groupEviction() throws Exception {
    AccountGroup.UUID uuid1 = AccountGroup.uuid("abcd1");
    AccountGroup.UUID uuid2 = AccountGroup.uuid("abcd2");
    AccountGroup.UUID uuid3 = AccountGroup.uuid("abcd3");
    Project.NameKey allUsers = Project.nameKey(AllUsersNameProvider.DEFAULT);
    Repository allUsersRepo = repoManager.createRepository(allUsers);
    GroupCache cache = mock(GroupCache.class);
    GroupIndexer indexer = mock(GroupIndexer.class);
    GroupIncludeCache includeCache = mock(GroupIncludeCache.class);
    createRef(allUsersRepo, RefNames.refsGroups(uuid1));
    Ref ref2 = createRef(allUsersRepo, RefNames.refsGroups(uuid2));
    try (ProjectResetter resetProject = builder(null, null, null, cache, includeCache, indexer, null).build(new ProjectResetter.Config().reset(project).reset(allUsers))) {
        updateRef(allUsersRepo, ref2);
        createRef(allUsersRepo, RefNames.refsGroups(uuid3));
    }
    verify(cache).evict(uuid2);
    verify(indexer).index(uuid2);
    verify(includeCache).evictParentGroupsOf(uuid2);
    verify(cache).evict(uuid3);
    verify(indexer).index(uuid3);
    verify(includeCache).evictParentGroupsOf(uuid3);
    verifyNoMoreInteractions(cache, indexer, includeCache);
}
Also used : Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupIndexer(com.google.gerrit.server.index.group.GroupIndexer) GroupCache(com.google.gerrit.server.account.GroupCache) GroupIncludeCache(com.google.gerrit.server.account.GroupIncludeCache) Test(org.junit.Test)

Aggregations

AccountGroup (com.google.gerrit.entities.AccountGroup)2 GroupIndexer (com.google.gerrit.server.index.group.GroupIndexer)2 Repository (org.eclipse.jgit.lib.Repository)2 Project (com.google.gerrit.entities.Project)1 GroupCache (com.google.gerrit.server.account.GroupCache)1 GroupIncludeCache (com.google.gerrit.server.account.GroupIncludeCache)1 Ref (org.eclipse.jgit.lib.Ref)1 Test (org.junit.Test)1