| | |
| | | Set<String> processed = new HashSet<String>();
|
| | | if (!queue.isEmpty()) {
|
| | | // update the repository Lucene index
|
| | | String repositoryName = null;
|
| | | while ((repositoryName = queue.poll()) != null) {
|
| | | if (processed.contains(repositoryName)) {
|
| | | String name = null;
|
| | | while ((name = queue.poll()) != null) {
|
| | | if (processed.contains(name)) {
|
| | | // skipping multi-queued repository
|
| | | continue;
|
| | | }
|
| | | try {
|
| | | Repository repository = GitBlit.self().getRepository(repositoryName);
|
| | | Repository repository = GitBlit.self().getRepository(name);
|
| | | if (repository == null) {
|
| | | logger.warn(MessageFormat.format(
|
| | | "Lucene executor could not find repository {0}. Skipping.",
|
| | | repositoryName));
|
| | | name));
|
| | | continue;
|
| | | }
|
| | | index(repositoryName, repository);
|
| | | index(name, repository);
|
| | | repository.close();
|
| | | processed.add(repositoryName);
|
| | | System.gc();
|
| | | processed.add(name);
|
| | | } catch (Throwable e) {
|
| | | logger.error(MessageFormat.format("Failed to update {0} Lucene index",
|
| | | repositoryName), e);
|
| | | name), e);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | * Synchronously indexes a repository. This may build a complete index of a
|
| | | * repository or it may update an existing index.
|
| | | *
|
| | | * @param repositoryName
|
| | | * @param name
|
| | | * the name of the repository
|
| | | * @param repository
|
| | | * the repository object
|
| | | */
|
| | | public void index(String repositoryName, Repository repository) {
|
| | | public void index(String name, Repository repository) {
|
| | | try {
|
| | | if (JGitUtils.hasCommits(repository)) {
|
| | | if (LuceneUtils.shouldReindex(repository)) {
|
| | | // (re)build the entire index
|
| | | long start = System.currentTimeMillis();
|
| | | IndexResult result = LuceneUtils.reindex(repository);
|
| | | long duration = System.currentTimeMillis() - start;
|
| | | IndexResult result = LuceneUtils.reindex(name, repository);
|
| | | float duration = (System.currentTimeMillis() - start)/1000f;
|
| | | if (result.success) {
|
| | | if (result.commitCount > 0) {
|
| | | String msg = "Built {0} Lucene index from {1} commits in {2} msecs";
|
| | | logger.info(MessageFormat.format(msg, repositoryName,
|
| | | result.commitCount, duration));
|
| | | String msg = "Built {0} Lucene index from {1} commits and {2} files across {3} branches in {4} secs";
|
| | | logger.info(MessageFormat.format(msg, name,
|
| | | result.commitCount, result.blobCount, result.branchCount, duration));
|
| | | }
|
| | | } else {
|
| | | String msg = "Could not build {0} Lucene index!";
|
| | | logger.error(MessageFormat.format(msg, repositoryName));
|
| | | logger.error(MessageFormat.format(msg, name));
|
| | | }
|
| | | } else {
|
| | | // update the index with latest commits
|
| | | long start = System.currentTimeMillis();
|
| | | IndexResult result = LuceneUtils.updateIndex(repository);
|
| | | long duration = System.currentTimeMillis() - start;
|
| | | IndexResult result = LuceneUtils.updateIndex(name, repository);
|
| | | float duration = (System.currentTimeMillis() - start)/1000f;
|
| | | if (result.success) {
|
| | | if (result.commitCount > 0) {
|
| | | String msg = "Updated {0} Lucene index with {1} commits in {2} msecs";
|
| | | logger.info(MessageFormat.format(msg, repositoryName,
|
| | | result.commitCount, duration));
|
| | | String msg = "Updated {0} Lucene index with {1} commits and {2} files across {3} branches in {4} secs";
|
| | | logger.info(MessageFormat.format(msg, name,
|
| | | result.commitCount, result.blobCount, result.branchCount, duration));
|
| | | }
|
| | | } else {
|
| | | String msg = "Could not update {0} Lucene index!";
|
| | | logger.error(MessageFormat.format(msg, repositoryName));
|
| | | logger.error(MessageFormat.format(msg, name));
|
| | | }
|
| | | }
|
| | | } else {
|
| | | logger.info(MessageFormat.format("Skipped Lucene index of empty repository {0}",
|
| | | repositoryName));
|
| | | name));
|
| | | }
|
| | | } catch (Throwable t) {
|
| | | logger.error(MessageFormat.format("Lucene indexing failure for {0}", repositoryName), t);
|
| | | logger.error(MessageFormat.format("Lucene indexing failure for {0}", name), t);
|
| | | }
|
| | | }
|
| | |
|