Skip to content

Commit 23f01ac

Browse files
author
Vladimir Kotal
committed
parallelize history cache creation for individual files
fixes oracle#3542
1 parent b7d48c5 commit 23f01ac

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,10 @@ public void store(History history, Repository repository, String tillRevision) t
466466
LOGGER.log(Level.WARNING, "cannot create history cache directory for ''{0}''", histDataDir);
467467
}
468468

469+
Set<String> regularFiles = map.keySet().stream().
470+
filter(e -> !history.isRenamed(e)).collect(Collectors.toSet());
471+
createDirectoriesForFiles(regularFiles);
472+
469473
/*
470474
* Now traverse the list of files from the hash map built above
471475
* and for each file store its history (saved in the value of the
@@ -475,18 +479,31 @@ public void store(History history, Repository repository, String tillRevision) t
475479
LOGGER.log(Level.FINE, "Storing history for {0} files in repository ''{1}''",
476480
new Object[]{map.entrySet().size(), repository.getDirectoryName()});
477481
final File root = env.getSourceRootFile();
478-
int fileHistoryCount = 0;
479-
for (Map.Entry<String, List<HistoryEntry>> map_entry : map.entrySet()) {
480-
if (handleRenamedFiles && history.isRenamed(map_entry.getKey())) {
481-
continue;
482-
}
483482

484-
doFileHistory(map_entry.getKey(), new History(map_entry.getValue()),
485-
repository, root, false);
486-
fileHistoryCount++;
483+
final CountDownLatch latch = new CountDownLatch(regularFiles.size());
484+
AtomicInteger fileHistoryCount = new AtomicInteger();
485+
for (String file : regularFiles) {
486+
env.getIndexerParallelizer().getHistoryFileExecutor().submit(() -> {
487+
try {
488+
doFileHistory(file, new History(map.get(file)), repository, root, false);
489+
fileHistoryCount.getAndIncrement();
490+
} catch (Exception ex) {
491+
// We want to catch any exception since we are in thread.
492+
LOGGER.log(Level.WARNING, "doFileHistory() got exception ", ex);
493+
} finally {
494+
latch.countDown();
495+
}
496+
});
487497
}
488498

489-
LOGGER.log(Level.FINE, "Stored history for {0} files in repository ''{1}''",
499+
// Wait for the executors to finish.
500+
try {
501+
// Wait for the executors to finish.
502+
latch.await();
503+
} catch (InterruptedException ex) {
504+
LOGGER.log(Level.SEVERE, "latch exception", ex);
505+
}
506+
LOGGER.log(Level.FINE, "Stored history for {0} regular files in repository ''{1}''",
490507
new Object[]{fileHistoryCount, repository.getDirectoryName()});
491508

492509
if (!handleRenamedFiles) {

0 commit comments

Comments
 (0)