From 2f94e2e5627ff0870b3a1842c3fbf5cbfa3a6a2d Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Wed, 11 Mar 2015 15:13:31 +0100 Subject: [PATCH] Add "aggressive" option to REST call "Run GC" When triggering a garbage collection through REST it can be specified whether to run an aggressive garbage collection or not. Change-Id: If7472805331ea07e2d83f13d513c06a2203a1b94 --- Documentation/rest-api-projects.txt | 2 ++ .../google/gerrit/server/git/GarbageCollection.java | 11 +++++++++-- .../google/gerrit/server/project/GarbageCollect.java | 7 +++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Documentation/rest-api-projects.txt b/Documentation/rest-api-projects.txt index a909ab4c44..a25c7bba2f 100644 --- a/Documentation/rest-api-projects.txt +++ b/Documentation/rest-api-projects.txt @@ -2116,6 +2116,8 @@ collection. |Field Name ||Description |`show_progress` |`false` if not set| Whether progress information should be shown. +|`aggressive` |`false` if not set| +Whether an aggressive garbage collection should be done. |============================= [[head-input]] diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollection.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollection.java index 24af14d8d8..55672cf942 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollection.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollection.java @@ -63,6 +63,11 @@ public class GarbageCollection { public GarbageCollectionResult run(List projectNames, PrintWriter writer) { + return run(projectNames, false, writer); + } + + public GarbageCollectionResult run(List projectNames, + boolean aggressive, PrintWriter writer) { GarbageCollectionResult result = new GarbageCollectionResult(); Set projectsToGc = gcQueue.addAll(projectNames); for (Project.NameKey projectName : Sets.difference( @@ -74,9 +79,10 @@ public class GarbageCollection { Repository repo = null; try { repo = repoManager.openRepository(p); - logGcConfiguration(p, repo); + logGcConfiguration(p, repo, aggressive); print(writer, "collecting garbage for \"" + p + "\":\n"); GarbageCollectCommand gc = Git.wrap(repo).gc(); + gc.setAggressive(aggressive); logGcInfo(p, "before:", gc.getStatistics()); gc.setProgressMonitor(writer != null ? new TextProgressMonitor(writer) : NullProgressMonitor.INSTANCE); @@ -123,9 +129,10 @@ public class GarbageCollection { } private static void logGcConfiguration(Project.NameKey projectName, - Repository repo) { + Repository repo, boolean aggressive) { StringBuilder b = new StringBuilder(); Config cfg = repo.getConfig(); + b.append("gc.aggressive=").append(aggressive).append("; "); b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION, null)); for (String subsection : cfg.getSubsections(ConfigConstants.CONFIG_GC_SECTION)) { b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION, diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java index fe1086b6f1..a5a96b16ce 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java @@ -41,6 +41,7 @@ public class GarbageCollect implements RestModifyView, UiAction { public static class Input { public boolean showProgress; + public boolean aggressive; } private final boolean canGC; @@ -68,8 +69,10 @@ public class GarbageCollect implements RestModifyView, } }; try { - GarbageCollectionResult result = garbageCollectionFactory.create().run( - Collections.singletonList(rsrc.getNameKey()), input.showProgress ? writer : null); + GarbageCollectionResult result = + garbageCollectionFactory.create().run( + Collections.singletonList(rsrc.getNameKey()), input.aggressive, + input.showProgress ? writer : null); String msg = "Garbage collection completed successfully."; if (result.hasErrors()) { for (GarbageCollectionResult.Error e : result.getErrors()) {