From a4d1689581edac945dbb0505da3f2a8534eb8061 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Thu, 28 Apr 2011 12:27:06 +0200 Subject: [PATCH] try to be more responsive to user interrupts: do not build the aux databases after an interruption, and check for an interruption during the purge pass --- src/index/indexer.cpp | 17 +++++++++++------ src/rcldb/rcldb.cpp | 11 +++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/index/indexer.cpp b/src/index/indexer.cpp index fcb488d4..e4d57ca8 100644 --- a/src/index/indexer.cpp +++ b/src/index/indexer.cpp @@ -78,22 +78,27 @@ bool ConfIndexer::index(bool resetbefore, ixType typestorun) if (typestorun == IxTAll) { // Get rid of all database entries that don't exist in the // filesystem anymore. Only if all *configured* indexers ran. - if (m_updater) - m_updater->update(DbIxStatus::DBIXS_PURGE, string()); + if (m_updater && !m_updater->update(DbIxStatus::DBIXS_PURGE, string())) + return false; m_db.purge(); } + // The close would be done in our destructor, but we want status + // here. Makes no sense to check for cancel, we'll have to close + // anyway if (m_updater) m_updater->update(DbIxStatus::DBIXS_CLOSING, string()); - - // The close would be done in our destructor, but we want status here if (!m_db.close()) { LOGERR(("ConfIndexer::index: error closing database in %s\n", m_config->getDbDir().c_str())); return false; } + if (m_updater && !m_updater->update(DbIxStatus::DBIXS_CLOSING, string())) + return false; createStemmingDatabases(); + if (m_updater && !m_updater->update(DbIxStatus::DBIXS_CLOSING, string())) + return false; createAspellDict(); clearMimeHandlerCache(); return true; @@ -205,8 +210,8 @@ bool ConfIndexer::createStemmingDatabases() m_db.deleteStemDb(*it); } for (it = langs.begin(); it != langs.end(); it++) { - if (m_updater) - m_updater->update(DbIxStatus::DBIXS_STEMDB, *it); + if (m_updater && !m_updater->update(DbIxStatus::DBIXS_STEMDB, *it)) + return false; m_db.createStemDb(*it); } } diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index ba77b0bf..9f42cf81 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -50,6 +50,7 @@ using namespace std; #include "rclquery_p.h" #include "md5.h" #include "rclversion.h" +#include "cancelcheck.h" #ifndef MAX #define MAX(A,B) (A>B?A:B) @@ -1322,8 +1323,17 @@ bool Db::purge() // Walk the document array and delete any xapian document whose // flag is not set (we did not see its source during indexing). + int purgecount = 0; for (Xapian::docid docid = 1; docid < updated.size(); ++docid) { if (!updated[docid]) { + if ((purgecount+1) % 100 == 0) { + try { + CancelCheck::instance().checkCancel(); + } catch(CancelExcept) { + LOGINFO(("Db::purge: partially cancelled\n")); + break; + } + } try { m_ndb->xwdb.delete_document(docid); LOGDEB(("Db::purge: deleted document #%d\n", docid)); @@ -1334,6 +1344,7 @@ bool Db::purge() } catch (...) { LOGERR(("Db::purge: document #%d: unknown error\n", docid)); } + purgecount++; } }