diff --git a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java index fad5c2f2b1..ef2ef91784 100644 --- a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java +++ b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneChangeIndex.java @@ -120,7 +120,6 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener { private final Schema schema; private final SubIndex openIndex; private final SubIndex closedIndex; - private final boolean readOnly; LuceneChangeIndex(@GerritServerConfig Config cfg, SitePaths sitePaths, @@ -128,15 +127,19 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener { @IndexExecutor ListeningScheduledExecutorService executor, FillArgs fillArgs, Schema schema, - boolean readOnly) throws IOException { + String base) throws IOException { this.indexes = indexes; this.sitePaths = sitePaths; this.fillArgs = fillArgs; this.executor = executor; this.schema = schema; - this.readOnly = readOnly; - File dir = new File(sitePaths.index_dir, "changes_" + schema.getVersion()); + File dir; + if (base == null) { + dir = new File(sitePaths.index_dir, "changes_" + schema.getVersion()); + } else { + dir = new File(base); + } openIndex = new SubIndex(new File(dir, CHANGES_OPEN), getIndexWriterConfig(cfg, "changes_open")); closedIndex = new SubIndex(new File(dir, CHANGES_CLOSED), @@ -179,10 +182,6 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener { public ListenableFuture insert(ChangeData cd) throws IOException { Term id = QueryBuilder.idTerm(cd); Document doc = toDocument(cd); - if (readOnly) { - return Futures.immediateFuture(null); - } - if (cd.getChange().getStatus().isOpen()) { return allOf( closedIndex.delete(id), @@ -199,9 +198,6 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener { public ListenableFuture replace(ChangeData cd) throws IOException { Term id = QueryBuilder.idTerm(cd); Document doc = toDocument(cd); - if (readOnly) { - return Futures.immediateFuture(null); - } if (cd.getChange().getStatus().isOpen()) { return allOf( closedIndex.delete(id), @@ -217,9 +213,6 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener { @Override public ListenableFuture delete(ChangeData cd) throws IOException { Term id = QueryBuilder.idTerm(cd); - if (readOnly) { - return Futures.immediateFuture(null); - } return allOf( openIndex.delete(id), closedIndex.delete(id)); diff --git a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneIndexModule.java b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneIndexModule.java index fe3b3c82df..a302f6fa0f 100644 --- a/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneIndexModule.java +++ b/gerrit-lucene/src/main/java/com/google/gerrit/lucene/LuceneIndexModule.java @@ -34,17 +34,17 @@ import java.io.IOException; public class LuceneIndexModule extends LifecycleModule { private final boolean checkVersion; private final int threads; - private final boolean readOnly; + private final String base; public LuceneIndexModule() { - this(true, 0, false); + this(true, 0, null); } public LuceneIndexModule(boolean checkVersion, int threads, - boolean readOnly) { + String base) { this.checkVersion = checkVersion; this.threads = threads; - this.readOnly = readOnly; + this.base = base; } @Override @@ -65,6 +65,6 @@ public class LuceneIndexModule extends LifecycleModule { @IndexExecutor ListeningScheduledExecutorService executor, FillArgs fillArgs) throws IOException { return new LuceneChangeIndex(cfg, sitePaths, indexes, executor, fillArgs, - ChangeSchemas.getLatestRelease(), readOnly); + ChangeSchemas.getLatestRelease(), base); } } diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Reindex.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Reindex.java index 3c5b0ab70d..1070a52200 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Reindex.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Reindex.java @@ -98,8 +98,8 @@ public class Reindex extends SiteProgram { @Option(name = "--threads", usage = "Number of threads to use for indexing") private int threads = Runtime.getRuntime().availableProcessors(); - @Option(name = "--dry-run", usage = "Dry run: don't write anything to index") - private boolean dryRun; + @Option(name = "--output", usage = "Prefix for output; path for local disk index, or prefix for remote index") + private String outputBase; @Option(name = "--verbose", usage = "Output debug information for each change") private boolean verbose; @@ -142,10 +142,10 @@ public class Reindex extends SiteProgram { AbstractModule changeIndexModule; switch (IndexModule.getIndexType(dbInjector)) { case LUCENE: - changeIndexModule = new LuceneIndexModule(false, threads, dryRun); + changeIndexModule = new LuceneIndexModule(false, threads, outputBase); break; case SOLR: - changeIndexModule = new SolrIndexModule(false, threads); + changeIndexModule = new SolrIndexModule(false, threads, outputBase); break; default: changeIndexModule = new NoIndexModule(); @@ -208,9 +208,6 @@ public class Reindex extends SiteProgram { } private void deleteAll() throws IOException { - if (dryRun) { - return; - } ChangeIndex index = sysInjector.getInstance(ChangeIndex.class); index.deleteAll(); } @@ -470,9 +467,6 @@ public class Reindex extends SiteProgram { private void writeVersion() throws IOException, ConfigInvalidException { - if (dryRun) { - return; - } ChangeIndex index = sysInjector.getInstance(ChangeIndex.class); index.finishIndex(); } diff --git a/gerrit-solr/src/main/java/com/google/gerrit/solr/SolrChangeIndex.java b/gerrit-solr/src/main/java/com/google/gerrit/solr/SolrChangeIndex.java index cdb5a9c294..b338dffbe3 100644 --- a/gerrit-solr/src/main/java/com/google/gerrit/solr/SolrChangeIndex.java +++ b/gerrit-solr/src/main/java/com/google/gerrit/solr/SolrChangeIndex.java @@ -43,7 +43,6 @@ import com.google.gerrit.server.query.change.ChangeData; import com.google.gerrit.server.query.change.ChangeDataSource; import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.ResultSet; -import com.google.inject.Singleton; import org.apache.lucene.search.Query; import org.apache.solr.client.solrj.SolrQuery; @@ -67,7 +66,6 @@ import java.util.Map; import java.util.Set; /** Secondary index implementation using a remote Solr instance. */ -@Singleton class SolrChangeIndex implements ChangeIndex, LifecycleListener { public static final String CHANGES_OPEN = "changes_open"; public static final String CHANGES_CLOSED = "changes_closed"; @@ -85,7 +83,8 @@ class SolrChangeIndex implements ChangeIndex, LifecycleListener { FillArgs fillArgs, SitePaths sitePaths, IndexCollection indexes, - Schema schema) throws IOException { + Schema schema, + String base) throws IOException { this.fillArgs = fillArgs; this.sitePaths = sitePaths; this.indexes = indexes; @@ -96,11 +95,12 @@ class SolrChangeIndex implements ChangeIndex, LifecycleListener { throw new IllegalStateException("index.solr.url must be supplied"); } + base = Strings.nullToEmpty(base); openIndex = new CloudSolrServer(url); - openIndex.setDefaultCollection(CHANGES_OPEN); + openIndex.setDefaultCollection(base + CHANGES_OPEN); closedIndex = new CloudSolrServer(url); - closedIndex.setDefaultCollection(CHANGES_CLOSED); + closedIndex.setDefaultCollection(base + CHANGES_CLOSED); } @Override diff --git a/gerrit-solr/src/main/java/com/google/gerrit/solr/SolrIndexModule.java b/gerrit-solr/src/main/java/com/google/gerrit/solr/SolrIndexModule.java index d05fd5b059..4b892a8b43 100644 --- a/gerrit-solr/src/main/java/com/google/gerrit/solr/SolrIndexModule.java +++ b/gerrit-solr/src/main/java/com/google/gerrit/solr/SolrIndexModule.java @@ -32,14 +32,16 @@ import java.io.IOException; public class SolrIndexModule extends LifecycleModule { private final boolean checkVersion; private final int threads; + private final String base; public SolrIndexModule() { - this(true, 0); + this(true, 0, null); } - public SolrIndexModule(boolean checkVersion, int threads) { + public SolrIndexModule(boolean checkVersion, int threads, String base) { this.checkVersion = checkVersion; this.threads = threads; + this.base = base; } @Override @@ -59,6 +61,6 @@ public class SolrIndexModule extends LifecycleModule { IndexCollection indexes, FillArgs fillArgs) throws IOException { return new SolrChangeIndex(cfg, fillArgs, sitePaths, indexes, - ChangeSchemas.getLatestRelease()); + ChangeSchemas.getLatestRelease(), base); } }