| | |
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.LuceneUtils;
|
| | | import com.gitblit.utils.LuceneUtils.IndexResult;
|
| | |
|
| | | /**
|
| | | * The Lucene executor handles indexing repositories synchronously and
|
| | |
| | |
|
| | | public LuceneExecutor(IStoredSettings settings) {
|
| | | this.settings = settings;
|
| | | this.isLuceneEnabled = settings.getBoolean("lucene.enableLucene", false);
|
| | | this.isPollingMode = settings.getBoolean("lucene.pollingMode", false); |
| | | this.isLuceneEnabled = settings.getBoolean(Keys.lucene.enable, false);
|
| | | this.isPollingMode = settings.getBoolean(Keys.lucene.pollingMode, false);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | if (!isLuceneEnabled) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | if (firstRun.get() || isPollingMode) {
|
| | | // update all indexes on first run or if polling mode |
| | | // update all indexes on first run or if polling mode
|
| | | firstRun.set(false);
|
| | | queue.addAll(GitBlit.self().getRepositoryList());
|
| | | }
|
| | |
| | | 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();
|
| | | boolean success = LuceneUtils.reindex(repository);
|
| | | long duration = System.currentTimeMillis() - start;
|
| | | if (success) {
|
| | | String msg = "Built {0} Lucene index in {1} msecs";
|
| | | logger.info(MessageFormat.format(msg, repositoryName, duration));
|
| | | 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 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();
|
| | | boolean success = LuceneUtils.updateIndex(repository);
|
| | | long duration = System.currentTimeMillis() - start;
|
| | | if (success) {
|
| | | String msg = "Updated {0} Lucene index in {1} msecs";
|
| | | logger.info(MessageFormat.format(msg, repositoryName, duration));
|
| | | 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 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);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Close all Lucene indexers.
|
| | | * |
| | | */
|
| | | public void close() {
|
| | | LuceneUtils.close();
|
| | | }
|
| | | }
|