Stop creating the entire SchemaVersion chain at runtime

Running Gerrit servers build every Schema_NNN instance at server
startup due to the Guice binding for @Current SchemaVersion implicitly
linking to everything through the constructors and the Guice injector
running in mode PRODUCTION, where all dependencies are resolved
immediately at startup.

Instead get the binary version off the C constant, which does not
require loading all classes.  Use a new injector with mode DEVELOPMENT
to support lazy loading of older versions only as necessary.

Change-Id: I9c62f2603f61bdd58a800b1d03b10c28a0c78773
This commit is contained in:
Shawn Pearce
2015-01-05 13:11:52 -08:00
parent c0e668913e
commit c4377cd3d1
9 changed files with 59 additions and 73 deletions

View File

@@ -74,7 +74,6 @@ public class SchemaUpdaterTest {
protected void configure() {
bind(new TypeLiteral<SchemaFactory<ReviewDb>>() {}).toInstance(db);
bind(SitePaths.class).toInstance(paths);
install(new SchemaVersion.Module());
Config cfg = new Config();
cfg.setString("user", null, "name", "Gerrit Code Review");

View File

@@ -67,7 +67,6 @@ public class InMemoryDatabase implements SchemaFactory<ReviewDb> {
}
}
private final SchemaVersion schemaVersion;
private final SchemaCreator schemaCreator;
private Connection openHandle;
@@ -75,9 +74,7 @@ public class InMemoryDatabase implements SchemaFactory<ReviewDb> {
private boolean created;
@Inject
InMemoryDatabase(SchemaVersion schemaVersion,
SchemaCreator schemaCreator) throws OrmException {
this.schemaVersion = schemaVersion;
InMemoryDatabase(SchemaCreator schemaCreator) throws OrmException {
this.schemaCreator = schemaCreator;
try {
@@ -161,6 +158,6 @@ public class InMemoryDatabase implements SchemaFactory<ReviewDb> {
public void assertSchemaVersion() throws OrmException {
final CurrentSchemaVersion act = getSchemaVersion();
assertEquals(schemaVersion.getVersionNbr(), act.versionNbr);
assertEquals(SchemaVersion.getBinaryVersion(), act.versionNbr);
}
}

View File

@@ -48,10 +48,8 @@ import com.google.gerrit.server.index.ChangeSchemas;
import com.google.gerrit.server.index.IndexModule.IndexType;
import com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier;
import com.google.gerrit.server.mail.SmtpEmailSender;
import com.google.gerrit.server.schema.Current;
import com.google.gerrit.server.schema.DataSourceType;
import com.google.gerrit.server.schema.SchemaCreator;
import com.google.gerrit.server.schema.SchemaVersion;
import com.google.gerrit.server.securestore.DefaultSecureStore;
import com.google.gerrit.server.securestore.SecureStore;
import com.google.gerrit.server.ssh.NoSshKeyCache;
@@ -127,8 +125,6 @@ public class InMemoryModule extends FactoryModule {
bindScope(RequestScoped.class, PerThreadRequestScope.REQUEST);
install(new SchemaVersion.Module());
bind(File.class).annotatedWith(SitePath.class).toInstance(new File("."));
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
bind(SocketAddress.class).annotatedWith(RemotePeer.class).toInstance(
@@ -197,9 +193,9 @@ public class InMemoryModule extends FactoryModule {
@Provides
@Singleton
InMemoryDatabase getInMemoryDatabase(@Current SchemaVersion schemaVersion,
SchemaCreator schemaCreator) throws OrmException {
return new InMemoryDatabase(schemaVersion, schemaCreator);
InMemoryDatabase getInMemoryDatabase(SchemaCreator schemaCreator)
throws OrmException {
return new InMemoryDatabase(schemaCreator);
}
private Module luceneIndexModule() {