Index groups that are created during init

During the initialization of a new site some default groups are
automatically created ('Administrators' and 'Non-Interactive Users').
These new groups must be added to the index so that they become
queryable. For this init must have the group index available so that
it can write the new groups to it. Reading from the index during init
is not needed and not supported.

Alternatively we could require users to run the Reindex program after
the initial site initialization, but likely many people would forget
about it and then wonder why the default groups are not available from
the group index.

Change-Id: I274b142a6efde224bba68f8b5c459736d7a1f985
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-01-05 09:36:37 +01:00
parent c3b5956d89
commit a4c095f171
17 changed files with 343 additions and 62 deletions

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.index;
import com.google.common.collect.ImmutableSortedMap;
import com.google.inject.Provider;
/**
* Definition of an index over a Gerrit data type.
@@ -32,13 +33,13 @@ public abstract class IndexDefinition<K, V, I extends Index<K, V>> {
private final SchemaDefinitions<V> schemaDefs;
private final IndexCollection<K, V, I> indexCollection;
private final IndexFactory<K, V, I> indexFactory;
private final SiteIndexer<K, V, I> siteIndexer;
private final Provider<SiteIndexer<K, V, I>> siteIndexer;
protected IndexDefinition(
SchemaDefinitions<V> schemaDefs,
IndexCollection<K, V, I> indexCollection,
IndexFactory<K, V, I> indexFactory,
SiteIndexer<K, V, I> siteIndexer) {
Provider<SiteIndexer<K, V, I>> siteIndexer) {
this.schemaDefs = schemaDefs;
this.indexCollection = indexCollection;
this.indexFactory = indexFactory;
@@ -66,6 +67,6 @@ public abstract class IndexDefinition<K, V, I extends Index<K, V>> {
}
public final SiteIndexer<K, V, I> getSiteIndexer() {
return siteIndexer;
return siteIndexer.get();
}
}

View File

@@ -33,7 +33,7 @@ import java.util.Set;
@Singleton
public class SingleVersionModule extends LifecycleModule {
static final String SINGLE_VERSIONS = "IndexModule/SingleVersions";
public static final String SINGLE_VERSIONS = "IndexModule/SingleVersions";
private final Map<String, Integer> singleVersions;
@@ -50,7 +50,7 @@ public class SingleVersionModule extends LifecycleModule {
}
@Singleton
static class SingleVersionListener implements LifecycleListener {
public static class SingleVersionListener implements LifecycleListener {
private final Set<String> disabled;
private final Collection<IndexDefinition<?, ?, ?>> defs;
private final Map<String, Integer> singleVersions;

View File

@@ -18,6 +18,7 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.index.IndexDefinition;
import com.google.inject.Inject;
import com.google.inject.util.Providers;
public class AccountIndexDefinition
extends IndexDefinition<Account.Id, AccountState, AccountIndex> {
@@ -28,6 +29,6 @@ public class AccountIndexDefinition
AccountIndex.Factory indexFactory,
AllAccountsIndexer allAccountsIndexer) {
super(AccountSchemaDefinitions.INSTANCE, indexCollection, indexFactory,
allAccountsIndexer);
Providers.of(allAccountsIndexer));
}
}

View File

@@ -18,6 +18,7 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.IndexDefinition;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.inject.Inject;
import com.google.inject.util.Providers;
public class ChangeIndexDefinition
extends IndexDefinition<Change.Id, ChangeData, ChangeIndex> {
@@ -28,6 +29,6 @@ public class ChangeIndexDefinition
ChangeIndex.Factory indexFactory,
AllChangesIndexer allChangesIndexer) {
super(ChangeSchemaDefinitions.INSTANCE, indexCollection, indexFactory,
allChangesIndexer);
Providers.of(allChangesIndexer));
}
}

View File

@@ -14,9 +14,11 @@
package com.google.gerrit.server.index.group;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.server.index.IndexDefinition;
import com.google.inject.Inject;
import com.google.inject.util.Providers;
public class GroupIndexDefinition
extends IndexDefinition<AccountGroup.UUID, AccountGroup, GroupIndex> {
@@ -24,8 +26,8 @@ public class GroupIndexDefinition
@Inject
GroupIndexDefinition(GroupIndexCollection indexCollection,
GroupIndex.Factory indexFactory,
AllGroupsIndexer allGroupsIndexer) {
@Nullable AllGroupsIndexer allGroupsIndexer) {
super(GroupSchemaDefinitions.INSTANCE, indexCollection, indexFactory,
allGroupsIndexer);
Providers.of(allGroupsIndexer));
}
}

View File

@@ -24,6 +24,7 @@ import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.account.GroupUUID;
import com.google.gerrit.server.config.SitePath;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.index.group.GroupIndexCollection;
import com.google.gwtorm.jdbc.JdbcExecutor;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.server.OrmException;
@@ -46,6 +47,7 @@ public class SchemaCreator {
private final AllUsersCreator allUsersCreator;
private final PersonIdent serverUser;
private final DataSourceType dataSourceType;
private final GroupIndexCollection indexCollection;
private AccountGroup admin;
private AccountGroup batch;
@@ -55,20 +57,23 @@ public class SchemaCreator {
AllProjectsCreator ap,
AllUsersCreator auc,
@GerritPersonIdent PersonIdent au,
DataSourceType dst) {
this(site.site_path, ap, auc, au, dst);
DataSourceType dst,
GroupIndexCollection ic) {
this(site.site_path, ap, auc, au, dst, ic);
}
public SchemaCreator(@SitePath Path site,
AllProjectsCreator ap,
AllUsersCreator auc,
@GerritPersonIdent PersonIdent au,
DataSourceType dst) {
DataSourceType dst,
GroupIndexCollection ic) {
site_path = site;
allProjectsCreator = ap;
allUsersCreator = auc;
serverUser = au;
dataSourceType = dst;
indexCollection = ic;
}
public void create(final ReviewDb db) throws OrmException, IOException,
@@ -82,6 +87,7 @@ public class SchemaCreator {
sVer.versionNbr = SchemaVersion.getBinaryVersion();
db.schemaVersion().insert(Collections.singleton(sVer));
createDefaultGroups(db);
initSystemConfig(db);
allProjectsCreator
.setAdministrators(GroupReference.forGroup(admin))
@@ -93,6 +99,30 @@ public class SchemaCreator {
dataSourceType.getIndexScript().run(db);
}
private void createDefaultGroups(ReviewDb db)
throws OrmException, IOException {
admin = newGroup(db, "Administrators", null);
admin.setDescription("Gerrit Site Administrators");
db.accountGroups().insert(Collections.singleton(admin));
db.accountGroupNames()
.insert(Collections.singleton(new AccountGroupName(admin)));
index(admin);
batch = newGroup(db, "Non-Interactive Users", null);
batch.setDescription("Users who perform batch actions on Gerrit");
batch.setOwnerGroupUUID(admin.getGroupUUID());
db.accountGroups().insert(Collections.singleton(batch));
db.accountGroupNames()
.insert(Collections.singleton(new AccountGroupName(batch)));
index(batch);
}
private void index(AccountGroup group) throws IOException {
if (indexCollection.getSearchIndex() != null) {
indexCollection.getSearchIndex().replace(group);
}
}
private AccountGroup newGroup(ReviewDb c, String name, AccountGroup.UUID uuid)
throws OrmException {
if (uuid == null) {
@@ -104,27 +134,14 @@ public class SchemaCreator {
uuid);
}
private SystemConfig initSystemConfig(final ReviewDb c) throws OrmException {
admin = newGroup(c, "Administrators", null);
admin.setDescription("Gerrit Site Administrators");
c.accountGroups().insert(Collections.singleton(admin));
c.accountGroupNames().insert(
Collections.singleton(new AccountGroupName(admin)));
batch = newGroup(c, "Non-Interactive Users", null);
batch.setDescription("Users who perform batch actions on Gerrit");
batch.setOwnerGroupUUID(admin.getGroupUUID());
c.accountGroups().insert(Collections.singleton(batch));
c.accountGroupNames().insert(
Collections.singleton(new AccountGroupName(batch)));
final SystemConfig s = SystemConfig.create();
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();
}
c.systemConfig().insert(Collections.singleton(s));
db.systemConfig().insert(Collections.singleton(s));
return s;
}
}