]> source.dussan.org Git - gitblit.git/commitdiff
Don't even bother running Lucene indexer if we are GCing anything
authorJames Moger <james.moger@gitblit.com>
Wed, 31 Oct 2012 20:32:41 +0000 (16:32 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 31 Oct 2012 20:32:41 +0000 (16:32 -0400)
src/com/gitblit/GCExecutor.java
src/com/gitblit/GitBlit.java
src/com/gitblit/LuceneExecutor.java

index 243cbb92db14c2761b59527e10b1a0ae9232176b..312baf5bd6316450d368290754d1be90dd03271c 100644 (file)
@@ -53,6 +53,8 @@ public class GCExecutor implements Runnable {
 \r
        private final IStoredSettings settings;\r
        \r
+       private AtomicBoolean running = new AtomicBoolean(false);\r
+       \r
        private AtomicBoolean forceClose = new AtomicBoolean(false);\r
        \r
        private final Map<String, GCStatus> gcCache = new ConcurrentHashMap<String, GCStatus>();\r
@@ -70,6 +72,10 @@ public class GCExecutor implements Runnable {
                return settings.getBoolean(Keys.git.enableGarbageCollection, false);\r
        }\r
        \r
+       public boolean isRunning() {\r
+               return running.get();\r
+       }\r
+       \r
        public boolean lock(String repositoryName) {\r
                return setGCStatus(repositoryName, GCStatus.COLLECTING);\r
        }\r
@@ -121,6 +127,8 @@ public class GCExecutor implements Runnable {
                if (!isReady()) {\r
                        return;\r
                }\r
+               \r
+               running.set(true);              \r
                Date now = new Date();\r
 \r
                for (String repositoryName : GitBlit.self().getRepositoryList()) {\r
@@ -205,6 +213,8 @@ public class GCExecutor implements Runnable {
                                logger.debug(MessageFormat.format("GCExecutor released GC lock for {0}", repositoryName));\r
                        }\r
                }\r
+               \r
+               running.set(false);\r
        }\r
        \r
        private boolean isRepositoryIdle(FileRepository repository) {\r
index e9b5e7373b9ad5f9bbd5ba7634c05de1c2130ab2..8355c034e95623e10dde4016391f8bf882ed64fa 100644 (file)
@@ -2906,6 +2906,14 @@ public class GitBlit implements ServletContextListener {
                gcExecutor.close();\r
        }\r
        \r
+       /**\r
+        * \r
+        * @return true if we are running the gc executor\r
+        */\r
+       public boolean isCollectingGarbage() {\r
+               return gcExecutor.isRunning();\r
+       }\r
+       \r
        /**\r
         * Returns true if Gitblit is actively collecting garbage in this repository.\r
         * \r
index dffd4788bcd536cc20270085ed662e537db69b6f..0e4baae97250e45e49595ac357d430b8d2433353 100644 (file)
@@ -167,6 +167,11 @@ public class LuceneExecutor implements Runnable {
                String exts = storedSettings.getString(Keys.web.luceneIgnoreExtensions, luceneIgnoreExtensions);\r
                excludedExtensions = new TreeSet<String>(StringUtils.getStringsFromValue(exts));\r
 \r
+               if (GitBlit.self().isCollectingGarbage()) {\r
+                       // busy collecting garbage, try again later\r
+                       return;\r
+               }\r
+               \r
                for (String repositoryName: GitBlit.self().getRepositoryList()) {\r
                        RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
                        if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) {\r