Replace Reindex --dry-run with --output

The line of what was a "dry run" was a bit arbitrary, doing all the
Gerrit processing (including potential side effects like writing to
persistent caches) but not all the index-specific processing, which
could still be useful for evaluation or debugging purposes. Instead,
provide an output base so administrators can test the indexing
behavior without operating on production index data.

For Lucene, this flag is interpreted as a path to the index
directory; for Solr, it is a prefix added to the collection names.

Change-Id: Ic4808d1e3467a780a818ac7d1c89de13610da630
This commit is contained in:
Dave Borowitz
2013-06-28 12:40:59 -06:00
parent 1d2a998298
commit 97a01dbb05
5 changed files with 26 additions and 37 deletions

View File

@@ -120,7 +120,6 @@ public class LuceneChangeIndex implements ChangeIndex, LifecycleListener {
private final Schema<ChangeData> 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<ChangeData> 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<Void> 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<Void> 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<Void> delete(ChangeData cd) throws IOException {
Term id = QueryBuilder.idTerm(cd);
if (readOnly) {
return Futures.immediateFuture(null);
}
return allOf(
openIndex.delete(id),
closedIndex.delete(id));

View File

@@ -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);
}
}

View File

@@ -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();
}

View File

@@ -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<ChangeData> schema) throws IOException {
Schema<ChangeData> 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

View File

@@ -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);
}
}