add idxniceprio parameter to choose indexing process priority

This commit is contained in:
Jean-Francois Dockes 2020-01-31 09:29:02 +01:00
parent da05b762a7
commit aa40531bbe
3 changed files with 278 additions and 252 deletions

View File

@ -104,11 +104,11 @@ static void cleanup()
// Also check for an interrupt request and return the info to caller which // Also check for an interrupt request and return the info to caller which
// should subsequently orderly terminate what it is doing. // should subsequently orderly terminate what it is doing.
class MyUpdater : public DbIxStatusUpdater { class MyUpdater : public DbIxStatusUpdater {
public: public:
MyUpdater(const RclConfig *config) MyUpdater(const RclConfig *config)
: m_file(config->getIdxStatusFile().c_str()), : m_file(config->getIdxStatusFile().c_str()),
m_stopfilename(config->getIdxStopFile()), m_stopfilename(config->getIdxStopFile()),
m_prevphase(DbIxStatus::DBIXS_NONE) { m_prevphase(DbIxStatus::DBIXS_NONE) {
// The total number of files included in the index is actually // The total number of files included in the index is actually
// difficult to compute from the index itself. For display // difficult to compute from the index itself. For display
// purposes, we save it in the status file from indexing to // purposes, we save it in the status file from indexing to
@ -121,49 +121,49 @@ class MyUpdater : public DbIxStatusUpdater {
virtual bool update() virtual bool update()
{ {
// Update the status file. Avoid doing it too often. Always do // Update the status file. Avoid doing it too often. Always do
// it at the end (status DONE) // it at the end (status DONE)
if (status.phase == DbIxStatus::DBIXS_DONE || if (status.phase == DbIxStatus::DBIXS_DONE ||
status.phase != m_prevphase || m_chron.millis() > 300) { status.phase != m_prevphase || m_chron.millis() > 300) {
if (status.totfiles < status.filesdone || if (status.totfiles < status.filesdone ||
status.phase == DbIxStatus::DBIXS_DONE) { status.phase == DbIxStatus::DBIXS_DONE) {
status.totfiles = status.filesdone; status.totfiles = status.filesdone;
} }
m_prevphase = status.phase; m_prevphase = status.phase;
m_chron.restart(); m_chron.restart();
m_file.holdWrites(true); m_file.holdWrites(true);
m_file.set("phase", int(status.phase)); m_file.set("phase", int(status.phase));
m_file.set("docsdone", status.docsdone); m_file.set("docsdone", status.docsdone);
m_file.set("filesdone", status.filesdone); m_file.set("filesdone", status.filesdone);
m_file.set("fileerrors", status.fileerrors); m_file.set("fileerrors", status.fileerrors);
m_file.set("dbtotdocs", status.dbtotdocs); m_file.set("dbtotdocs", status.dbtotdocs);
m_file.set("totfiles", status.totfiles); m_file.set("totfiles", status.totfiles);
m_file.set("fn", status.fn); m_file.set("fn", status.fn);
m_file.set("hasmonitor", status.hasmonitor); m_file.set("hasmonitor", status.hasmonitor);
m_file.holdWrites(false); m_file.holdWrites(false);
} }
if (path_exists(m_stopfilename)) { if (path_exists(m_stopfilename)) {
LOGINF("recollindex: asking indexer to stop because " << LOGINF("recollindex: asking indexer to stop because " <<
m_stopfilename << " exists\n"); m_stopfilename << " exists\n");
unlink(m_stopfilename.c_str()); unlink(m_stopfilename.c_str());
stopindexing = true; stopindexing = true;
} }
if (stopindexing) { if (stopindexing) {
return false; return false;
} }
#ifndef DISABLE_X11MON #ifndef DISABLE_X11MON
// If we are in the monitor, we also need to check X11 status // If we are in the monitor, we also need to check X11 status
// during the initial indexing pass (else the user could log // during the initial indexing pass (else the user could log
// out and the indexing would go on, not good (ie: if the user // out and the indexing would go on, not good (ie: if the user
// logs in again, the new recollindex will fail). // logs in again, the new recollindex will fail).
if ((op_flags & OPT_m) && !(op_flags & OPT_x) && !x11IsAlive()) { if ((op_flags & OPT_m) && !(op_flags & OPT_x) && !x11IsAlive()) {
LOGDEB("X11 session went away during initial indexing pass\n"); LOGDEB("X11 session went away during initial indexing pass\n");
stopindexing = true; stopindexing = true;
return false; return false;
} }
#endif #endif
return true; return true;
} }
private: private:
@ -217,9 +217,9 @@ static void sigcleanup(int sig)
static void makeIndexerOrExit(RclConfig *config, bool inPlaceReset) static void makeIndexerOrExit(RclConfig *config, bool inPlaceReset)
{ {
if (!confindexer) { if (!confindexer) {
confindexer = new ConfIndexer(config, updater); confindexer = new ConfIndexer(config, updater);
if (inPlaceReset) if (inPlaceReset)
confindexer->setInPlaceReset(); confindexer->setInPlaceReset();
} }
if (!confindexer) { if (!confindexer) {
cerr << "Cannot create indexer" << endl; cerr << "Cannot create indexer" << endl;
@ -232,7 +232,8 @@ void rclIxIonice(const RclConfig *config)
#ifndef _WIN32 #ifndef _WIN32
string clss, classdata; string clss, classdata;
if (!config->getConfParam("monioniceclass", clss) || clss.empty()) if (!config->getConfParam("monioniceclass", clss) || clss.empty())
clss = "3"; clss = "3";
// Classdata may be empty (must be for idle class)
config->getConfParam("monioniceclassdata", classdata); config->getConfParam("monioniceclassdata", classdata);
rclionice(clss, classdata); rclionice(clss, classdata);
#endif #endif
@ -241,7 +242,13 @@ void rclIxIonice(const RclConfig *config)
static void setMyPriority(const RclConfig *config) static void setMyPriority(const RclConfig *config)
{ {
#ifndef _WIN32 #ifndef _WIN32
if (setpriority(PRIO_PROCESS, 0, 20) != 0) { int prio{19};
std::string sprio;
config->getConfParam("idxniceprio", sprio);
if (!sprio.empty()) {
prio = atoi(sprio.c_str());
}
if (setpriority(PRIO_PROCESS, 0, prio) != 0) {
LOGINFO("recollindex: can't setpriority(), errno " << errno << "\n"); LOGINFO("recollindex: can't setpriority(), errno " << errno << "\n");
} }
// Try to ionice. This does not work on all platforms // Try to ionice. This does not work on all platforms
@ -253,13 +260,13 @@ static void setMyPriority(const RclConfig *config)
class MakeListWalkerCB : public FsTreeWalkerCB { class MakeListWalkerCB : public FsTreeWalkerCB {
public: public:
MakeListWalkerCB(list<string>& files, const vector<string>& selpats) MakeListWalkerCB(list<string>& files, const vector<string>& selpats)
: m_files(files), m_pats(selpats) : m_files(files), m_pats(selpats)
{ {
} }
virtual FsTreeWalker::Status virtual FsTreeWalker::Status
processone(const string& fn, const struct stat *, FsTreeWalker::CbFlag flg) processone(const string& fn, const struct stat *, FsTreeWalker::CbFlag flg)
{ {
if (flg== FsTreeWalker::FtwDirEnter || flg == FsTreeWalker::FtwRegular){ if (flg== FsTreeWalker::FtwDirEnter || flg == FsTreeWalker::FtwRegular){
if (m_pats.empty()) { if (m_pats.empty()) {
cerr << "Selecting " << fn << endl; cerr << "Selecting " << fn << endl;
m_files.push_back(fn); m_files.push_back(fn);
@ -273,7 +280,7 @@ public:
} }
} }
} }
return FsTreeWalker::FtwOk; return FsTreeWalker::FtwOk;
} }
list<string>& m_files; list<string>& m_files;
const vector<string>& m_pats; const vector<string>& m_pats;
@ -312,7 +319,7 @@ bool recursive_index(RclConfig *config, const string& top,
bool indexfiles(RclConfig *config, list<string> &filenames) bool indexfiles(RclConfig *config, list<string> &filenames)
{ {
if (filenames.empty()) if (filenames.empty())
return true; return true;
makeIndexerOrExit(config, (op_flags & OPT_Z) != 0); makeIndexerOrExit(config, (op_flags & OPT_Z) != 0);
// The default is to retry failed files // The default is to retry failed files
int indexerFlags = ConfIndexer::IxFNone; int indexerFlags = ConfIndexer::IxFNone;
@ -330,7 +337,7 @@ bool indexfiles(RclConfig *config, list<string> &filenames)
bool purgefiles(RclConfig *config, list<string> &filenames) bool purgefiles(RclConfig *config, list<string> &filenames)
{ {
if (filenames.empty()) if (filenames.empty())
return true; return true;
makeIndexerOrExit(config, (op_flags & OPT_Z) != 0); makeIndexerOrExit(config, (op_flags & OPT_Z) != 0);
return confindexer->purgeFiles(filenames, ConfIndexer::IxFNone); return confindexer->purgeFiles(filenames, ConfIndexer::IxFNone);
} }
@ -341,10 +348,10 @@ bool createAuxDbs(RclConfig *config)
makeIndexerOrExit(config, false); makeIndexerOrExit(config, false);
if (!confindexer->createStemmingDatabases()) if (!confindexer->createStemmingDatabases())
return false; return false;
if (!confindexer->createAspellDict()) if (!confindexer->createAspellDict())
return false; return false;
return true; return true;
} }
@ -391,7 +398,7 @@ static bool checktopdirs(RclConfig *config, vector<string>& nonexist)
} }
for (auto& dir : o_topdirs) { for (auto& dir : o_topdirs) {
dir = path_tildexpand(dir); dir = path_tildexpand(dir);
if (!dir.size() || !path_isabsolute(dir)) { if (!dir.size() || !path_isabsolute(dir)) {
if (dir[0] == '~') { if (dir[0] == '~') {
cerr << "Tilde expansion failed: " << dir << endl; cerr << "Tilde expansion failed: " << dir << endl;
@ -418,54 +425,54 @@ static bool checktopdirs(RclConfig *config, vector<string>& nonexist)
string thisprog; string thisprog;
static const char usage [] = static const char usage [] =
"\n" "\n"
"recollindex [-h] \n" "recollindex [-h] \n"
" Print help\n" " Print help\n"
"recollindex [-z|-Z] [-k]\n" "recollindex [-z|-Z] [-k]\n"
" Index everything according to configuration file\n" " Index everything according to configuration file\n"
" -z : reset database before starting indexing\n" " -z : reset database before starting indexing\n"
" -Z : in place reset: consider all documents as changed. Can also\n" " -Z : in place reset: consider all documents as changed. Can also\n"
" be combined with -i or -r but not -m\n" " be combined with -i or -r but not -m\n"
" -k : retry files on which we previously failed\n" " -k : retry files on which we previously failed\n"
#ifdef RCL_MONITOR #ifdef RCL_MONITOR
"recollindex -m [-w <secs>] -x [-D] [-C]\n" "recollindex -m [-w <secs>] -x [-D] [-C]\n"
" Perform real time indexing. Don't become a daemon if -D is set.\n" " Perform real time indexing. Don't become a daemon if -D is set.\n"
" -w sets number of seconds to wait before starting.\n" " -w sets number of seconds to wait before starting.\n"
" -C disables monitoring config for changes/reexecuting.\n" " -C disables monitoring config for changes/reexecuting.\n"
" -n disables initial incremental indexing (!and purge!).\n" " -n disables initial incremental indexing (!and purge!).\n"
#ifndef DISABLE_X11MON #ifndef DISABLE_X11MON
" -x disables exit on end of x11 session\n" " -x disables exit on end of x11 session\n"
#endif /* DISABLE_X11MON */ #endif /* DISABLE_X11MON */
#endif /* RCL_MONITOR */ #endif /* RCL_MONITOR */
"recollindex -e [<filepath [path ...]>]\n" "recollindex -e [<filepath [path ...]>]\n"
" Purge data for individual files. No stem database updates.\n" " Purge data for individual files. No stem database updates.\n"
" Reads paths on stdin if none is given as argument.\n" " Reads paths on stdin if none is given as argument.\n"
"recollindex -i [-f] [-Z] [<filepath [path ...]>]\n" "recollindex -i [-f] [-Z] [<filepath [path ...]>]\n"
" Index individual files. No database purge or stem database updates\n" " Index individual files. No database purge or stem database updates\n"
" Will read paths on stdin if none is given as argument\n" " Will read paths on stdin if none is given as argument\n"
" -f : ignore skippedPaths and skippedNames while doing this\n" " -f : ignore skippedPaths and skippedNames while doing this\n"
"recollindex -r [-K] [-f] [-Z] [-p pattern] <top> \n" "recollindex -r [-K] [-f] [-Z] [-p pattern] <top> \n"
" Recursive partial reindex. \n" " Recursive partial reindex. \n"
" -p : filter file names, multiple instances are allowed, e.g.: \n" " -p : filter file names, multiple instances are allowed, e.g.: \n"
" -p *.odt -p *.pdf\n" " -p *.odt -p *.pdf\n"
" -K : skip previously failed files (they are retried by default)\n" " -K : skip previously failed files (they are retried by default)\n"
"recollindex -l\n" "recollindex -l\n"
" List available stemming languages\n" " List available stemming languages\n"
"recollindex -s <lang>\n" "recollindex -s <lang>\n"
" Build stem database for additional language <lang>\n" " Build stem database for additional language <lang>\n"
"recollindex -E\n" "recollindex -E\n"
" Check configuration file for topdirs and other paths existence\n" " Check configuration file for topdirs and other paths existence\n"
#ifdef FUTURE_IMPROVEMENT #ifdef FUTURE_IMPROVEMENT
"recollindex -W\n" "recollindex -W\n"
" Process the Web queue\n" " Process the Web queue\n"
#endif #endif
#ifdef RCL_USE_ASPELL #ifdef RCL_USE_ASPELL
"recollindex -S\n" "recollindex -S\n"
" Build aspell spelling dictionary.>\n" " Build aspell spelling dictionary.>\n"
#endif #endif
"Common options:\n" "Common options:\n"
" -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n" " -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n"
; ;
static void static void
Usage(FILE *where = stderr) Usage(FILE *where = stderr)
@ -508,12 +515,12 @@ static void lockorexit(Pidfile *pidfile, RclConfig *config)
cerr << "Can't become exclusive indexer: " << pidfile->getreason() cerr << "Can't become exclusive indexer: " << pidfile->getreason()
<< endl; << endl;
} }
exit(1); exit(1);
} }
if (pidfile->write_pid() != 0) { if (pidfile->write_pid() != 0) {
cerr << "Can't become exclusive indexer: " << pidfile->getreason() << cerr << "Can't become exclusive indexer: " << pidfile->getreason() <<
endl; endl;
exit(1); exit(1);
} }
} }
@ -557,65 +564,65 @@ int main(int argc, char **argv)
argc--; argv++; argc--; argv++;
while (argc > 0 && **argv == '-') { while (argc > 0 && **argv == '-') {
(*argv)++; (*argv)++;
if (!(**argv)) if (!(**argv))
Usage(); Usage();
while (**argv) while (**argv)
switch (*(*argv)++) { switch (*(*argv)++) {
case 'b': op_flags |= OPT_b; break; case 'b': op_flags |= OPT_b; break;
case 'c': op_flags |= OPT_c; if (argc < 2) Usage(); case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
a_config = *(++argv); a_config = *(++argv);
argc--; goto b1; argc--; goto b1;
#ifdef RCL_MONITOR #ifdef RCL_MONITOR
case 'C': op_flags |= OPT_C; break; case 'C': op_flags |= OPT_C; break;
case 'D': op_flags |= OPT_D; break; case 'D': op_flags |= OPT_D; break;
#endif #endif
case 'E': op_flags |= OPT_E; break; case 'E': op_flags |= OPT_E; break;
case 'e': op_flags |= OPT_e; break; case 'e': op_flags |= OPT_e; break;
case 'f': op_flags |= OPT_f; break; case 'f': op_flags |= OPT_f; break;
case 'h': op_flags |= OPT_h; break; case 'h': op_flags |= OPT_h; break;
case 'i': op_flags |= OPT_i; break; case 'i': op_flags |= OPT_i; break;
case 'k': op_flags |= OPT_k; break; case 'k': op_flags |= OPT_k; break;
case 'K': op_flags |= OPT_K; break; case 'K': op_flags |= OPT_K; break;
case 'l': op_flags |= OPT_l; break; case 'l': op_flags |= OPT_l; break;
case 'm': op_flags |= OPT_m; break; case 'm': op_flags |= OPT_m; break;
case 'n': op_flags |= OPT_n; break; case 'n': op_flags |= OPT_n; break;
case 'P': op_flags |= OPT_P; break; case 'P': op_flags |= OPT_P; break;
case 'p': op_flags |= OPT_p; if (argc < 2) Usage(); case 'p': op_flags |= OPT_p; if (argc < 2) Usage();
selpatterns.push_back(*(++argv)); selpatterns.push_back(*(++argv));
argc--; goto b1; argc--; goto b1;
case 'r': op_flags |= OPT_r; break; case 'r': op_flags |= OPT_r; break;
case 'R': op_flags |= OPT_R; if (argc < 2) Usage(); case 'R': op_flags |= OPT_R; if (argc < 2) Usage();
reasonsfile = *(++argv); argc--; goto b1; reasonsfile = *(++argv); argc--; goto b1;
case 's': op_flags |= OPT_s; break; case 's': op_flags |= OPT_s; break;
#ifdef RCL_USE_ASPELL #ifdef RCL_USE_ASPELL
case 'S': op_flags |= OPT_S; break; case 'S': op_flags |= OPT_S; break;
#endif #endif
case 'w': op_flags |= OPT_w; if (argc < 2) Usage(); case 'w': op_flags |= OPT_w; if (argc < 2) Usage();
if ((sscanf(*(++argv), "%d", &sleepsecs)) != 1) if ((sscanf(*(++argv), "%d", &sleepsecs)) != 1)
Usage(); Usage();
argc--; goto b1; argc--; goto b1;
case 'x': op_flags |= OPT_x; break; case 'x': op_flags |= OPT_x; break;
case 'Z': op_flags |= OPT_Z; break; case 'Z': op_flags |= OPT_Z; break;
case 'z': op_flags |= OPT_z; break; case 'z': op_flags |= OPT_z; break;
default: Usage(); break; default: Usage(); break;
} }
b1: argc--; argv++; b1: argc--; argv++;
} }
if (op_flags & OPT_h) if (op_flags & OPT_h)
Usage(stdout); Usage(stdout);
#ifndef RCL_MONITOR #ifndef RCL_MONITOR
if (op_flags & (OPT_m | OPT_w|OPT_x)) { if (op_flags & (OPT_m | OPT_w|OPT_x)) {
cerr << "Sorry, -m not available: real-time monitoring was not " cerr << "Sorry, -m not available: real-time monitoring was not "
"configured in this build\n"; "configured in this build\n";
exit(1); exit(1);
} }
#endif #endif
if ((op_flags & OPT_z) && (op_flags & (OPT_i|OPT_e|OPT_r))) if ((op_flags & OPT_z) && (op_flags & (OPT_i|OPT_e|OPT_r)))
Usage(); Usage();
if ((op_flags & OPT_Z) && (op_flags & (OPT_m))) if ((op_flags & OPT_Z) && (op_flags & (OPT_m)))
Usage(); Usage();
if ((op_flags & OPT_E) && (op_flags & ~(OPT_E|OPT_c))) { if ((op_flags & OPT_E) && (op_flags & ~(OPT_E|OPT_c))) {
Usage(); Usage();
} }
@ -623,14 +630,14 @@ int main(int argc, char **argv)
string reason; string reason;
int flags = RCLINIT_IDX; int flags = RCLINIT_IDX;
if ((op_flags & OPT_m) && !(op_flags&OPT_D)) { if ((op_flags & OPT_m) && !(op_flags&OPT_D)) {
flags |= RCLINIT_DAEMON; flags |= RCLINIT_DAEMON;
} }
config = recollinit(flags, cleanup, sigcleanup, reason, &a_config); config = recollinit(flags, cleanup, sigcleanup, reason, &a_config);
if (config == 0 || !config->ok()) { if (config == 0 || !config->ok()) {
addIdxReason("init", reason); addIdxReason("init", reason);
flushIdxReasons(); flushIdxReasons();
cerr << "Configuration problem: " << reason << endl; cerr << "Configuration problem: " << reason << endl;
exit(1); exit(1);
} }
#ifndef _WIN32 #ifndef _WIN32
o_reexec->atexit(cleanup); o_reexec->atexit(cleanup);
@ -661,18 +668,18 @@ int main(int argc, char **argv)
string rundir; string rundir;
config->getConfParam("idxrundir", rundir); config->getConfParam("idxrundir", rundir);
if (!rundir.compare("tmp")) { if (!rundir.compare("tmp")) {
LOGINFO("recollindex: changing current directory to [" << LOGINFO("recollindex: changing current directory to [" <<
tmplocation() << "]\n"); tmplocation() << "]\n");
if (chdir(tmplocation().c_str()) < 0) { if (chdir(tmplocation().c_str()) < 0) {
LOGERR("chdir(" << tmplocation() << ") failed, errno " << errno << LOGERR("chdir(" << tmplocation() << ") failed, errno " << errno <<
"\n"); "\n");
} }
} else if (!rundir.empty()) { } else if (!rundir.empty()) {
LOGINFO("recollindex: changing current directory to [" << rundir << LOGINFO("recollindex: changing current directory to [" << rundir <<
"]\n"); "]\n");
if (chdir(rundir.c_str()) < 0) { if (chdir(rundir.c_str()) < 0) {
LOGERR("chdir(" << rundir << ") failed, errno " << errno << "\n"); LOGERR("chdir(" << rundir << ") failed, errno " << errno << "\n");
} }
} }
bool rezero((op_flags & OPT_z) != 0); bool rezero((op_flags & OPT_z) != 0);
@ -710,10 +717,10 @@ int main(int argc, char **argv)
setMyPriority(config); setMyPriority(config);
if (op_flags & OPT_r) { if (op_flags & OPT_r) {
if (argc != 1) if (argc != 1)
Usage(); Usage();
string top = *argv++; argc--; string top = *argv++; argc--;
bool status = recursive_index(config, top, selpatterns); bool status = recursive_index(config, top, selpatterns);
if (confindexer && !confindexer->getReason().empty()) { if (confindexer && !confindexer->getReason().empty()) {
addIdxReason("indexer", confindexer->getReason()); addIdxReason("indexer", confindexer->getReason());
cerr << confindexer->getReason() << endl; cerr << confindexer->getReason() << endl;
@ -721,33 +728,33 @@ int main(int argc, char **argv)
flushIdxReasons(); flushIdxReasons();
exit(status ? 0 : 1); exit(status ? 0 : 1);
} else if (op_flags & (OPT_i|OPT_e)) { } else if (op_flags & (OPT_i|OPT_e)) {
lockorexit(&pidfile, config); lockorexit(&pidfile, config);
list<string> filenames; list<string> filenames;
if (argc == 0) { if (argc == 0) {
// Read from stdin // Read from stdin
char line[1024]; char line[1024];
while (fgets(line, 1023, stdin)) { while (fgets(line, 1023, stdin)) {
string sl(line); string sl(line);
trimstring(sl, "\n\r"); trimstring(sl, "\n\r");
filenames.push_back(sl); filenames.push_back(sl);
} }
} else { } else {
while (argc--) { while (argc--) {
filenames.push_back(*argv++); filenames.push_back(*argv++);
} }
} }
// Note that -e and -i may be both set. In this case we first erase, // Note that -e and -i may be both set. In this case we first erase,
// then index. This is a slightly different from -Z -i because we // then index. This is a slightly different from -Z -i because we
// warranty that all subdocs are purged. // warranty that all subdocs are purged.
bool status = true; bool status = true;
if (op_flags & OPT_e) { if (op_flags & OPT_e) {
status = purgefiles(config, filenames); status = purgefiles(config, filenames);
} }
if (status && (op_flags & OPT_i)) { if (status && (op_flags & OPT_i)) {
status = indexfiles(config, filenames); status = indexfiles(config, filenames);
} }
if (confindexer && !confindexer->getReason().empty()) { if (confindexer && !confindexer->getReason().empty()) {
addIdxReason("indexer", confindexer->getReason()); addIdxReason("indexer", confindexer->getReason());
@ -756,132 +763,132 @@ int main(int argc, char **argv)
flushIdxReasons(); flushIdxReasons();
exit(status ? 0 : 1); exit(status ? 0 : 1);
} else if (op_flags & OPT_l) { } else if (op_flags & OPT_l) {
if (argc != 0) if (argc != 0)
Usage(); Usage();
vector<string> stemmers = ConfIndexer::getStemmerNames(); vector<string> stemmers = ConfIndexer::getStemmerNames();
for (vector<string>::const_iterator it = stemmers.begin(); for (vector<string>::const_iterator it = stemmers.begin();
it != stemmers.end(); it++) { it != stemmers.end(); it++) {
cout << *it << endl; cout << *it << endl;
} }
exit(0); exit(0);
} else if (op_flags & OPT_s) { } else if (op_flags & OPT_s) {
if (argc != 1) if (argc != 1)
Usage(); Usage();
string lang = *argv++; argc--; string lang = *argv++; argc--;
exit(!createstemdb(config, lang)); exit(!createstemdb(config, lang));
#ifdef RCL_USE_ASPELL #ifdef RCL_USE_ASPELL
} else if (op_flags & OPT_S) { } else if (op_flags & OPT_S) {
makeIndexerOrExit(config, false); makeIndexerOrExit(config, false);
exit(!confindexer->createAspellDict()); exit(!confindexer->createAspellDict());
#endif // ASPELL #endif // ASPELL
#ifdef RCL_MONITOR #ifdef RCL_MONITOR
} else if (op_flags & OPT_m) { } else if (op_flags & OPT_m) {
if (argc != 0) if (argc != 0)
Usage(); Usage();
lockorexit(&pidfile, config); lockorexit(&pidfile, config);
if (updater) { if (updater) {
updater->status.hasmonitor = true; updater->status.hasmonitor = true;
} }
if (!(op_flags&OPT_D)) { if (!(op_flags&OPT_D)) {
LOGDEB("recollindex: daemonizing\n"); LOGDEB("recollindex: daemonizing\n");
#ifndef _WIN32 #ifndef _WIN32
if (daemon(0,0) != 0) { if (daemon(0,0) != 0) {
addIdxReason("monitor", "daemon() failed"); addIdxReason("monitor", "daemon() failed");
cerr << "daemon() failed, errno " << errno << endl; cerr << "daemon() failed, errno " << errno << endl;
LOGERR("daemon() failed, errno " << errno << "\n"); LOGERR("daemon() failed, errno " << errno << "\n");
flushIdxReasons(); flushIdxReasons();
exit(1); exit(1);
} }
#endif #endif
} }
// Need to rewrite pid, it changed // Need to rewrite pid, it changed
pidfile.write_pid(); pidfile.write_pid();
// Not too sure if I have to redo the nice thing after daemon(), // Not too sure if I have to redo the nice thing after daemon(),
// can't hurt anyway (easier than testing on all platforms...) // can't hurt anyway (easier than testing on all platforms...)
setMyPriority(config); setMyPriority(config);
if (sleepsecs > 0) { if (sleepsecs > 0) {
LOGDEB("recollindex: sleeping " << sleepsecs << "\n"); LOGDEB("recollindex: sleeping " << sleepsecs << "\n");
for (int i = 0; i < sleepsecs; i++) { for (int i = 0; i < sleepsecs; i++) {
sleep(1); sleep(1);
// Check that x11 did not go away while we were sleeping. // Check that x11 did not go away while we were sleeping.
if (!(op_flags & OPT_x) && !x11IsAlive()) { if (!(op_flags & OPT_x) && !x11IsAlive()) {
LOGDEB("X11 session went away during initial sleep period\n"); LOGDEB("X11 session went away during initial sleep period\n");
exit(0); exit(0);
} }
} }
} }
if (!(op_flags & OPT_n)) { if (!(op_flags & OPT_n)) {
makeIndexerOrExit(config, inPlaceReset); makeIndexerOrExit(config, inPlaceReset);
LOGDEB("Recollindex: initial indexing pass before monitoring\n"); LOGDEB("Recollindex: initial indexing pass before monitoring\n");
if (!confindexer->index(rezero, ConfIndexer::IxTAll, indexerFlags) if (!confindexer->index(rezero, ConfIndexer::IxTAll, indexerFlags)
|| stopindexing) { || stopindexing) {
LOGERR("recollindex, initial indexing pass failed, " LOGERR("recollindex, initial indexing pass failed, "
"not going into monitor mode\n"); "not going into monitor mode\n");
flushIdxReasons(); flushIdxReasons();
exit(1); exit(1);
} else { } else {
// Record success of indexing pass with failed files retries. // Record success of indexing pass with failed files retries.
if (!(indexerFlags & ConfIndexer::IxFNoRetryFailed)) { if (!(indexerFlags & ConfIndexer::IxFNoRetryFailed)) {
checkRetryFailed(config, true); checkRetryFailed(config, true);
} }
} }
deleteZ(confindexer); deleteZ(confindexer);
#ifndef _WIN32 #ifndef _WIN32
o_reexec->insertArgs(vector<string>(1, "-n")); o_reexec->insertArgs(vector<string>(1, "-n"));
LOGINFO("recollindex: reexecuting with -n after initial full " LOGINFO("recollindex: reexecuting with -n after initial full "
"pass\n"); "pass\n");
// Note that -n will be inside the reexec when we come // Note that -n will be inside the reexec when we come
// back, but the monitor will explicitly strip it before // back, but the monitor will explicitly strip it before
// starting a config change exec to ensure that we do a // starting a config change exec to ensure that we do a
// purging pass in this latter case (full restart). // purging pass in this latter case (full restart).
o_reexec->reexec(); o_reexec->reexec();
#endif #endif
} }
if (updater) { if (updater) {
updater->status.phase = DbIxStatus::DBIXS_MONITOR; updater->status.phase = DbIxStatus::DBIXS_MONITOR;
updater->status.fn.clear(); updater->status.fn.clear();
updater->update(); updater->update();
} }
int opts = RCLMON_NONE; int opts = RCLMON_NONE;
if (op_flags & OPT_D) if (op_flags & OPT_D)
opts |= RCLMON_NOFORK; opts |= RCLMON_NOFORK;
if (op_flags & OPT_C) if (op_flags & OPT_C)
opts |= RCLMON_NOCONFCHECK; opts |= RCLMON_NOCONFCHECK;
if (op_flags & OPT_x) if (op_flags & OPT_x)
opts |= RCLMON_NOX11; opts |= RCLMON_NOX11;
bool monret = startMonitor(config, opts); bool monret = startMonitor(config, opts);
MONDEB(("Monitor returned %d, exiting\n", monret)); MONDEB(("Monitor returned %d, exiting\n", monret));
exit(monret == false); exit(monret == false);
#endif // MONITOR #endif // MONITOR
} else if (op_flags & OPT_b) { } else if (op_flags & OPT_b) {
cerr << "Not yet" << endl; cerr << "Not yet" << endl;
return 1; return 1;
} else { } else {
lockorexit(&pidfile, config); lockorexit(&pidfile, config);
makeIndexerOrExit(config, inPlaceReset); makeIndexerOrExit(config, inPlaceReset);
bool status = confindexer->index(rezero, ConfIndexer::IxTAll, bool status = confindexer->index(rezero, ConfIndexer::IxTAll,
indexerFlags); indexerFlags);
// Record success of indexing pass with failed files retries. // Record success of indexing pass with failed files retries.
if (status && !(indexerFlags & ConfIndexer::IxFNoRetryFailed)) { if (status && !(indexerFlags & ConfIndexer::IxFNoRetryFailed)) {
checkRetryFailed(config, true); checkRetryFailed(config, true);
} }
if (!status) if (!status)
cerr << "Indexing failed" << endl; cerr << "Indexing failed" << endl;
if (!confindexer->getReason().empty()) { if (!confindexer->getReason().empty()) {
addIdxReason("indexer", confindexer->getReason()); addIdxReason("indexer", confindexer->getReason());
cerr << confindexer->getReason() << endl; cerr << confindexer->getReason() << endl;
} }
if (updater) { if (updater) {
updater->status.phase = DbIxStatus::DBIXS_DONE; updater->status.phase = DbIxStatus::DBIXS_DONE;
updater->status.fn.clear(); updater->status.fn.clear();
updater->update(); updater->update();
} }
flushIdxReasons(); flushIdxReasons();
return !status; return !status;
} }
} }

View File

@ -817,18 +817,38 @@ checkneedretryindexscript = rclcheckneedretry.sh
# Example: mondelaypatterns = *.log:20 "*with spaces.*:30"</descr></var> # Example: mondelaypatterns = *.log:20 "*with spaces.*:30"</descr></var>
#mondelaypatterns = *.log:20 "*with spaces.*:30" #mondelaypatterns = *.log:20 "*with spaces.*:30"
# <var name="idxniceprio" type="int">
#
# <brief>"nice" process priority for the indexing processes. Default: 19
# (lowest)</brief>
#
# <descr>Appeared with 1.26.5. Prior versions were fixed at 19.</descr>
#
# </var>
#idxniceprio = 19
# <var name="monioniceclass" type="int"> # <var name="monioniceclass" type="int">
# #
# <brief>ionice class for the real time indexing process</brief> # <brief>ionice class for the indexing process.</brief>
# <descr>On platforms where this is supported. The default value is #
# 3.</descr></var> # <descr>Despite the misleading name, and on platforms where this is
# monioniceclass = 3 # supported, this affects all indexing processes,
# not only the real time/monitoring ones. The default value is 3 (use
# lowest "Idle" priority).</descr>
#
# </var>
#monioniceclass = 3
# <var name="monioniceclassdata" type="string"> # <var name="monioniceclassdata" type="string">
# #
# <brief>ionice class parameter for the real time indexing process.</brief> # <brief>ionice class level parameter if the class supports it.</brief>
# <descr>On platforms where this is supported. The default is #
# empty.</descr></var> # <descr>The default is empty, as the default "Idle" class has no
# levels.</descr>
#
# </var>
#
#monioniceclassdata = #monioniceclassdata =

View File

@ -29,17 +29,17 @@ bool rclionice(const string& clss, const string& cdata)
{ {
string ionicexe; string ionicexe;
if (!ExecCmd::which("ionice", ionicexe)) { if (!ExecCmd::which("ionice", ionicexe)) {
// ionice not found, bail out // ionice not found, bail out
LOGDEB0("rclionice: ionice not found\n" ); LOGDEB0("rclionice: ionice not found\n");
return false; return false;
} }
vector<string> args; vector<string> args;
args.push_back("-c"); args.push_back("-c");
args.push_back(clss); args.push_back(clss);
if (!cdata.empty()) { if (!cdata.empty()) {
args.push_back("-n"); args.push_back("-n");
args.push_back(cdata); args.push_back(cdata);
} }
char cpid[100]; char cpid[100];
@ -51,9 +51,8 @@ bool rclionice(const string& clss, const string& cdata)
int status = cmd.doexec(ionicexe, args); int status = cmd.doexec(ionicexe, args);
if (status) { if (status) {
LOGERR("rclionice: failed, status 0x" << (status) << "\n" ); LOGERR("rclionice: failed, status 0x" << status << "\n");
return false; return false;
} }
return true; return true;
} }