Delete system config table

Rely on gerrit.site_path system property for the site_path location for
unattended setup mode.

Normally schema migration is not supported on stable branch. Given that
in the next gerrit release ReviewDb is going to be removed and schema
migration procedure is migrated from ReviewDb to NoteDb, we can perform
last ReviewDb schema migration on stable branch.

Change-Id: Id6e5348ef017f8add059ebb572eaa4d817f7fff5
This commit is contained in:
David Ostrovsky 2016-03-15 12:17:35 +01:00
parent fc2599fbd2
commit 3329529068
18 changed files with 64 additions and 316 deletions

View File

@ -27,15 +27,14 @@ If the `gerrit.site_path` system property is defined then the init is
run for that site. The database connectivity, in that case, is defined
in the `etc/gerrit.config`.
If `gerrit.site_path` is not defined then Gerrit will try to find the
`gerrit.init_path` system property. If defined this property will be
used to determine the site path. The database connectivity, also for
this case, is defined by the `jdbc/ReviewDb` JNDI property.
`gerrit.site_path` system property must be defined to run the init for
that site.
[WARNING]
Defining the `jdbc/ReviewDb` JNDI property for an H2 database under the
path defined by either `gerrit.site_path` or `gerrit.init_path` will
cause an incomplete auto initialization and Gerrit will fail to start.
path defined by `gerrit.site_path` will cause an incomplete auto
initialization and Gerrit will fail to start.
Opening a connection to such a database will create a subfolder under the
site path folder (in order to create the H2 database) and Gerrit will
no longer consider that site path to be new and, because of that,

View File

@ -5090,16 +5090,6 @@ command.
The format is one Base-64 encoded public key per line.
== Database system_config
Several columns in the `system_config` table within the metadata
database may be set to control how Gerrit behaves.
[NOTE]
The contents of the `system_config` table are cached at startup
by Gerrit. If you modify any columns in this table, Gerrit needs
to be restarted before it will use the new values.
== Configuring the Polygerrit UI
Please see link:dev-polygerrit.html[UI] on configuring the Polygerrit UI.

View File

@ -105,9 +105,8 @@ script and modify it for your configuration:
----
[TIP]
Under Jetty, restarting the web application (e.g. after modifying
`system_config`) is as simple as touching the context config file:
`'$JETTY_HOME'/contexts/gerrit.xml`
Under Jetty, restarting the web application is as simple as
touching the context config file: `'$JETTY_HOME'/contexts/gerrit.xml`
[[tomcat]]
== Tomcat 7.x

View File

@ -14,19 +14,17 @@
package com.google.gerrit.httpd.init;
import com.google.common.base.Strings;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.pgm.init.BaseInit;
import com.google.gerrit.pgm.init.PluginsDistribution;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
public final class SiteInitializer {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String GERRIT_SITE_PATH = "gerrit.site_path";
private final String sitePath;
private final String initPath;
@ -53,42 +51,29 @@ public final class SiteInitializer {
return;
}
try (Connection conn = connectToDb()) {
Path site = getSiteFromReviewDb(conn);
if (site == null && initPath != null) {
site = Paths.get(initPath);
}
if (site != null) {
logger.atInfo().log("Initializing site at %s", site.toRealPath().normalize());
new BaseInit(
site,
new ReviewDbDataSourceProvider(),
false,
false,
pluginsDistribution,
pluginsToInstall)
.run();
}
String path = System.getProperty(GERRIT_SITE_PATH);
Path site = null;
if (!Strings.isNullOrEmpty(path)) {
site = Paths.get(path);
}
if (site == null && initPath != null) {
site = Paths.get(initPath);
}
if (site != null) {
logger.atInfo().log("Initializing site at %s", site.toRealPath().normalize());
new BaseInit(
site,
new ReviewDbDataSourceProvider(),
false,
false,
pluginsDistribution,
pluginsToInstall)
.run();
}
} catch (Exception e) {
logger.atSevere().withCause(e).log("Site init failed");
throw new RuntimeException(e);
}
}
private Connection connectToDb() throws SQLException {
return new ReviewDbDataSourceProvider().get().getConnection();
}
private Path getSiteFromReviewDb(Connection conn) {
try (Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT site_path FROM system_config")) {
if (rs.next()) {
return Paths.get(rs.getString(1));
}
} catch (SQLException e) {
return null;
}
return null;
}
}

View File

