Use container.replica as the property for readonly replicas
Change-Id: Ifd2f55107425bc6a1f9202d676694ba9c07d93c4
This commit is contained in:
@@ -1565,12 +1565,16 @@ line, separated by spaces.
|
||||
Execute `java -jar gerrit.war daemon --help` to see all possible
|
||||
options.
|
||||
|
||||
[[container.slave]]container.slave::
|
||||
[[container.replica]]container.replica::
|
||||
+
|
||||
Used on Gerrit replica installations. If set to true the Gerrit JVM is
|
||||
called with the '--replica' switch, enabling replica mode. If no value is
|
||||
set (or any other value), Gerrit defaults to master mode.
|
||||
|
||||
[[container.replica]]container.slave::
|
||||
+
|
||||
Backward compatibility for 'container.slave' config setting.
|
||||
|
||||
[[container.startupTimeout]]container.startupTimeout::
|
||||
+
|
||||
The maximum time (in seconds) to wait for a gerrit.sh start command
|
||||
|
@@ -44,6 +44,7 @@ import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.gerrit.server.git.receive.AsyncReceiveCommits;
|
||||
import com.google.gerrit.server.schema.JdbcAccountPatchReviewStore;
|
||||
import com.google.gerrit.server.ssh.NoSshModule;
|
||||
import com.google.gerrit.server.util.ReplicaUtil;
|
||||
import com.google.gerrit.server.util.SocketUtil;
|
||||
import com.google.gerrit.server.util.SystemLog;
|
||||
import com.google.gerrit.testing.FakeEmailSender;
|
||||
@@ -450,7 +451,7 @@ public class GerritServer implements AutoCloseable {
|
||||
@Nullable InMemoryRepositoryManager inMemoryRepoManager)
|
||||
throws Exception {
|
||||
Config cfg = desc.buildConfig(baseConfig);
|
||||
daemon.setReplica(isReplica(baseConfig) || isReplica(cfg));
|
||||
daemon.setReplica(ReplicaUtil.isReplica(baseConfig) || ReplicaUtil.isReplica(cfg));
|
||||
mergeTestConfig(cfg);
|
||||
// Set the log4j configuration to an invalid one to prevent system logs
|
||||
// from getting configured and creating log files.
|
||||
@@ -463,7 +464,8 @@ public class GerritServer implements AutoCloseable {
|
||||
cfg.setString(
|
||||
"accountPatchReviewDb", null, "url", JdbcAccountPatchReviewStore.TEST_IN_MEMORY_URL);
|
||||
daemon.setEnableHttpd(desc.httpd());
|
||||
daemon.setLuceneModule(LuceneIndexModule.singleVersionAllLatest(0, isReplica(baseConfig)));
|
||||
daemon.setLuceneModule(
|
||||
LuceneIndexModule.singleVersionAllLatest(0, ReplicaUtil.isReplica(baseConfig)));
|
||||
daemon.setDatabaseForTesting(
|
||||
ImmutableList.of(
|
||||
new InMemoryTestingDatabaseModule(cfg, site, inMemoryRepoManager),
|
||||
@@ -479,10 +481,6 @@ public class GerritServer implements AutoCloseable {
|
||||
return new GerritServer(desc, null, createTestInjector(daemon), daemon, null);
|
||||
}
|
||||
|
||||
private static boolean isReplica(Config baseConfig) {
|
||||
return baseConfig.getBoolean("container", "slave", false);
|
||||
}
|
||||
|
||||
private static GerritServer startOnDisk(
|
||||
Description desc,
|
||||
Path site,
|
||||
@@ -662,7 +660,7 @@ public class GerritServer implements AutoCloseable {
|
||||
Path site = server.testInjector.getInstance(Key.get(Path.class, SitePath.class));
|
||||
|
||||
Config cfg = server.testInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
|
||||
cfg.setBoolean("container", null, "slave", true);
|
||||
cfg.setBoolean("container", null, "replica", true);
|
||||
|
||||
InMemoryRepositoryManager inMemoryRepoManager = null;
|
||||
if (hasBinding(server.testInjector, InMemoryRepositoryManager.class)) {
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.group.db.Groups;
|
||||
import com.google.gerrit.server.index.group.GroupIndexer;
|
||||
import com.google.gerrit.server.util.ReplicaUtil;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Scopes;
|
||||
import java.io.IOException;
|
||||
@@ -50,8 +51,8 @@ public class ReindexGroupsAtStartup implements LifecycleListener {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
// Gerrit slaves without a reindex
|
||||
if (cfg.getBoolean("container", "slave", false)
|
||||
// Gerrit replicas without a reindex
|
||||
if (ReplicaUtil.isReplica(cfg)
|
||||
&& !cfg.getBoolean("index", "scheduledIndexer", "runOnStartup", true)) {
|
||||
return;
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ import com.google.gerrit.server.config.GerritServerConfigModule;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.gerrit.server.ioutil.HostPlatform;
|
||||
import com.google.gerrit.server.securestore.SecureStoreClassName;
|
||||
import com.google.gerrit.server.util.ReplicaUtil;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
@@ -144,7 +145,7 @@ public class Init extends BaseInit {
|
||||
});
|
||||
modules.add(new GerritServerConfigModule());
|
||||
Guice.createInjector(modules).injectMembers(this);
|
||||
if (!run.flags.cfg.getBoolean("container", "slave", false)) {
|
||||
if (!ReplicaUtil.isReplica(run.flags.cfg)) {
|
||||
reindexProjects();
|
||||
}
|
||||
start(run);
|
||||
|
@@ -34,6 +34,7 @@ import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.index.IndexModule;
|
||||
import com.google.gerrit.server.index.change.ChangeSchemaDefinitions;
|
||||
import com.google.gerrit.server.plugins.PluginGuiceEnvironment;
|
||||
import com.google.gerrit.server.util.ReplicaUtil;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
@@ -144,14 +145,15 @@ public class Reindex extends SiteProgram {
|
||||
if (changesVersion != null) {
|
||||
versions.put(ChangeSchemaDefinitions.INSTANCE.getName(), changesVersion);
|
||||
}
|
||||
boolean slave = globalConfig.getBoolean("container", "slave", false);
|
||||
boolean replica = ReplicaUtil.isReplica(globalConfig);
|
||||
List<Module> modules = new ArrayList<>();
|
||||
Module indexModule;
|
||||
IndexType indexType = IndexModule.getIndexType(dbInjector);
|
||||
if (indexType.isLucene()) {
|
||||
indexModule = LuceneIndexModule.singleVersionWithExplicitVersions(versions, threads, slave);
|
||||
indexModule = LuceneIndexModule.singleVersionWithExplicitVersions(versions, threads, replica);
|
||||
} else if (indexType.isElasticsearch()) {
|
||||
indexModule = ElasticIndexModule.singleVersionWithExplicitVersions(versions, threads, slave);
|
||||
indexModule =
|
||||
ElasticIndexModule.singleVersionWithExplicitVersions(versions, threads, replica);
|
||||
} else {
|
||||
throw new IllegalStateException("unsupported index.type = " + indexType);
|
||||
}
|
||||
|
25
java/com/google/gerrit/server/util/ReplicaUtil.java
Normal file
25
java/com/google/gerrit/server/util/ReplicaUtil.java
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2019 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.server.util;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
public class ReplicaUtil {
|
||||
/** Provides backward compatibility for container.slave property. */
|
||||
public static boolean isReplica(Config cfg) {
|
||||
return cfg.getBoolean("container", "slave", false)
|
||||
|| cfg.getBoolean("container", "replica", false);
|
||||
}
|
||||
}
|
@@ -299,7 +299,7 @@ public class InMemoryModule extends FactoryModule {
|
||||
|
||||
private Module indexModule(String moduleClassName) {
|
||||
try {
|
||||
boolean slave = cfg.getBoolean("container", "slave", false);
|
||||
boolean slave = cfg.getBoolean("container", "replica", false);
|
||||
Class<?> clazz = Class.forName(moduleClassName);
|
||||
Method m =
|
||||
clazz.getMethod("singleVersionWithExplicitVersions", Map.class, int.class, boolean.class);
|
||||
|
@@ -241,7 +241,7 @@ public abstract class AbstractReindexTests extends StandaloneSiteTest {
|
||||
}
|
||||
|
||||
private void enableSlaveMode() throws Exception {
|
||||
updateConfig(config -> config.setBoolean("container", null, "slave", true));
|
||||
updateConfig(config -> config.setBoolean("container", null, "replica", true));
|
||||
}
|
||||
|
||||
private void updateConfig(Consumer<Config> configConsumer) throws Exception {
|
||||
|
Reference in New Issue
Block a user