From: Timo Sirainen Date: Thu, 21 Aug 2014 12:48:41 +0000 (+0200) Subject: fts-lucene: Automatically close index after 2 minutes of idling. X-Git-Tag: 2.2.14.rc1~130 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4d72a99412a0577b026b64afc27975f28a58d071;p=thirdparty%2Fdovecot%2Fcore.git fts-lucene: Automatically close index after 2 minutes of idling. --- diff --git a/src/plugins/fts-lucene/lucene-wrapper.cc b/src/plugins/fts-lucene/lucene-wrapper.cc index 90c8553d64..e5379f915b 100644 --- a/src/plugins/fts-lucene/lucene-wrapper.cc +++ b/src/plugins/fts-lucene/lucene-wrapper.cc @@ -6,6 +6,7 @@ extern "C" { #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 @@ extern "C" { #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 @@ struct lucene_index { IndexReader *reader; IndexWriter *writer; IndexSearcher *searcher; + struct timeout *to_close; buffer_t *normalizer_buf; Analyzer *default_analyzer, *cur_analyzer; @@ -97,8 +100,6 @@ static void *textcat = NULL; 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 @@ struct lucene_index *lucene_index_init(const char *path, 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 void lucene_handle_error(struct lucene_index *index, CLuceneError &err, 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 @@ static int lucene_index_open(struct lucene_index *index) 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; }