@ -1,58 +0,0 @@
// Copyright (C) 2009 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.httpd.init;
import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.config.SitePath;
import com.google.gerrit.server.schema.ReviewDbFactory;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
/** Provides {@link Path} annotated with {@link SitePath}. */
class SitePathFromSystemConfigProvider implements Provider<Path> {
private final Path path;
@Inject
SitePathFromSystemConfigProvider(@ReviewDbFactory SchemaFactory<ReviewDb> schemaFactory)
throws OrmException {
path = read(schemaFactory);
}
@Override
public Path get() {
return path;
}
private static Path read(SchemaFactory<ReviewDb> schemaFactory) throws OrmException {
try (ReviewDb db = schemaFactory.open()) {
List<SystemConfig> all = db.systemConfig().all().toList();
switch (all.size()) {
case 1:
return Paths.get(all.get(0).sitePath);
case 0:
throw new OrmException("system_config table is empty");
default:
throw new OrmException(
"system_config must have exactly 1 row; found " + all.size() + " rows instead");
}
}
}
}

View File

@ -107,6 +107,7 @@ import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Provider;
import com.google.inject.ProvisionException;
import com.google.inject.name.Names;
import com.google.inject.servlet.GuiceFilter;
import com.google.inject.servlet.GuiceServletContextListener;
@ -134,6 +135,8 @@ import org.eclipse.jgit.lib.Config;
public class WebAppInitializer extends GuiceServletContextListener implements Filter {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String GERRIT_SITE_PATH = "gerrit.site_path";
private Path sitePath;
private Injector dbInjector;
private Injector cfgInjector;
@ -155,9 +158,11 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
private synchronized void init() {
if (manager == null) {
final String path = System.getProperty("gerrit.site_path");
String path = System.getProperty(GERRIT_SITE_PATH);
if (path != null) {
sitePath = Paths.get(path);
} else {
throw new ProvisionException(GERRIT_SITE_PATH + " must be defined");
}
if (System.getProperty("gerrit.init") != null) {
@ -171,7 +176,7 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
}
new SiteInitializer(
path,
System.getProperty("gerrit.init_path"),
System.getProperty(GERRIT_SITE_PATH),
new UnzippedDistribution(servletContext),
pluginsToInstall)
.init();
@ -292,21 +297,6 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
listener().to(ReviewDbDataSourceProvider.class);
}
});
// If we didn't get the site path from the system property
// we need to get it from the database, as that's our old
// method of locating the site path on disk.
//
modules.add(
new AbstractModule() {
@Override
protected void configure() {
bind(Path.class)
.annotatedWith(SitePath.class)
.toProvider(SitePathFromSystemConfigProvider.class)
.in(SINGLETON);
}
});
modules.add(new GerritServerConfigModule());
}
modules.add(new DatabaseModule());

View File

@ -1,89 +0,0 @@
// Copyright (C) 2008 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.reviewdb.client;
import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.StringKey;
/** Global configuration needed to serve web requests. */
public final class SystemConfig {
public static final class Key extends StringKey<com.google.gwtorm.client.Key<?>> {
private static final long serialVersionUID = 1L;
private static final String VALUE = "X";
@Column(id = 1, length = 1)
protected String one = VALUE;
public Key() {}
@Override
public String get() {
return VALUE;
}
@Override
protected void set(String newValue) {
assert get().equals(newValue);
}
}
/** Construct a new, unconfigured instance. */
public static SystemConfig create() {
final SystemConfig r = new SystemConfig();
r.singleton = new SystemConfig.Key();
return r;
}
@Column(id = 1)
protected Key singleton;
/** Local filesystem location of header/footer/CSS configuration files */
@Column(id = 3, notNull = false, length = Integer.MAX_VALUE)
public transient String sitePath;
// DO NOT LOOK BELOW THIS LINE. These fields have all been deleted,
// but survive to support schema upgrade code.
/** DEPRECATED DO NOT USE */
@Column(id = 2, length = 36, notNull = false)
public transient String registerEmailPrivateKey;
/** DEPRECATED DO NOT USE */
@Column(id = 4, notNull = false)
public AccountGroup.Id adminGroupId;
/** DEPRECATED DO NOT USE */
@Column(id = 10, notNull = false)
public AccountGroup.UUID adminGroupUUID;
/** DEPRECATED DO NOT USE */
@Column(id = 5, notNull = false)
public AccountGroup.Id anonymousGroupId;
/** DEPRECATED DO NOT USE */
@Column(id = 6, notNull = false)
public AccountGroup.Id registeredGroupId;
/** DEPRECATED DO NOT USE */
@Column(id = 7, notNull = false)
public Project.NameKey wildProjectName;
/** DEPRECATED DO NOT USE */
@Column(id = 9, notNull = false)
public AccountGroup.Id ownerGroupId;
/** DEPRECATED DO NOT USE */
@Column(id = 8, notNull = false)
public AccountGroup.Id batchUsersGroupId;
/** DEPRECATED DO NOT USE */
@Column(id = 11, notNull = false)
public AccountGroup.UUID batchUsersGroupUUID;
protected SystemConfig() {}
}

