Use the new @IndexDir annotation to locate Gerrit index path The introduction of the index dir configuration with I0cf954f0 has broken the healthcheck plugin that was relying on SitePaths.index_dir. Adapt the changes, index health-check, and the associated tests by injecting the index directory as @IndexDir Path indexDir. Change-Id: I20791fb74ffbb85da255d275153e2647ae1bc5b9
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ChangesIndexHealthCheck.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ChangesIndexHealthCheck.java index ab281f9..6fb55ab 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ChangesIndexHealthCheck.java +++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/check/ChangesIndexHealthCheck.java
@@ -21,7 +21,7 @@ import com.google.gerrit.index.IndexType; import com.google.gerrit.metrics.MetricMaker; import com.google.gerrit.server.config.GerritServerConfig; -import com.google.gerrit.server.config.SitePaths; +import com.google.gerrit.server.index.IndexDir; import com.google.gerrit.server.index.OnlineUpgradeListener; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -41,7 +41,7 @@ private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final String lockFilename = "write.lock"; - private final SitePaths sitePaths; + private final Path indexDir; private final boolean isLuceneIndex; private final AtomicReference<Optional<ChangesIndexLockFiles>> changes; @@ -51,11 +51,11 @@ ListeningExecutorService executor, HealthCheckConfig config, MetricMaker metricMaker, - SitePaths sitePaths) { + @IndexDir Path indexDir) { super(executor, config, CHANGES_INDEX, metricMaker); - this.sitePaths = sitePaths; + this.indexDir = indexDir; this.isLuceneIndex = isIndexTypeLucene(cfg); - this.changes = new AtomicReference<>(getChangesIndexLockFiles(sitePaths.index_dir)); + this.changes = new AtomicReference<>(getChangesIndexLockFiles(indexDir)); } @Override @@ -78,8 +78,7 @@ } Optional<ChangesIndexLockFiles> newLockFiles = - Optional.of( - getChangesLockFiles(sitePaths.index_dir, String.format("changes_%04d", newVersion))); + Optional.of(getChangesLockFiles(indexDir, String.format("changes_%04d", newVersion))); if (!changes.compareAndSet(changes.get(), newLockFiles)) { logger.atInfo().log( "New version %d of changes index healthcheck lock files was set already by another"
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ChangesIndexHealthCheckIT.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ChangesIndexHealthCheckIT.java index 2a18dd3..be32203 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ChangesIndexHealthCheckIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/ChangesIndexHealthCheckIT.java
@@ -22,6 +22,8 @@ import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.UseLocalDisk; import com.google.gerrit.acceptance.config.GerritConfig; +import com.google.gerrit.server.index.IndexDir; +import com.google.inject.Inject; import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -38,6 +40,8 @@ @Sandboxed public class ChangesIndexHealthCheckIT extends AbstractHealthCheckIntegrationTest { + @Inject @IndexDir Path indexDir; + @Test @UseLocalDisk @GerritConfig(name = "index.type", value = "lucene") @@ -68,7 +72,7 @@ assertCheckResult(getResponseJson(resp), CHANGES_INDEX, "passed"); - Path openChangesIndexLockPath = getIndexLockFile(sitePaths.index_dir, indexType); + Path openChangesIndexLockPath = getIndexLockFile(indexDir, indexType); assertThat( openChangesIndexLockPath .toFile()