make indexation more easily cancellable

This commit is contained in:
dockes 2006-04-04 13:49:55 +00:00
parent e9d722e25c
commit 962f6f1012
6 changed files with 75 additions and 27 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.29 2006-04-04 12:37:51 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.30 2006-04-04 13:49:54 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -200,8 +200,11 @@ FsTreeWalker::Status
DbIndexer::processone(const std::string &fn, const struct stat *stp,
FsTreeWalker::CbFlag flg)
{
if (m_updfunc)
m_updfunc->update(fn);
if (m_updfunc) {
if (!m_updfunc->update(fn)) {
return FsTreeWalker::FtwStop;
}
}
// If we're changing directories, possibly adjust parameters (set
// the current directory in configuration object)
if (flg == FsTreeWalker::FtwDirEnter ||
@ -222,6 +225,7 @@ DbIndexer::processone(const std::string &fn, const struct stat *stp,
FileInterner interner(fn, m_config, m_tmpdir);
FileInterner::Status fis = FileInterner::FIAgain;
int i = 0;
while (fis == FileInterner::FIAgain) {
Rcl::Doc doc;
string ipath;
@ -229,6 +233,12 @@ DbIndexer::processone(const std::string &fn, const struct stat *stp,
if (fis == FileInterner::FIError)
break;
if (m_updfunc) {
if ((++i % 100) == 0 && !m_updfunc->update(fn+"|"+ipath)) {
return FsTreeWalker::FtwStop;
}
}
// Set the date if this was not done in the document handler
if (doc.fmtime.empty()) {
char ascdate[20];
@ -292,13 +302,13 @@ bool ConfIndexer::index(bool resetbefore)
if (lstat(doctopdir.c_str(), &st) < 0) {
LOGERR(("ConfIndexer::index: cant stat %s\n",
doctopdir.c_str()));
m_reason = string("Stat error for: ") + doctopdir;
m_reason = "Stat error for: " + doctopdir;
return false;
}
if (S_ISLNK(st.st_mode)) {
LOGERR(("ConfIndexer::index: no symlinks allowed in topdirs: %s\n",
doctopdir.c_str()));
m_reason = doctopdir + "is a symbolic link";
m_reason = doctopdir + " is a symbolic link";
return false;
}
}
@ -306,7 +316,7 @@ bool ConfIndexer::index(bool resetbefore)
if (!m_config->getConfParam("dbdir", dbdir)) {
LOGERR(("ConfIndexer::index: no database directory in "
"configuration for %s\n", doctopdir.c_str()));
m_reason = string("No database directory set for ") + doctopdir;
m_reason = "No database directory set for " + doctopdir;
return false;
}
dbdir = path_tildexpand(dbdir);
@ -333,7 +343,7 @@ bool ConfIndexer::index(bool resetbefore)
m_dbindexer = new DbIndexer(m_config, dbit->first, m_updfunc);
if (!m_dbindexer->indexDb(resetbefore, &dbit->second)) {
deleteZ(m_dbindexer);
m_reason = string("Failed indexing in ") + dbit->first;
m_reason = "Failed indexing in " + dbit->first;
return false;
}
deleteZ(m_dbindexer);

View File

@ -16,7 +16,7 @@
*/
#ifndef _INDEXER_H_INCLUDED_
#define _INDEXER_H_INCLUDED_
/* @(#$Id: indexer.h,v 1.13 2006-04-04 12:37:51 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: indexer.h,v 1.14 2006-04-04 13:49:54 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
@ -28,11 +28,12 @@
/* Forward decl for lower level indexing object */
class DbIndexer;
/* Callback to say what we're doing */
/* Callback to say what we're doing. If the update func returns false, we
* stop */
class DbIxStatusUpdater {
public:
virtual ~DbIxStatusUpdater(){}
virtual void update(const std::string &) = 0;
virtual bool update(const std::string &) = 0;
};
/**

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.16 2006-01-23 13:32:28 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.17 2006-04-04 13:49:54 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -83,11 +83,27 @@ static void cleanup()
dbindexer = 0;
}
int stopindexing;
string currentfile;
// Mainly used to request indexing stop, we currently do not use the
// current file name
class MyUpdater : public DbIxStatusUpdater {
public:
virtual bool update(const string &fn) {
currentfile = fn;
if (stopindexing) {
stopindexing = 0;
return false;
}
return true;
}
};
MyUpdater updater;
static void sigcleanup(int sig)
{
fprintf(stderr, "sigcleanup\n");
cleanup();
exit(1);
stopindexing = 1;
}
static const char *thisprog;
@ -173,7 +189,7 @@ int main(int argc, const char **argv)
string lang = *argv++; argc--;
exit(!createstemdb(config, lang));
} else {
confindexer = new ConfIndexer(config);
confindexer = new ConfIndexer(config, &updater);
bool rezero(op_flags & OPT_z);
exit(!confindexer->index(rezero));
}

View File

@ -30,20 +30,26 @@ static QMutex curfile_mutex;
class IdxThread : public QThread , public DbIxStatusUpdater {
virtual void run();
public:
virtual void update(const string &fn) {
virtual bool update(const string &fn) {
QMutexLocker locker(&curfile_mutex);
m_curfile = fn;
LOGDEB(("IdxThread::update: indexing %s\n", m_curfile.c_str()));
LOGDEB1(("IdxThread::update: indexing %s\n", m_curfile.c_str()));
if (stopindexing) {
stopindexing = 0;
return false;
}
return true;
}
ConfIndexer *indexer;
string m_curfile;
int loglevel;
};
int stopindexing;
int startindexing;
int indexingdone = 1;
bool indexingstatus = false;
IdxThreadStatus indexingstatus = IDXTS_NULL;
string indexingReason;
static int stopidxthread;
void IdxThread::run()
@ -55,10 +61,16 @@ void IdxThread::run()
return;
}
if (startindexing) {
indexingdone = indexingstatus = 0;
fprintf(stderr, "Index thread :start index\n");
indexingstatus = indexer->index();
startindexing = 0;
indexingdone = 0;
indexingstatus = IDXTS_NULL;
if (indexer->index()) {
indexingstatus = IDXTS_OK;
indexingReason = "";
} else {
indexingstatus = IDXTS_ERROR;
indexingReason = "Indexation failed: " + indexer->getReason();
}
indexingdone = 1;
}
msleep(100);
@ -80,6 +92,7 @@ void start_idxthread(const RclConfig& cnf)
void stop_idxthread()
{
stopindexing = 1;
stopidxthread = 1;
idxthread.wait();
}

View File

@ -16,7 +16,7 @@
*/
#ifndef _IDXTHREAD_H_INCLUDED_
#define _IDXTHREAD_H_INCLUDED_
/* @(#$Id: idxthread.h,v 1.4 2006-03-22 16:24:41 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: idxthread.h,v 1.5 2006-04-04 13:49:55 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
class RclConfig;
@ -27,8 +27,11 @@ extern void start_idxthread(const RclConfig& cnf);
extern void stop_idxthread();
extern std::string idxthread_currentfile();
extern int stopindexing;
extern int startindexing;
extern int indexingdone;
extern bool indexingstatus;
enum IdxThreadStatus {IDXTS_NULL = 0, IDXTS_OK = 1, IDXTS_ERROR = 2};
extern IdxThreadStatus indexingstatus;
extern string indexingReason;
#endif /* _IDXTHREAD_H_INCLUDED_ */

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.18 2006-04-04 07:55:29 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclmain.cpp,v 1.19 2006-04-04 13:49:55 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -211,9 +211,14 @@ void RclMain::periodic100()
{
static int toggle = 0;
// Check if indexing thread done
if (indexingstatus) {
if (indexingstatus != IDXTS_NULL) {
statusBar()->message("");
indexingstatus = false;
if (indexingstatus != IDXTS_OK) {
indexingstatus = IDXTS_NULL;
QMessageBox::warning(0, "Recoll",
QString::fromAscii(indexingReason.c_str()));
}
indexingstatus = IDXTS_NULL;
// Make sure we reopen the db to get the results.
LOGINFO(("Indexing done: closing query database\n"));
rcldb->close();
@ -240,7 +245,7 @@ void RclMain::periodic100()
void RclMain::fileStart_IndexingAction_activated()
{
if (indexingdone == 1)
if (indexingdone)
startindexing = 1;
}