Merge "Initialize Lucene index automatically at init"
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.pgm.init;
|
package com.google.gerrit.pgm.init;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.lucene.LuceneChangeIndex;
|
import com.google.gerrit.lucene.LuceneChangeIndex;
|
||||||
import com.google.gerrit.pgm.init.api.ConsoleUI;
|
import com.google.gerrit.pgm.init.api.ConsoleUI;
|
||||||
import com.google.gerrit.pgm.init.api.InitFlags;
|
import com.google.gerrit.pgm.init.api.InitFlags;
|
||||||
@@ -26,6 +27,9 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
/** Initialize the {@code index} configuration section. */
|
/** Initialize the {@code index} configuration section. */
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -34,6 +38,7 @@ class InitIndex implements InitStep {
|
|||||||
private final Section index;
|
private final Section index;
|
||||||
private final SitePaths site;
|
private final SitePaths site;
|
||||||
private final InitFlags initFlags;
|
private final InitFlags initFlags;
|
||||||
|
private final Section gerrit;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
InitIndex(ConsoleUI ui,
|
InitIndex(ConsoleUI ui,
|
||||||
@@ -42,6 +47,7 @@ class InitIndex implements InitStep {
|
|||||||
InitFlags initFlags) {
|
InitFlags initFlags) {
|
||||||
this.ui = ui;
|
this.ui = ui;
|
||||||
this.index = sections.get("index", null);
|
this.index = sections.get("index", null);
|
||||||
|
this.gerrit = sections.get("gerrit", null);
|
||||||
this.site = site;
|
this.site = site;
|
||||||
this.initFlags = initFlags;
|
this.initFlags = initFlags;
|
||||||
}
|
}
|
||||||
@@ -51,9 +57,9 @@ class InitIndex implements InitStep {
|
|||||||
ui.header("Index");
|
ui.header("Index");
|
||||||
|
|
||||||
IndexType type = index.select("Type", "type", IndexType.LUCENE);
|
IndexType type = index.select("Type", "type", IndexType.LUCENE);
|
||||||
if (site.isNew && type == IndexType.LUCENE) {
|
|
||||||
LuceneChangeIndex.setReady(
|
LuceneChangeIndex.setReady(
|
||||||
site, ChangeSchemas.getLatest().getVersion(), true);
|
site, ChangeSchemas.getLatest().getVersion(), true);
|
||||||
|
if ((site.isNew || isEmptySite()) && type == IndexType.LUCENE) {
|
||||||
} else {
|
} else {
|
||||||
final String message = String.format(
|
final String message = String.format(
|
||||||
"\nThe index must be %sbuilt before starting Gerrit:\n"
|
"\nThe index must be %sbuilt before starting Gerrit:\n"
|
||||||
@@ -64,6 +70,15 @@ class InitIndex implements InitStep {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isEmptySite() {
|
||||||
|
try (DirectoryStream<Path> files =
|
||||||
|
Files.newDirectoryStream(site.resolve(gerrit.get("basePath")))) {
|
||||||
|
return Iterables.isEmpty(files);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postRun() throws Exception {
|
public void postRun() throws Exception {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user