Skip to content

Commit 4f26165

Browse files
committed
Merge pull request #777 from vladak/finally_take2
rework handling of latest revisions for list of repositories
2 parents 6a2ee9a + 72a1ca5 commit 4f26165

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/org/opensolaris/opengrok/history/HistoryGuru.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,27 +513,47 @@ private void createCache(Repository repository, String sinceRevision) {
513513
}
514514

515515
private void createCacheReal(Collection<Repository> repositories) {
516+
long start = System.currentTimeMillis();
516517
ExecutorService executor = RuntimeEnvironment.getHistoryExecutor();
517-
518-
final CountDownLatch latch = new CountDownLatch(repositories.size());
518+
// Since we know each repository object from the repositories
519+
// collection is unique, we can abuse HashMap to create a list of
520+
// repository,revision tuples with repository as key (as the revision
521+
// string does not have to be unique - surely it is not unique
522+
// for the initial index case).
523+
HashMap<Repository,String> repos2process = new HashMap<>();
524+
525+
// Collect the list of <latestRev,repo> pairs first so that we
526+
// do not have to deal with latch decrementing in the cycle below.
519527
for (final Repository repo : repositories) {
520528
final String latestRev;
521529

522530
try {
523531
latestRev = historyCache.getLatestCachedRevision(repo);
532+
repos2process.put(repo, latestRev);
524533
} catch (HistoryException he) {
525534
log.log(Level.WARNING,
526535
String.format(
527536
"Failed to retrieve latest cached revision for %s",
528537
repo.getDirectoryName()), he);
529-
latch.countDown();
530-
continue;
531538
}
539+
}
540+
541+
log.log(Level.INFO, "Creating historycache for {0} repositories",
542+
repos2process.size());
543+
final CountDownLatch latch = new CountDownLatch(repos2process.size());
544+
for (final Map.Entry<Repository,String> entry : repos2process.entrySet()) {
532545
executor.submit(new Runnable() {
533546
@Override
534547
public void run() {
535-
createCache(repo, latestRev);
536-
latch.countDown();
548+
try {
549+
createCache(entry.getKey(), entry.getValue());
550+
} catch (Exception ex) {
551+
// We want to catch any exception since we are in thread.
552+
log.log(Level.WARNING,
553+
"createCacheReal() got exception" + ex);
554+
} finally {
555+
latch.countDown();
556+
}
537557
}
538558
});
539559
}
@@ -577,6 +597,10 @@ public void run() {
577597
OpenGrokLogger.getLogger().log(Level.WARNING,
578598
"Failed optimizing the history cache database", he);
579599
}
600+
long stop = System.currentTimeMillis();
601+
String time_str = StringUtils.getReadableTime(stop - start);
602+
log.log(Level.INFO, "Done historycache for all repositories (took {0})",
603+
time_str);
580604
}
581605

582606
public void createCache(Collection<String> repositories) {

0 commit comments

Comments
 (0)