From e6637cd48c50aa5ebbc01e7826b835b75bd92a87 Mon Sep 17 00:00:00 2001 From: James Moger Date: Thu, 15 Mar 2012 19:51:16 -0400 Subject: [PATCH] Close the Lucene index writer/searcher on a repository rename or delete --- src/com/gitblit/GitBlit.java | 3 +++ src/com/gitblit/LuceneExecutor.java | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 3bda06fb..15b69ec0 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -871,6 +871,9 @@ public class GitBlit implements ServletContextListener { repository.close(); } } + + // close any open index writer/searcher in the Lucene executor + luceneExecutor.close(repositoryName); } /** diff --git a/src/com/gitblit/LuceneExecutor.java b/src/com/gitblit/LuceneExecutor.java index 3b8c2b4f..0b90b74c 100644 --- a/src/com/gitblit/LuceneExecutor.java +++ b/src/com/gitblit/LuceneExecutor.java @@ -233,6 +233,31 @@ public class LuceneExecutor implements Runnable { logger.error(MessageFormat.format("Lucene indexing failure for {0}", name), t); } } + + /** + * Close the writer/searcher objects for a repository. + * + * @param repositoryName + */ + public void close(String repositoryName) { + try { + IndexWriter writer = writers.remove(repositoryName); + if (writer != null) { + writer.close(); + } + } catch (Exception e) { + logger.error("Failed to close index writer for " + repositoryName, e); + } + + try { + IndexSearcher searcher = searchers.remove(repositoryName); + if (searcher != null) { + searcher.close(); + } + } catch (Exception e) { + logger.error("Failed to close index searcher for " + repositoryName, e); + } + } /** * Close all Lucene indexers. -- 2.39.5