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