View File

@ -17,7 +17,6 @@ package com.google.gerrit.reviewdb.server;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.Relation;
import com.google.gwtorm.server.Schema;
@ -31,7 +30,6 @@ import com.google.gwtorm.server.Sequence;
* <ul>
* <li>{@link Account}: Per-user account registration, preferences, identity.
* <li>{@link Change}: All review information about a single proposed change.
* <li>{@link SystemConfig}: Server-wide settings, managed by administrator.
* </ul>
*/
public interface ReviewDb extends Schema {
@ -40,8 +38,7 @@ public interface ReviewDb extends Schema {
@Relation(id = 1)
SchemaVersionAccess schemaVersion();
@Relation(id = 2)
SystemConfigAccess systemConfig();
// Deleted @Relation(id = 2)
// Deleted @Relation(id = 3)

View File

@ -109,11 +109,6 @@ public class ReviewDbWrapper implements ReviewDb {
return delegate.schemaVersion();
}
@Override
public SystemConfigAccess systemConfig() {
return delegate.systemConfig();
}
@Override
public ChangeAccess changes() {
return delegate.changes();

View File

@ -1,32 +0,0 @@
// Copyright (C) 2008 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.reviewdb.server;
import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.gwtorm.server.Access;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.PrimaryKey;
import com.google.gwtorm.server.Query;
import com.google.gwtorm.server.ResultSet;
/** Access interface for {@link SystemConfig}. */
public interface SystemConfigAccess extends Access<SystemConfig, SystemConfig.Key> {
@Override
@PrimaryKey("singleton")
SystemConfig get(SystemConfig.Key key) throws OrmException;
@Query
ResultSet<SystemConfig> all() throws OrmException;
}

View File

@ -20,7 +20,6 @@ import com.google.gerrit.common.data.GroupReference;
import com.google.gerrit.metrics.MetricMaker;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.CurrentSchemaVersion;
import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.Sequences;
@ -150,7 +149,6 @@ public class SchemaCreator {
GroupReference admins = createGroupReference("Administrators");
GroupReference batchUsers = createGroupReference("Non-Interactive Users");
initSystemConfig(db);
allProjectsCreator.setAdministrators(admins).setBatchUsers(batchUsers).create();
// We have to create the All-Users repository before we can use it to store the groups in it.
allUsersCreator.setAdministrators(admins).create();
@ -274,15 +272,4 @@ public class SchemaCreator {
.setGroupUUID(groupReference.getUUID())
.build();
}
private SystemConfig initSystemConfig(ReviewDb db) throws OrmException {
SystemConfig s = SystemConfig.create();
try {
s.sitePath = site_path.toRealPath().normalize().toString();
} catch (IOException e) {
s.sitePath = site_path.toAbsolutePath().normalize().toString();
}
db.systemConfig().insert(Collections.singleton(s));
return s;
}
}

View File

@ -16,7 +16,6 @@ package com.google.gerrit.server.schema;
import com.google.common.annotations.VisibleForTesting;
import com.google.gerrit.reviewdb.client.CurrentSchemaVersion;
import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.reviewdb.server.ReviewDbUtil;
import com.google.gerrit.server.GerritPersonIdent;
@ -38,7 +37,6 @@ import com.google.inject.Provider;
import com.google.inject.Stage;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Collections;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.PersonIdent;
@ -46,18 +44,13 @@ import org.eclipse.jgit.lib.PersonIdent;
/** Creates or updates the current database schema. */
public class SchemaUpdater {
private final SchemaFactory<ReviewDb> schema;
private final SitePaths site;
private final SchemaCreator creator;
private final Provider<SchemaVersion> updater;
@Inject
SchemaUpdater(
@ReviewDbFactory SchemaFactory<ReviewDb> schema,
SitePaths site,
SchemaCreator creator,
Injector parent) {
@ReviewDbFactory SchemaFactory<ReviewDb> schema, SchemaCreator creator, Injector parent) {
this.schema = schema;
this.site = site;
this.creator = creator;
this.updater = buildInjector(parent).getProvider(SchemaVersion.class);
}
@ -119,8 +112,6 @@ public class SchemaUpdater {
} catch (SQLException e) {
throw new OrmException("Cannot upgrade schema", e);
}
updateSystemConfig(db);
}
}
}
@ -137,17 +128,4 @@ public class SchemaUpdater {
return null;
}
}
private void updateSystemConfig(ReviewDb db) throws OrmException {
final SystemConfig sc = db.systemConfig().get(new SystemConfig.Key());
if (sc == null) {
throw new OrmException("No record in system_config table");
}
try {
sc.sitePath = site.site_path.toRealPath().normalize().toString();
} catch (IOException e) {
sc.sitePath = site.site_path.toAbsolutePath().normalize().toString();
}
db.systemConfig().update(Collections.singleton(sc));
}
}

