dovecot-2.2: fts-lucene: Automatically close index after 2 minut...

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 21 12:49:53 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/9cdf42df4c4b
changeset: 17740:9cdf42df4c4b
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 21 14:48:41 2014 +0200
description:
fts-lucene: Automatically close index after 2 minutes of idling.

diffstat:

 src/plugins/fts-lucene/lucene-wrapper.cc |  16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diffs (69 lines):

diff -r 5f8cff646417 -r 9cdf42df4c4b src/plugins/fts-lucene/lucene-wrapper.cc
--- a/src/plugins/fts-lucene/lucene-wrapper.cc	Thu Aug 21 14:46:47 2014 +0200
+++ b/src/plugins/fts-lucene/lucene-wrapper.cc	Thu Aug 21 14:48:41 2014 +0200
@@ -6,6 +6,7 @@
 #include "unichar.h"
 #include "hash.h"
 #include "hex-binary.h"
+#include "ioloop.h"
 #include "unlink-directory.h"
 #include "mail-index.h"
 #include "mail-search.h"
@@ -35,6 +36,7 @@
 #define FTS_LUCENE_MAX_SEARCH_TERMS 1000
 
 #define LUCENE_LOCK_OVERRIDE_SECS 60
+#define LUCENE_INDEX_CLOSE_TIMEOUT_MSECS (120*1000)
 
 using namespace lucene::document;
 using namespace lucene::index;
@@ -66,6 +68,7 @@
 	IndexReader *reader;
 	IndexWriter *writer;
 	IndexSearcher *searcher;
+	struct timeout *to_close;
 
 	buffer_t *normalizer_buf;
 	Analyzer *default_analyzer, *cur_analyzer;
@@ -97,8 +100,6 @@
 static bool textcat_broken = FALSE;
 static int textcat_refcount = 0;
 
-static void lucene_handle_error(struct lucene_index *index, CLuceneError &err,
-				const char *msg);
 static void rescan_clear_unseen_mailboxes(struct lucene_index *index,
 					  struct rescan_context *rescan_ctx);
 
@@ -143,6 +144,9 @@
 
 void lucene_index_close(struct lucene_index *index)
 {
+	if (index->to_close != NULL)
+		timeout_remove(&index->to_close);
+
 	_CLDELETE(index->searcher);
 	if (index->writer != NULL) {
 		try {
@@ -274,8 +278,11 @@
 
 static int lucene_index_open(struct lucene_index *index)
 {
-	if (index->reader != NULL)
+	if (index->reader != NULL) {
+		i_assert(index->to_close != NULL);
+		timeout_reset(index->to_close);
 		return 1;
+	}
 
 	if (!IndexReader::indexExists(index->path))
 		return 0;
@@ -286,6 +293,9 @@
 		lucene_handle_error(index, err, "IndexReader::open()");
 		return -1;
 	}
+	i_assert(index->to_close == NULL);
+	index->to_close = timeout_add(LUCENE_INDEX_CLOSE_TIMEOUT_MSECS,
+				      lucene_index_close, index);
 	return 1;
 }
 


More information about the dovecot-cvs mailing list