Drain the job pipeline in fsindexer::purgefiles like was done in fsindexer::indexfiles as there is no warranty that the latter will be called before a db::close for each iteration of the monitor loop

This commit is contained in:
Jean-Francois Dockes 2012-12-15 09:21:50 +01:00
parent 5cb6e5f182
commit a0e273ddd4
2 changed files with 27 additions and 7 deletions

View File

@ -291,6 +291,8 @@ static bool matchesSkipped(const vector<string>& tdl,
*/ */
bool FsIndexer::indexFiles(list<string>& files, ConfIndexer::IxFlag flag) bool FsIndexer::indexFiles(list<string>& files, ConfIndexer::IxFlag flag)
{ {
int ret = false;
if (!init()) if (!init())
return false; return false;
@ -315,7 +317,8 @@ bool FsIndexer::indexFiles(list<string>& files, ConfIndexer::IxFlag flag)
// Check path against indexed areas and skipped names/paths // Check path against indexed areas and skipped names/paths
if (!(flag&ConfIndexer::IxFIgnoreSkip) && if (!(flag&ConfIndexer::IxFIgnoreSkip) &&
matchesSkipped(m_tdl, walker, *it)) { matchesSkipped(m_tdl, walker, *it)) {
it++; continue; it++;
continue;
} }
struct stat stb; struct stat stb;
@ -324,17 +327,20 @@ bool FsIndexer::indexFiles(list<string>& files, ConfIndexer::IxFlag flag)
if (ststat != 0) { if (ststat != 0) {
LOGERR(("FsIndexer::indexFiles: lstat(%s): %s", it->c_str(), LOGERR(("FsIndexer::indexFiles: lstat(%s): %s", it->c_str(),
strerror(errno))); strerror(errno)));
it++; continue; it++;
continue;
} }
if (processone(*it, &stb, FsTreeWalker::FtwRegular) != if (processone(*it, &stb, FsTreeWalker::FtwRegular) !=
FsTreeWalker::FtwOk) { FsTreeWalker::FtwOk) {
LOGERR(("FsIndexer::indexFiles: processone failed\n")); LOGERR(("FsIndexer::indexFiles: processone failed\n"));
return false; goto out;
} }
it = files.erase(it); it = files.erase(it);
} }
ret = true;
out:
#ifdef IDX_THREADS #ifdef IDX_THREADS
if (m_haveInternQ) if (m_haveInternQ)
m_iwqueue.waitIdle(); m_iwqueue.waitIdle();
@ -342,14 +348,14 @@ bool FsIndexer::indexFiles(list<string>& files, ConfIndexer::IxFlag flag)
m_dwqueue.waitIdle(); m_dwqueue.waitIdle();
m_db->waitUpdIdle(); m_db->waitUpdIdle();
#endif // IDX_THREADS #endif // IDX_THREADS
return ret;
return true;
} }
/** Purge docs for given files out of the database */ /** Purge docs for given files out of the database */
bool FsIndexer::purgeFiles(list<string>& files) bool FsIndexer::purgeFiles(list<string>& files)
{ {
bool ret = false;
if (!init()) if (!init())
return false; return false;
@ -361,7 +367,7 @@ bool FsIndexer::purgeFiles(list<string>& files)
bool existed; bool existed;
if (!m_db->purgeFile(udi, &existed)) { if (!m_db->purgeFile(udi, &existed)) {
LOGERR(("FsIndexer::purgeFiles: Database error\n")); LOGERR(("FsIndexer::purgeFiles: Database error\n"));
return false; goto out;
} }
// If we actually deleted something, take it off the list // If we actually deleted something, take it off the list
if (existed) { if (existed) {
@ -371,7 +377,16 @@ bool FsIndexer::purgeFiles(list<string>& files)
} }
} }
return true; ret = true;
out:
#ifdef IDX_THREADS
if (m_haveInternQ)
m_iwqueue.waitIdle();
if (m_haveSplitQ)
m_dwqueue.waitIdle();
m_db->waitUpdIdle();
#endif // IDX_THREADS
return ret;
} }
// Local fields can be set for fs subtrees in the configuration file // Local fields can be set for fs subtrees in the configuration file

View File

@ -147,6 +147,11 @@ public:
* only thread which can call it safely is the client just above * only thread which can call it safely is the client just above
* (which can control the task flow), else there could be * (which can control the task flow), else there could be
* tasks in the intermediate queues. * tasks in the intermediate queues.
* To rephrase: there is no warranty on return that the queue is actually
* idle EXCEPT if the caller knows that no jobs are still being created.
* It would be possible to transform this into a safe call if some kind
* of suspend condition was set on the queue by waitIdle(), to be reset by
* some kind of "resume" call. Not currently the case.
*/ */
bool waitIdle() bool waitIdle()
{ {