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
This commit is contained in:
parent
7ed32ecde5
commit
2f94e2e562
@ -2116,6 +2116,8 @@ collection.
|
|||||||
|Field Name ||Description
|
|Field Name ||Description
|
||||||
|`show_progress` |`false` if not set|
|
|`show_progress` |`false` if not set|
|
||||||
Whether progress information should be shown.
|
Whether progress information should be shown.
|
||||||
|
|`aggressive` |`false` if not set|
|
||||||
|
Whether an aggressive garbage collection should be done.
|
||||||
|=============================
|
|=============================
|
||||||
|
|
||||||
[[head-input]]
|
[[head-input]]
|
||||||
|
@ -63,6 +63,11 @@ public class GarbageCollection {
|
|||||||
|
|
||||||
public GarbageCollectionResult run(List<Project.NameKey> projectNames,
|
public GarbageCollectionResult run(List<Project.NameKey> projectNames,
|
||||||
PrintWriter writer) {
|
PrintWriter writer) {
|
||||||
|
return run(projectNames, false, writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GarbageCollectionResult run(List<Project.NameKey> projectNames,
|
||||||
|
boolean aggressive, PrintWriter writer) {
|
||||||
GarbageCollectionResult result = new GarbageCollectionResult();
|
GarbageCollectionResult result = new GarbageCollectionResult();
|
||||||
Set<Project.NameKey> projectsToGc = gcQueue.addAll(projectNames);
|
Set<Project.NameKey> projectsToGc = gcQueue.addAll(projectNames);
|
||||||
for (Project.NameKey projectName : Sets.difference(
|
for (Project.NameKey projectName : Sets.difference(
|
||||||
@ -74,9 +79,10 @@ public class GarbageCollection {
|
|||||||
Repository repo = null;
|
Repository repo = null;
|
||||||
try {
|
try {
|
||||||
repo = repoManager.openRepository(p);
|
repo = repoManager.openRepository(p);
|
||||||
logGcConfiguration(p, repo);
|
logGcConfiguration(p, repo, aggressive);
|
||||||
print(writer, "collecting garbage for \"" + p + "\":\n");
|
print(writer, "collecting garbage for \"" + p + "\":\n");
|
||||||
GarbageCollectCommand gc = Git.wrap(repo).gc();
|
GarbageCollectCommand gc = Git.wrap(repo).gc();
|
||||||
|
gc.setAggressive(aggressive);
|
||||||
logGcInfo(p, "before:", gc.getStatistics());
|
logGcInfo(p, "before:", gc.getStatistics());
|
||||||
gc.setProgressMonitor(writer != null ? new TextProgressMonitor(writer)
|
gc.setProgressMonitor(writer != null ? new TextProgressMonitor(writer)
|
||||||
: NullProgressMonitor.INSTANCE);
|
: NullProgressMonitor.INSTANCE);
|
||||||
@ -123,9 +129,10 @@ public class GarbageCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void logGcConfiguration(Project.NameKey projectName,
|
private static void logGcConfiguration(Project.NameKey projectName,
|
||||||
Repository repo) {
|
Repository repo, boolean aggressive) {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
Config cfg = repo.getConfig();
|
Config cfg = repo.getConfig();
|
||||||
|
b.append("gc.aggressive=").append(aggressive).append("; ");
|
||||||
b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION, null));
|
b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION, null));
|
||||||
for (String subsection : cfg.getSubsections(ConfigConstants.CONFIG_GC_SECTION)) {
|
for (String subsection : cfg.getSubsections(ConfigConstants.CONFIG_GC_SECTION)) {
|
||||||
b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION,
|
b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION,
|
||||||
|
@ -41,6 +41,7 @@ public class GarbageCollect implements RestModifyView<ProjectResource, Input>,
|
|||||||
UiAction<ProjectResource> {
|
UiAction<ProjectResource> {
|
||||||
public static class Input {
|
public static class Input {
|
||||||
public boolean showProgress;
|
public boolean showProgress;
|
||||||
|
public boolean aggressive;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean canGC;
|
private final boolean canGC;
|
||||||
@ -68,8 +69,10 @@ public class GarbageCollect implements RestModifyView<ProjectResource, Input>,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
GarbageCollectionResult result = garbageCollectionFactory.create().run(
|
GarbageCollectionResult result =
|
||||||
Collections.singletonList(rsrc.getNameKey()), input.showProgress ? writer : null);
|
garbageCollectionFactory.create().run(
|
||||||
|
Collections.singletonList(rsrc.getNameKey()), input.aggressive,
|
||||||
|
input.showProgress ? writer : null);
|
||||||
String msg = "Garbage collection completed successfully.";
|
String msg = "Garbage collection completed successfully.";
|
||||||
if (result.hasErrors()) {
|
if (result.hasErrors()) {
|
||||||
for (GarbageCollectionResult.Error e : result.getErrors()) {
|
for (GarbageCollectionResult.Error e : result.getErrors()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user