|
34 | 34 | import org.opengrok.indexer.analysis.AnalyzerGuru;
|
35 | 35 | import org.opengrok.indexer.authorization.AuthorizationFramework;
|
36 | 36 | import org.opengrok.indexer.configuration.CommandTimeoutType;
|
| 37 | +import org.opengrok.indexer.configuration.OpenGrokThreadFactory; |
37 | 38 | import org.opengrok.indexer.configuration.Project;
|
38 | 39 | import org.opengrok.indexer.configuration.RuntimeEnvironment;
|
39 | 40 | import org.opengrok.indexer.index.IndexCheck;
|
40 | 41 | import org.opengrok.indexer.index.IndexDatabase;
|
41 | 42 | import org.opengrok.indexer.logger.LoggerFactory;
|
| 43 | +import org.opengrok.indexer.util.Statistics; |
42 | 44 | import org.opengrok.indexer.web.SearchHelper;
|
43 | 45 | import org.opengrok.web.api.ApiTaskManager;
|
44 | 46 | import org.opengrok.web.api.v1.controller.ConfigurationController;
|
|
51 | 53 | import java.time.Duration;
|
52 | 54 | import java.time.Instant;
|
53 | 55 | import java.util.Map;
|
| 56 | +import java.util.concurrent.ExecutorService; |
| 57 | +import java.util.concurrent.Executors; |
| 58 | +import java.util.concurrent.TimeUnit; |
54 | 59 | import java.util.logging.Level;
|
55 | 60 | import java.util.logging.Logger;
|
56 | 61 |
|
@@ -146,18 +151,34 @@ private void checkIndex(RuntimeEnvironment env) {
|
146 | 151 | Path indexRoot = Path.of(env.getDataRootPath(), IndexDatabase.INDEX_DIR);
|
147 | 152 | if (indexRoot.toFile().exists()) {
|
148 | 153 | LOGGER.log(Level.FINE, "Checking indexes for all projects");
|
| 154 | + Statistics statistics = new Statistics(); |
| 155 | + ExecutorService executor = Executors.newFixedThreadPool(env.getRepositoryInvalidationParallelism(), |
| 156 | + new OpenGrokThreadFactory("webapp-index-check")); |
149 | 157 | for (Map.Entry<String, Project> projectEntry : projects.entrySet()) {
|
150 |
| - try { |
151 |
| - IndexCheck.checkDir(Path.of(indexRoot.toString(), projectEntry.getKey()), |
152 |
| - IndexCheck.IndexCheckMode.VERSION, projectEntry.getKey()); |
153 |
| - } catch (Exception e) { |
154 |
| - LOGGER.log(Level.WARNING, |
155 |
| - String.format("Project %s index check failed, marking as not indexed", |
156 |
| - projectEntry.getKey()), e); |
157 |
| - projectEntry.getValue().setIndexed(false); |
| 158 | + executor.submit(() -> { |
| 159 | + try { |
| 160 | + IndexCheck.checkDir(Path.of(indexRoot.toString(), projectEntry.getKey()), |
| 161 | + IndexCheck.IndexCheckMode.VERSION, projectEntry.getKey()); |
| 162 | + } catch (Exception e) { |
| 163 | + LOGGER.log(Level.WARNING, |
| 164 | + String.format("Project %s index check failed, marking as not indexed", |
| 165 | + projectEntry.getKey()), e); |
| 166 | + projectEntry.getValue().setIndexed(false); |
| 167 | + } |
| 168 | + }); |
| 169 | + } |
| 170 | + executor.shutdown(); |
| 171 | + 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"); |
| 175 | + executor.shutdownNow(); |
158 | 176 | }
|
| 177 | + } catch (InterruptedException e) { |
| 178 | + LOGGER.log(Level.WARNING, "failed to await termination of index check"); |
| 179 | + executor.shutdownNow(); |
159 | 180 | }
|
160 |
| - LOGGER.log(Level.FINE, "Index check for all projects done"); |
| 181 | + statistics.report(LOGGER, Level.FINE, "Index check for all projects done"); |
161 | 182 | }
|
162 | 183 | } else {
|
163 | 184 | LOGGER.log(Level.FINE, "Checking index");
|
|
0 commit comments