Search in sources :

Example 1 with DeleteZombieCommentsRefs

use of com.google.gerrit.server.notedb.DeleteZombieCommentsRefs in project gerrit by GerritCodeReview.

the class Schema_182 method upgrade.

@Override
public void upgrade(Arguments args, UpdateUI ui) throws Exception {
    AllUsersName allUsers = args.allUsers;
    GitRepositoryManager gitRepoManager = args.repoManager;
    DeleteZombieCommentsRefs cleanup = new DeleteZombieCommentsRefs(allUsers, gitRepoManager, 100, ui::message);
    cleanup.execute();
}
Also used : DeleteZombieCommentsRefs(com.google.gerrit.server.notedb.DeleteZombieCommentsRefs) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) AllUsersName(com.google.gerrit.server.config.AllUsersName)

Example 2 with DeleteZombieCommentsRefs

use of com.google.gerrit.server.notedb.DeleteZombieCommentsRefs in project gerrit by GerritCodeReview.

the class DeleteZombieCommentsRefsTest method cleanZombieDraftsWithPercentage.

@Test
public void cleanZombieDraftsWithPercentage() throws Exception {
    try (Repository usersRepo = repoManager.createRepository(allUsersProject)) {
        Ref ref1 = createRefWithNonEmptyTreeCommit(usersRepo, 1005, 1000001);
        Ref ref2 = createRefWithEmptyTreeCommit(usersRepo, 1006, 1000002);
        Ref ref3 = createRefWithEmptyTreeCommit(usersRepo, 1060, 1000002);
        assertThat(usersRepo.getRefDatabase().getRefs()).hasSize(3);
        int cleanupPercentage = 50;
        DeleteZombieCommentsRefs clean = new DeleteZombieCommentsRefs(new AllUsersName("All-Users"), repoManager, cleanupPercentage);
        clean.execute();
        /* ref1 not deleted, ref2 deleted, ref3 not deleted because of the clean percentage */
        assertThat(usersRepo.getRefDatabase().getRefs()).hasSize(2);
        assertThat(usersRepo.exactRef(ref1.getName())).isNotNull();
        assertThat(usersRepo.exactRef(ref2.getName())).isNull();
        assertThat(usersRepo.exactRef(ref3.getName())).isNotNull();
        /* Re-execute the cleanup and make sure nothing's changed */
        clean.execute();
        assertThat(usersRepo.getRefDatabase().getRefs()).hasSize(2);
        assertThat(usersRepo.exactRef(ref1.getName())).isNotNull();
        assertThat(usersRepo.exactRef(ref2.getName())).isNull();
        assertThat(usersRepo.exactRef(ref3.getName())).isNotNull();
        /* Increase the cleanup percentage */
        cleanupPercentage = 70;
        clean = new DeleteZombieCommentsRefs(new AllUsersName("All-Users"), repoManager, cleanupPercentage);
        clean.execute();
        /* Now ref3 is deleted */
        assertThat(usersRepo.getRefDatabase().getRefs()).hasSize(1);
        assertThat(usersRepo.exactRef(ref1.getName())).isNotNull();
        assertThat(usersRepo.exactRef(ref2.getName())).isNull();
        assertThat(usersRepo.exactRef(ref3.getName())).isNull();
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) DeleteZombieCommentsRefs(com.google.gerrit.server.notedb.DeleteZombieCommentsRefs) AllUsersName(com.google.gerrit.server.config.AllUsersName) Test(org.junit.Test)

Example 3 with DeleteZombieCommentsRefs

use of com.google.gerrit.server.notedb.DeleteZombieCommentsRefs in project gerrit by GerritCodeReview.

the class DeleteZombieCommentsRefsTest method cleanZombieDraftsSmall.

@Test
public void cleanZombieDraftsSmall() throws Exception {
    try (Repository usersRepo = repoManager.createRepository(allUsersProject)) {
        Ref ref1 = createRefWithNonEmptyTreeCommit(usersRepo, 1, 1000001);
        Ref ref2 = createRefWithEmptyTreeCommit(usersRepo, 1, 1000002);
        DeleteZombieCommentsRefs clean = new DeleteZombieCommentsRefs(new AllUsersName("All-Users"), repoManager, null);
        clean.execute();
        /* Check that ref1 still exists, and ref2 is deleted */
        assertThat(usersRepo.exactRef(ref1.getName())).isNotNull();
        assertThat(usersRepo.exactRef(ref2.getName())).isNull();
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) DeleteZombieCommentsRefs(com.google.gerrit.server.notedb.DeleteZombieCommentsRefs) AllUsersName(com.google.gerrit.server.config.AllUsersName) Test(org.junit.Test)

Example 4 with DeleteZombieCommentsRefs

use of com.google.gerrit.server.notedb.DeleteZombieCommentsRefs in project gerrit by GerritCodeReview.

the class DeleteZombieDrafts method run.

@Override
public int run() throws IOException {
    mustHaveValidSite();
    Injector sysInjector = getSysInjector();
    DeleteZombieCommentsRefs cleanup = sysInjector.getInstance(DeleteZombieCommentsRefs.Factory.class).create(cleanupPercentage);
    cleanup.execute();
    return 0;
}
Also used : Injector(com.google.inject.Injector) DeleteZombieCommentsRefs(com.google.gerrit.server.notedb.DeleteZombieCommentsRefs)

Example 5 with DeleteZombieCommentsRefs

use of com.google.gerrit.server.notedb.DeleteZombieCommentsRefs in project gerrit by GerritCodeReview.

the class DeleteZombieCommentsRefsTest method cleanZombieDraftsLarge.

@Test
public void cleanZombieDraftsLarge() throws Exception {
    try (Repository usersRepo = repoManager.createRepository(allUsersProject)) {
        int goodRefsCnt = 5000;
        int zombieRefsCnt = 5000;
        int userIdGoodRefs = 1000001;
        int userIdBadRefs = 1000002;
        Ref nonEmptyBaseRef = createRefWithNonEmptyTreeCommit(usersRepo, 1, userIdGoodRefs);
        Ref emptyBaseRef = createRefWithEmptyTreeCommit(usersRepo, 1, userIdBadRefs);
        List<String> goodRefs = createNRefsOnCommit(usersRepo, nonEmptyBaseRef.getObjectId(), goodRefsCnt, userIdGoodRefs);
        List<String> badRefs = createNRefsOnCommit(usersRepo, emptyBaseRef.getObjectId(), zombieRefsCnt, userIdBadRefs);
        goodRefs.add(0, nonEmptyBaseRef.getName());
        badRefs.add(0, emptyBaseRef.getName());
        assertThat(usersRepo.getRefDatabase().getRefs().size()).isEqualTo(goodRefs.size() + badRefs.size());
        DeleteZombieCommentsRefs clean = new DeleteZombieCommentsRefs(new AllUsersName("All-Users"), repoManager, null);
        clean.execute();
        assertThat(usersRepo.getRefDatabase().getRefs().stream().map(Ref::getName).collect(toImmutableList())).containsExactlyElementsIn(goodRefs);
        assertThat(usersRepo.getRefDatabase().getRefs().stream().map(Ref::getName).collect(toImmutableList())).containsNoneIn(badRefs);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) DeleteZombieCommentsRefs(com.google.gerrit.server.notedb.DeleteZombieCommentsRefs) AllUsersName(com.google.gerrit.server.config.AllUsersName) Test(org.junit.Test)

Aggregations

DeleteZombieCommentsRefs (com.google.gerrit.server.notedb.DeleteZombieCommentsRefs)5 AllUsersName (com.google.gerrit.server.config.AllUsersName)4 Ref (org.eclipse.jgit.lib.Ref)3 Repository (org.eclipse.jgit.lib.Repository)3 Test (org.junit.Test)3 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)1 Injector (com.google.inject.Injector)1