From: James Moger Date: Wed, 31 Oct 2012 20:32:41 +0000 (-0400) Subject: Don't even bother running Lucene indexer if we are GCing anything X-Git-Tag: v1.2.0~113 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dad8b4b5dc2ad22556968b878c466a59ba80933a;p=gitblit.git Don't even bother running Lucene indexer if we are GCing anything --- diff --git a/src/com/gitblit/GCExecutor.java b/src/com/gitblit/GCExecutor.java index 243cbb92..312baf5b 100644 --- a/src/com/gitblit/GCExecutor.java +++ b/src/com/gitblit/GCExecutor.java @@ -53,6 +53,8 @@ public class GCExecutor implements Runnable { private final IStoredSettings settings; + private AtomicBoolean running = new AtomicBoolean(false); + private AtomicBoolean forceClose = new AtomicBoolean(false); private final Map gcCache = new ConcurrentHashMap(); @@ -70,6 +72,10 @@ public class GCExecutor implements Runnable { return settings.getBoolean(Keys.git.enableGarbageCollection, false); } + public boolean isRunning() { + return running.get(); + } + public boolean lock(String repositoryName) { return setGCStatus(repositoryName, GCStatus.COLLECTING); } @@ -121,6 +127,8 @@ public class GCExecutor implements Runnable { if (!isReady()) { return; } + + running.set(true); Date now = new Date(); for (String repositoryName : GitBlit.self().getRepositoryList()) { @@ -205,6 +213,8 @@ public class GCExecutor implements Runnable { logger.debug(MessageFormat.format("GCExecutor released GC lock for {0}", repositoryName)); } } + + running.set(false); } private boolean isRepositoryIdle(FileRepository repository) { diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index e9b5e737..8355c034 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -2906,6 +2906,14 @@ public class GitBlit implements ServletContextListener { gcExecutor.close(); } + /** + * + * @return true if we are running the gc executor + */ + public boolean isCollectingGarbage() { + return gcExecutor.isRunning(); + } + /** * Returns true if Gitblit is actively collecting garbage in this repository. * diff --git a/src/com/gitblit/LuceneExecutor.java b/src/com/gitblit/LuceneExecutor.java index dffd4788..0e4baae9 100644 --- a/src/com/gitblit/LuceneExecutor.java +++ b/src/com/gitblit/LuceneExecutor.java @@ -167,6 +167,11 @@ public class LuceneExecutor implements Runnable { String exts = storedSettings.getString(Keys.web.luceneIgnoreExtensions, luceneIgnoreExtensions); excludedExtensions = new TreeSet(StringUtils.getStringsFromValue(exts)); + if (GitBlit.self().isCollectingGarbage()) { + // busy collecting garbage, try again later + return; + } + for (String repositoryName: GitBlit.self().getRepositoryList()) { RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName); if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) {