Encapsulate per-index utilities in a pair of generic classes
This collects the schema definitions (superseding the static ChangeSchemas utilities) into a class called SchemaDefinitions. Additionally, the backend-specific implementation classes (index collection, site indexer, etc.) are collected into a class called IndexDefinition. (We use the longer "definition" rather than "type" because the latter is already used to describe the backend implementation.) The total set of supported index definitions is bound in IndexModule, which provides them as a Collection<IndexDefinition<?, ?, ?>>. Alternatively, callers that can't get the injected implementations (notably InitIndex) can access the fully-static list of schema definitions. Abstract out LuceneChangeIndex.Factory into a generic IndexFactory interface. At this point the only things that a particular backend implementation needs to implement are: - The IndexFactory that constructs a per-implementation index implementation given a schema definition. Eventually this will expand to one IndexFactory implementation per index definition. - A listener that populates the IndexCollection for each supported index definition. This change uses the Collection<IndexDefinition> in most places where it is possible, with a few exceptions that will require a bit more work: - LuceneVersionManager, which is used directly by some SSH commands to manipulate the index. - Reindex, which needs a different scheme for passing flags. Change-Id: Ia5724cfecaae6335e7c0df24cd41c87b2bb5e36a
This commit is contained in:
@@ -17,21 +17,31 @@ package com.google.gerrit.server.index;
|
||||
import static com.google.gerrit.server.git.QueueProvider.QueueType.BATCH;
|
||||
import static com.google.gerrit.server.git.QueueProvider.QueueType.INTERACTIVE;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.git.WorkQueue;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexCollection;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexDefintion;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexer;
|
||||
import com.google.gerrit.server.index.change.ChangeSchemaDefinitions;
|
||||
import com.google.gerrit.server.index.change.IndexRewriter;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Module for non-indexer-specific secondary index setup.
|
||||
* <p>
|
||||
@@ -43,6 +53,10 @@ public class IndexModule extends LifecycleModule {
|
||||
LUCENE
|
||||
}
|
||||
|
||||
public static final ImmutableCollection<SchemaDefinitions<?>> ALL_SCHEMA_DEFS =
|
||||
ImmutableList.<SchemaDefinitions<?>> of(
|
||||
ChangeSchemaDefinitions.INSTANCE);
|
||||
|
||||
/** Type of secondary index. */
|
||||
public static IndexType getIndexType(Injector injector) {
|
||||
Config cfg = injector.getInstance(
|
||||
@@ -74,6 +88,33 @@ public class IndexModule extends LifecycleModule {
|
||||
factory(ChangeIndexer.Factory.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
Collection<IndexDefinition<?, ?, ?>> getIndexDefinitions(
|
||||
ChangeIndexDefintion changes) {
|
||||
Collection<IndexDefinition<?, ?, ?>> result =
|
||||
ImmutableList.<IndexDefinition<?, ?, ?>> of(changes);
|
||||
Set<String> expected = FluentIterable.from(ALL_SCHEMA_DEFS)
|
||||
.transform(new Function<SchemaDefinitions<?>, String>() {
|
||||
@Override
|
||||
public String apply(SchemaDefinitions<?> in) {
|
||||
return in.getName();
|
||||
}
|
||||
}).toSet();
|
||||
Set<String> actual = FluentIterable.from(result)
|
||||
.transform(new Function<IndexDefinition<?, ?, ?>, String>() {
|
||||
@Override
|
||||
public String apply(IndexDefinition<?, ?, ?> in) {
|
||||
return in.getName();
|
||||
}
|
||||
}).toSet();
|
||||
if (!expected.equals(actual)) {
|
||||
throw new ProvisionException(
|
||||
"need index definitions for all schemas: "
|
||||
+ expected + " != " + actual);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ChangeIndexer getChangeIndexer(
|
||||
|
||||
Reference in New Issue
Block a user