Skip to content

Commit a482660

Browse files
committed
add tunable for index check timeout
1 parent af10791 commit a482660

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Configuration.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ public final class Configuration {
302302
private int connectTimeout = -1; // connect timeout in seconds
303303
private int apiTimeout = -1; // API timeout in seconds
304304

305+
private int indexCheckTimeout;
306+
305307
private boolean historyBasedReindex;
306308

307309
/**
@@ -416,6 +418,25 @@ public void setRestfulCommandTimeout(int timeout) throws IllegalArgumentExceptio
416418
this.restfulCommandTimeout = timeout;
417419
}
418420

421+
public int getIndexCheckTimeout() {
422+
return indexCheckTimeout;
423+
}
424+
425+
/**
426+
* Set the index check timeout (performed by the webapp on startup) to a new value.
427+
*
428+
* @see org.opengrok.indexer.index.IndexCheck
429+
* @param timeout the new value
430+
* @throws IllegalArgumentException when the timeout is negative
431+
*/
432+
public void setIndexCheckTimeout(int timeout) throws IllegalArgumentException {
433+
if (timeout < 0) {
434+
throw new IllegalArgumentException(
435+
String.format(NEGATIVE_NUMBER_ERROR, "indexCheckTimeout", timeout));
436+
}
437+
this.indexCheckTimeout = timeout;
438+
}
439+
419440
public int getWebappStartCommandTimeout() {
420441
return webappStartCommandTimeout;
421442
}
@@ -552,6 +573,7 @@ public Configuration() {
552573
setHitsPerPage(25);
553574
setIgnoredNames(new IgnoredNames());
554575
setIncludedNames(new Filter());
576+
setIndexCheckTimeout(60);
555577
setIndexVersionedFilesOnly(false);
556578
setLastEditedDisplayMode(true);
557579
//luceneLocking default is OFF

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ public void setWebappStartCommandTimeout(int timeout) {
325325
syncWriteConfiguration(timeout, Configuration::setWebappStartCommandTimeout);
326326
}
327327

328+
public int getIndexCheckTimeout() {
329+
return syncReadConfiguration(Configuration::getIndexCheckTimeout);
330+
}
331+
332+
public void setIndexCheckTimeout(int timeout) {
333+
syncWriteConfiguration(timeout, Configuration::setIndexCheckTimeout);
334+
}
335+
328336
public int getIndexerCommandTimeout() {
329337
return syncReadConfiguration(Configuration::getIndexerCommandTimeout);
330338
}

opengrok-web/src/main/java/org/opengrok/web/WebappListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private void checkIndex(RuntimeEnvironment env) {
150150
Map<String, Project> projects = env.getProjects();
151151
Path indexRoot = Path.of(env.getDataRootPath(), IndexDatabase.INDEX_DIR);
152152
if (indexRoot.toFile().exists()) {
153-
LOGGER.log(Level.FINE, "Checking indexes for all projects");
153+
LOGGER.log(Level.FINE, "Checking index versions for all projects");
154154
Statistics statistics = new Statistics();
155155
ExecutorService executor = Executors.newFixedThreadPool(env.getRepositoryInvalidationParallelism(),
156156
new OpenGrokThreadFactory("webapp-index-check"));
@@ -169,16 +169,16 @@ private void checkIndex(RuntimeEnvironment env) {
169169
}
170170
executor.shutdown();
171171
try {
172-
// TODO: make the timeout tunable
173-
if (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
174-
LOGGER.log(Level.WARNING, "index check took more than 60 seconds");
172+
if (!executor.awaitTermination(env.getIndexCheckTimeout(), TimeUnit.SECONDS)) {
173+
LOGGER.log(Level.WARNING, "index version check took more than {0} seconds",
174+
env.getIndexCheckTimeout());
175175
executor.shutdownNow();
176176
}
177177
} catch (InterruptedException e) {
178-
LOGGER.log(Level.WARNING, "failed to await termination of index check");
178+
LOGGER.log(Level.WARNING, "failed to await termination of index version check");
179179
executor.shutdownNow();
180180
}
181-
statistics.report(LOGGER, Level.FINE, "Index check for all projects done");
181+
statistics.report(LOGGER, Level.FINE, "Index version check for all projects done");
182182
}
183183
} else {
184184
LOGGER.log(Level.FINE, "Checking index");

0 commit comments

Comments
 (0)