Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions suggester/src/main/java/org/opengrok/suggest/Suggester.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.opengrok.suggest;

import org.apache.commons.lang3.time.DurationFormatUtils;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
Expand Down Expand Up @@ -148,6 +149,7 @@ public void init(final Collection<NamedIndexDir> luceneIndexes) {
}

synchronized (lock) {
Instant start = Instant.now();
logger.log(Level.INFO, "Initializing suggester");

ExecutorService executor = Executors.newWorkStealingPool(rebuildParallelismLevel);
Expand All @@ -156,7 +158,7 @@ public void init(final Collection<NamedIndexDir> luceneIndexes) {
submitInitIfIndexExists(executor, indexDir);
}

shutdownAndAwaitTermination(executor, "Suggester successfully initialized");
shutdownAndAwaitTermination(executor, start, "Suggester successfully initialized");
}
}

Expand Down Expand Up @@ -209,11 +211,13 @@ private boolean indexExists(final Path indexDir) throws IOException {
}
}

private void shutdownAndAwaitTermination(final ExecutorService executorService, final String logMessageOnSuccess) {
private void shutdownAndAwaitTermination(final ExecutorService executorService, Instant start, final String logMessageOnSuccess) {
executorService.shutdown();
try {
executorService.awaitTermination(awaitTerminationTime.toMillis(), TimeUnit.MILLISECONDS);
logger.log(Level.INFO, logMessageOnSuccess);
logger.log(Level.INFO, logMessageOnSuccess + " (took {0})",
DurationFormatUtils.formatDurationWords(Duration.between(start, Instant.now()).toMillis(),
true, true));
} catch (InterruptedException e) {
logger.log(Level.SEVERE, "Interrupted while building suggesters", e);
Thread.currentThread().interrupt();
Expand All @@ -231,6 +235,7 @@ public void rebuild(final Collection<NamedIndexDir> indexDirs) {
}

synchronized (lock) {
Instant start = Instant.now();
logger.log(Level.INFO, "Rebuilding the following suggesters: {0}", indexDirs);

ExecutorService executor = Executors.newWorkStealingPool(rebuildParallelismLevel);
Expand All @@ -244,7 +249,7 @@ public void rebuild(final Collection<NamedIndexDir> indexDirs) {
}
}

shutdownAndAwaitTermination(executor, "Suggesters for " + indexDirs + " were successfully rebuilt");
shutdownAndAwaitTermination(executor, start, "Suggesters for " + indexDirs + " were successfully rebuilt");
}
}

Expand Down