]> source.dussan.org Git - gitblit.git/commitdiff
Close the Lucene index writer/searcher on a repository rename or delete
authorJames Moger <james.moger@gitblit.com>
Thu, 15 Mar 2012 23:51:16 +0000 (19:51 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 15 Mar 2012 23:51:16 +0000 (19:51 -0400)
src/com/gitblit/GitBlit.java
src/com/gitblit/LuceneExecutor.java

index 3bda06fb2417520d064071a59ac88cbc8c82f8f0..15b69ec0c471ae1b3ee1057d3272fb72941ba1f8 100644 (file)
@@ -871,6 +871,9 @@ public class GitBlit implements ServletContextListener {
                                repository.close();\r
                        }\r
                }\r
+               \r
+               // close any open index writer/searcher in the Lucene executor\r
+               luceneExecutor.close(repositoryName);\r
        }\r
 \r
        /**\r
index 3b8c2b4f29048f87a5f78fb5c1239d6e34662987..0b90b74c9eb13826bbb0ba9216d512f44f145ebc 100644 (file)
@@ -233,6 +233,31 @@ public class LuceneExecutor implements Runnable {
                        logger.error(MessageFormat.format("Lucene indexing failure for {0}", name), t);\r
                }\r
        }\r
+       \r
+       /**\r
+        * Close the writer/searcher objects for a repository.\r
+        * \r
+        * @param repositoryName\r
+        */\r
+       public void close(String repositoryName) {\r
+               try {\r
+                       IndexWriter writer = writers.remove(repositoryName);\r
+                       if (writer != null) {\r
+                               writer.close();\r
+                       }\r
+               } catch (Exception e) {\r
+                       logger.error("Failed to close index writer for " + repositoryName, e);\r
+               }\r
+\r
+               try {\r
+                       IndexSearcher searcher = searchers.remove(repositoryName);\r
+                       if (searcher != null) {\r
+                               searcher.close();\r
+                       }\r
+               } catch (Exception e) {\r
+                       logger.error("Failed to close index searcher for " + repositoryName, e);\r
+               }\r
+       }\r
 \r
        /**\r
         * Close all Lucene indexers.\r