From dad8b4b5dc2ad22556968b878c466a59ba80933a Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 31 Oct 2012 16:32:41 -0400 Subject: [PATCH] Don't even bother running Lucene indexer if we are GCing anything --- src/com/gitblit/GCExecutor.java | 10 ++++++++++ src/com/gitblit/GitBlit.java | 8 ++++++++ src/com/gitblit/LuceneExecutor.java | 5 +++++ 3 files changed, 23 insertions(+) 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)) { -- 2.39.5