View File

@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
public static final Class<Schema_169> C = Schema_169.class;
public static final Class<Schema_170> C = Schema_170.class;
public static int getBinaryVersion() {
return guessVersion(C);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2018 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.schema;
import com.google.inject.Inject;
import com.google.inject.Provider;
public class Schema_170 extends SchemaVersion {
@Inject
Schema_170(Provider<Schema_169> prior) {
super(prior);
}
}

View File

@ -21,7 +21,6 @@ import com.google.gerrit.reviewdb.server.PatchSetAccess;
import com.google.gerrit.reviewdb.server.PatchSetApprovalAccess;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.reviewdb.server.SchemaVersionAccess;
import com.google.gerrit.reviewdb.server.SystemConfigAccess;
import com.google.gwtorm.server.Access;
import com.google.gwtorm.server.StatementExecutor;
@ -70,11 +69,6 @@ public class DisabledReviewDb implements ReviewDb {
throw new Disabled();
}
@Override
public SystemConfigAccess systemConfig() {
throw new Disabled();
}
@Override
public ChangeAccess changes() {
throw new Disabled();

View File

@ -20,7 +20,6 @@ import com.google.gerrit.lifecycle.LifecycleManager;
import com.google.gerrit.pgm.init.index.elasticsearch.ElasticIndexModuleOnInit;
import com.google.gerrit.pgm.init.index.lucene.LuceneIndexModuleOnInit;
import com.google.gerrit.reviewdb.client.CurrentSchemaVersion;
import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.index.IndexModule;
import com.google.gerrit.server.schema.SchemaCreator;
@ -127,12 +126,6 @@ public class InMemoryDatabase implements SchemaFactory<ReviewDb> {
return this;
}
public SystemConfig getSystemConfig() throws OrmException {
try (ReviewDb c = open()) {
return c.systemConfig().get(new SystemConfig.Key());
}
}
public CurrentSchemaVersion getSchemaVersion() throws OrmException {
try (ReviewDb c = open()) {
return c.schemaVersion().get(new CurrentSchemaVersion.Key());

View File

@ -31,7 +31,6 @@ import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@ -61,7 +60,7 @@ public class SchemaCreatorTest {
}
@Test
public void getCauses_CreateSchema() throws OrmException, SQLException, IOException {
public void getCauses_CreateSchema() throws OrmException, SQLException {
// Initially the schema should be empty.
String[] types = {"TABLE", "VIEW"};
try (JdbcSchema d = (JdbcSchema) db.open();
@ -80,7 +79,6 @@ public class SchemaCreatorTest {
if (sitePath.getName().equals(".")) {
sitePath = sitePath.getParentFile();
}
assertThat(db.getSystemConfig().sitePath).isEqualTo(sitePath.getCanonicalPath());
}
private LabelTypes getLabelTypes() throws Exception {

View File

@ -20,7 +20,6 @@ import com.google.gerrit.extensions.config.FactoryModule;
import com.google.gerrit.lifecycle.LifecycleManager;
import com.google.gerrit.metrics.DisabledMetricMaker;
import com.google.gerrit.metrics.MetricMaker;
import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.GerritPersonIdentProvider;
@ -146,7 +145,5 @@ public class SchemaUpdaterTest {
u.update(new TestUpdateUI());
db.assertSchemaVersion();
final SystemConfig sc = db.getSystemConfig();
assertThat(sc.sitePath).isEqualTo(paths.site_path.toAbsolutePath().toString());
}
}