Let recollindex execute a script at startup to try and guess if it should retry failed files

This commit is contained in:
Jean-Francois Dockes
2015-04-24 10:46:58 +02:00
parent 95a8cd2aaa
commit 1e6f56522e
8 changed files with 209 additions and 13 deletions
+54
View File
@@ -0,0 +1,54 @@
/* Copyright (C) 2014 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#include <string>
#include <vector>
#include "rclconfig.h"
#include "execmd.h"
#include "debuglog.h"
#include "checkretryfailed.h"
using namespace std;
bool checkRetryFailed(RclConfig *conf, bool record)
{
string cmd;
if (!conf->getConfParam("checkneedretryindexscript", cmd)) {
LOGDEB(("checkRetryFailed: 'checkneedretryindexscript' "
"not set in config\n"));
// We could toss a dice ? Say no retry in this case.
return false;
}
// Look in the filters directory (ies). If not found execpath will
// be the same as cmd, and we'll let execvp do its thing.
string execpath = conf->findFilter(cmd);
vector<string> args;
if (record) {
args.push_back("1");
}
ExecCmd ecmd;
int status = ecmd.doexec(execpath, args);
if (status == 0) {
return true;
}
return false;
}
+33
View File
@@ -0,0 +1,33 @@
#ifndef _CHECKRETRYFAILED_H_INCLUDED_
#define _CHECKRETRYFAILED_H_INCLUDED_
/* Copyright (C) 2015 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/** Check if retrying failed files may be needed. We execute a
shell-script for this. The default one checks if any of the common
bin directories changed.
@param conf the config
@param record if true, record the state instead of testing
@return true if retrying should be performed
*/
class RclConfig;
bool checkRetryFailed(RclConfig *conf, bool record);
#endif /* _CHECKRETRYFAILED_H_INCLUDED_ */
+23 -4
View File
@@ -46,6 +46,7 @@ using namespace std;
#include "fsindexer.h"
#include "rclionice.h"
#include "execmd.h"
#include "checkretryfailed.h"
// Command line options
static int op_flags;
@@ -418,9 +419,17 @@ int main(int argc, char **argv)
bool rezero((op_flags & OPT_z) != 0);
bool inPlaceReset((op_flags & OPT_Z) != 0);
int indexerFlags = ConfIndexer::IxFNone;
if (!(op_flags & OPT_k))
indexerFlags |= ConfIndexer::IxFNoRetryFailed;
// We do not retry previously failed files by default. If -k is
// set, we do. If the checker script says so, we do too.
int indexerFlags = ConfIndexer::IxFNoRetryFailed;
if (op_flags & OPT_k) {
indexerFlags &= ~ConfIndexer::IxFNoRetryFailed;
} else {
if (checkRetryFailed(config, false)) {
indexerFlags &= ~ConfIndexer::IxFNoRetryFailed;
}
}
Pidfile pidfile(config->getPidfile());
updater = new MyUpdater(config);
@@ -538,7 +547,12 @@ int main(int argc, char **argv)
LOGERR(("recollindex, initial indexing pass failed, "
"not going into monitor mode\n"));
exit(1);
}
} else {
// Record success of indexing pass with failed files retries.
if (!(indexerFlags & ConfIndexer::IxFNoRetryFailed)) {
checkRetryFailed(config, true);
}
}
deleteZ(confindexer);
o_reexec->insertArgs(vector<string>(1, "-n"));
LOGINFO(("recollindex: reexecuting with -n after initial full pass\n"));
@@ -573,6 +587,11 @@ int main(int argc, char **argv)
makeIndexerOrExit(config, inPlaceReset);
bool status = confindexer->index(rezero, ConfIndexer::IxTAll,
indexerFlags);
// Record success of indexing pass with failed files retries.
if (status && !(indexerFlags & ConfIndexer::IxFNoRetryFailed)) {
checkRetryFailed(config, true);
}
if (!status)
cerr << "Indexing failed" << endl;
if (!confindexer->getReason().empty())