Auto-disable auto gc in jgit
By JGit's default, git-receive-pack will run auto gc after receiving data from git-push and updating refs. Disable this behavior in Gerrit init to avoid the additional load it creates: gc should be configured in gc config section or run as a separate process. Change-Id: I9450f8edbade7b6e789387645cfe70daa0949aff
This commit is contained in:
committed by
Matthias Sohn
parent
375241bdd1
commit
53528f49a5
@@ -5604,10 +5604,12 @@ Supported versions:
|
|||||||
|
|
||||||
[[receive.autogc]]receive.autogc::
|
[[receive.autogc]]receive.autogc::
|
||||||
+
|
+
|
||||||
By default, `git-receive-pack` will run auto gc after receiving data from git-push and updating refs.
|
By default, up to Gerrit 3.2 `git-receive-pack` will run auto gc after receiving data from git-push and updating refs.
|
||||||
You can stop it by setting this variable to `false`. This is recommended in gerrit to avoid the
|
You can stop it by setting this variable to `false`. This is recommended in gerrit to avoid the
|
||||||
additional load this creates. Instead schedule gc using link:cmd-gc.html#gc.startTime[gc.startTime]
|
additional load this creates. Instead schedule gc using link:cmd-gc.html#gc.startTime[gc.startTime]
|
||||||
and link:cmd-gc.html#gc.interval[gc.interval] or e.g. in a cron job that runs gc in a separate process.
|
and link:cmd-gc.html#gc.interval[gc.interval] or e.g. in a cron job that runs gc in a separate process.
|
||||||
|
Since Gerrit 3.3 the init command will auto-configure `git-receive-pack = false` in `etc/jgit.config` if
|
||||||
|
it wasn't set manually and show a warning if it was set to `true` manually.
|
||||||
|
|
||||||
GERRIT
|
GERRIT
|
||||||
------
|
------
|
||||||
|
|||||||
71
java/com/google/gerrit/pgm/init/InitJGitConfig.java
Normal file
71
java/com/google/gerrit/pgm/init/InitJGitConfig.java
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// Copyright (C) 2020 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.pgm.init;
|
||||||
|
|
||||||
|
import static com.google.gerrit.pgm.init.api.InitUtil.die;
|
||||||
|
|
||||||
|
import com.google.gerrit.pgm.init.api.ConsoleUI;
|
||||||
|
import com.google.gerrit.pgm.init.api.InitStep;
|
||||||
|
import com.google.gerrit.server.config.SitePaths;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||||
|
import org.eclipse.jgit.lib.ConfigConstants;
|
||||||
|
import org.eclipse.jgit.storage.file.FileBasedConfig;
|
||||||
|
import org.eclipse.jgit.util.FS;
|
||||||
|
|
||||||
|
/** Initialize the JGit configuration. */
|
||||||
|
@Singleton
|
||||||
|
class InitJGitConfig implements InitStep {
|
||||||
|
private final ConsoleUI ui;
|
||||||
|
private final SitePaths sitePaths;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
InitJGitConfig(ConsoleUI ui, SitePaths sitePaths) {
|
||||||
|
this.ui = ui;
|
||||||
|
this.sitePaths = sitePaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ui.header("JGit Configuration");
|
||||||
|
FileBasedConfig jgitConfig = new FileBasedConfig(sitePaths.jgit_config.toFile(), FS.DETECTED);
|
||||||
|
try {
|
||||||
|
jgitConfig.load();
|
||||||
|
if (!jgitConfig
|
||||||
|
.getNames(ConfigConstants.CONFIG_RECEIVE_SECTION)
|
||||||
|
.contains(ConfigConstants.CONFIG_KEY_AUTOGC)) {
|
||||||
|
jgitConfig.setBoolean(
|
||||||
|
ConfigConstants.CONFIG_RECEIVE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOGC, false);
|
||||||
|
jgitConfig.save();
|
||||||
|
ui.error(
|
||||||
|
"Auto-configured \"receive.autogc = false\" to disable auto-gc after git-receive-pack.");
|
||||||
|
} else if (jgitConfig.getBoolean(
|
||||||
|
ConfigConstants.CONFIG_RECEIVE_SECTION, ConfigConstants.CONFIG_KEY_AUTOGC, true)) {
|
||||||
|
ui.error(
|
||||||
|
"WARNING: JGit option \"receive.autogc = true\". This is not recommended in Gerrit.\n"
|
||||||
|
+ "git-receive-pack will run auto gc after receiving data from "
|
||||||
|
+ "git-push and updating refs.\n"
|
||||||
|
+ "Disable this behavior to avoid the additional load it creates: "
|
||||||
|
+ "gc should be configured in gc config section or run as a separate process.");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw die(String.format("Handling JGit configuration %s failed", sitePaths.jgit_config), e);
|
||||||
|
} catch (ConfigInvalidException e) {
|
||||||
|
throw die(String.format("Invalid JGit configuration %s", sitePaths.jgit_config), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,6 +40,7 @@ public class InitModule extends FactoryModule {
|
|||||||
// Steps are executed in the order listed here.
|
// Steps are executed in the order listed here.
|
||||||
//
|
//
|
||||||
step().to(InitGitManager.class);
|
step().to(InitGitManager.class);
|
||||||
|
step().to(InitJGitConfig.class);
|
||||||
step().to(InitLogging.class);
|
step().to(InitLogging.class);
|
||||||
step().to(InitIndex.class);
|
step().to(InitIndex.class);
|
||||||
step().to(InitAuth.class);
|
step().to(InitAuth.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user