2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-09-13 18:10:23 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2004-09-13 18:10:23 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software 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 Lesser General Public License for more details.
|
2004-09-13 18:10:23 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-09-13 18:10:23 +00:00
|
|
|
|
2004-12-27 06:54:23 +00:00
|
|
|
// db_purge options
|
|
|
|
//
|
|
|
|
// purge workunit and result records that are no longer needed.
|
|
|
|
// Specifically, purges WUs for which file_delete_state=DONE;
|
|
|
|
// this occurs only when it has been assimilated
|
|
|
|
// and all results have server_state=OVER.
|
|
|
|
// Purging a WU means writing it and all its results
|
|
|
|
// to XML-format archive files, then deleting it and its results from the DB.
|
|
|
|
//
|
|
|
|
// The XML files have names of the form
|
|
|
|
// wu_archive_TIME and result_archive_TIME
|
|
|
|
// where TIME is the time it was created.
|
|
|
|
// In addition there are index files associating each WU and result ID
|
|
|
|
// with the timestamp of the file it's in.
|
|
|
|
//
|
|
|
|
// Options:
|
|
|
|
//
|
2004-12-27 21:14:18 +00:00
|
|
|
// -min_age_days n purge WUs with mod_time at least N days in the past
|
2004-12-27 06:54:23 +00:00
|
|
|
// -max n purge at most N WUs
|
2005-07-17 19:52:44 +00:00
|
|
|
// -one_pass go until nothing left to purge, then exit
|
2004-12-27 06:54:23 +00:00
|
|
|
// default: keep scanning indefinitely
|
|
|
|
// -max_wu_per_file n write at most N WUs to an archive file
|
|
|
|
// The file is then closed and another file is opened.
|
|
|
|
// This can be used to get a series of small files
|
|
|
|
// instead of one huge file.
|
|
|
|
// -zip
|
|
|
|
// compress output files using zip. If used with
|
|
|
|
// -max_wu_per_file then the files get compressed after
|
|
|
|
// being closed. In any case the files are compressed
|
|
|
|
// when db_purge exits on a signal.
|
|
|
|
// -gzip
|
|
|
|
// compress output files using gzip. If used with
|
|
|
|
// -max_wu_per_file then the files get compressed after
|
|
|
|
// being closed. In any case the files are compressed
|
|
|
|
// when db_purge exits on a signal.
|
2004-10-20 19:38:10 +00:00
|
|
|
|
2006-06-01 13:51:10 +00:00
|
|
|
// -sleep N // when done with a pass of purging the DB, sleep
|
|
|
|
// for N seconds before the next pass. Default
|
|
|
|
// value is 600 seconds.
|
2005-11-21 18:34:44 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2004-09-13 18:10:23 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <ctime>
|
2004-09-13 21:56:02 +00:00
|
|
|
#include <string>
|
2004-10-18 23:33:04 +00:00
|
|
|
#include <time.h>
|
2004-12-07 22:54:54 +00:00
|
|
|
#include <errno.h>
|
2004-09-13 21:56:02 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2004-09-13 18:10:23 +00:00
|
|
|
|
|
|
|
#include "boinc_db.h"
|
|
|
|
#include "util.h"
|
2007-06-26 21:14:58 +00:00
|
|
|
#include "filesys.h"
|
2004-09-13 18:10:23 +00:00
|
|
|
#include "parse.h"
|
|
|
|
#include "sched_config.h"
|
|
|
|
#include "sched_util.h"
|
2004-09-13 21:56:02 +00:00
|
|
|
#include "sched_msgs.h"
|
2004-09-13 18:10:23 +00:00
|
|
|
|
2004-09-13 21:56:02 +00:00
|
|
|
#include "error_numbers.h"
|
2004-09-13 18:10:23 +00:00
|
|
|
|
2004-10-18 23:33:04 +00:00
|
|
|
#define WU_FILENAME_PREFIX "wu_archive"
|
|
|
|
#define RESULT_FILENAME_PREFIX "result_archive"
|
|
|
|
#define WU_INDEX_FILENAME_PREFIX "wu_index"
|
|
|
|
#define RESULT_INDEX_FILENAME_PREFIX "result_index"
|
2004-09-13 18:10:23 +00:00
|
|
|
|
2004-10-18 23:33:04 +00:00
|
|
|
#define DB_QUERY_LIMIT 1000
|
2004-09-13 18:10:23 +00:00
|
|
|
|
2004-12-07 22:54:54 +00:00
|
|
|
#define COMPRESSION_NONE 0
|
|
|
|
#define COMPRESSION_GZIP 1
|
|
|
|
#define COMPRESSION_ZIP 2
|
2004-10-20 20:54:14 +00:00
|
|
|
|
2007-08-21 20:07:50 +00:00
|
|
|
SCHED_CONFIG config;
|
|
|
|
FILE *wu_stream=NULL;
|
|
|
|
FILE *re_stream=NULL;
|
|
|
|
FILE *wu_index_stream=NULL;
|
|
|
|
FILE *re_index_stream=NULL;
|
|
|
|
int time_int=0;
|
|
|
|
int min_age_days=0;
|
|
|
|
bool no_archive = false;
|
|
|
|
int purged_workunits= 0;
|
|
|
|
// used if limiting the total number of workunits to eliminate
|
|
|
|
int max_number_workunits_to_purge=0;
|
|
|
|
// If nonzero, maximum number of workunits to purge.
|
|
|
|
// Since all results associated with a purged workunit are also purged,
|
|
|
|
// this also limits the number of purged results.
|
2005-02-16 23:17:43 +00:00
|
|
|
const char *suffix[3]={"", ".gz", ".zip"};
|
2007-08-21 20:07:50 +00:00
|
|
|
// subscripts MUST be in agreement with defines above
|
2004-12-27 21:53:38 +00:00
|
|
|
int compression_type=COMPRESSION_NONE;
|
2004-12-07 22:54:54 +00:00
|
|
|
int max_wu_per_file=0;
|
2007-08-21 20:07:50 +00:00
|
|
|
// set on command line if archive files should be closed and re-opened
|
|
|
|
// after getting some max no of WU in the file
|
2004-12-07 22:54:54 +00:00
|
|
|
int wu_stored_in_file=0;
|
2007-08-21 20:07:50 +00:00
|
|
|
// keep track of how many WU archived in file so far
|
2004-12-07 22:54:54 +00:00
|
|
|
|
2004-12-27 06:54:23 +00:00
|
|
|
bool time_to_quit() {
|
|
|
|
if (max_number_workunits_to_purge) {
|
|
|
|
if (purged_workunits >= max_number_workunits_to_purge) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-08-11 00:17:00 +00:00
|
|
|
// Open an archive. Only subtle thing is that if the user has
|
2004-12-07 22:54:54 +00:00
|
|
|
// asked for compression, then we popen(2) a pipe to gzip or zip.
|
|
|
|
// This does 'in place' compression.
|
|
|
|
//
|
2005-02-16 23:17:43 +00:00
|
|
|
void open_archive(const char* filename_prefix, FILE*& f){
|
2004-12-07 22:54:54 +00:00
|
|
|
char path[256];
|
|
|
|
char command[512];
|
|
|
|
|
|
|
|
// append appropriate suffix for file type
|
|
|
|
sprintf(path, "../archives/%s_%d.xml", filename_prefix, time_int);
|
2004-12-27 21:53:38 +00:00
|
|
|
strcat(path, suffix[compression_type]);
|
2004-12-07 22:54:54 +00:00
|
|
|
|
|
|
|
// and construct appropriate command if needed
|
2004-12-27 21:53:38 +00:00
|
|
|
if (compression_type==COMPRESSION_GZIP) {
|
2004-12-07 22:54:54 +00:00
|
|
|
sprintf(command, "gzip - > %s", path);
|
2004-12-27 06:54:23 +00:00
|
|
|
}
|
2004-12-07 22:54:54 +00:00
|
|
|
|
2004-12-27 21:53:38 +00:00
|
|
|
if (compression_type==COMPRESSION_ZIP) {
|
2004-12-07 22:54:54 +00:00
|
|
|
sprintf(command, "zip %s -", path);
|
2004-12-27 06:54:23 +00:00
|
|
|
}
|
2004-09-13 19:05:19 +00:00
|
|
|
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
|
|
|
|
"Opening archive %s\n", path
|
|
|
|
);
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2004-12-07 22:54:54 +00:00
|
|
|
// in the case with no compression, just open the file, else open
|
|
|
|
// a pipe to the compression executable.
|
2004-12-27 06:54:23 +00:00
|
|
|
//
|
2004-12-27 21:53:38 +00:00
|
|
|
if (compression_type==COMPRESSION_NONE) {
|
2004-12-07 22:54:54 +00:00
|
|
|
if (!(f = fopen( path,"w"))) {
|
2004-12-27 06:54:23 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,"Can't open archive file %s %s\n",
|
2004-12-27 06:54:23 +00:00
|
|
|
path, errno?strerror(errno):""
|
|
|
|
);
|
2004-12-07 22:54:54 +00:00
|
|
|
exit(3);
|
|
|
|
}
|
2004-12-27 06:54:23 +00:00
|
|
|
} else if (!(f = popen(command,"w"))) {
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,"Can't open pipe %s %s\n",
|
2004-12-27 06:54:23 +00:00
|
|
|
command, errno?strerror(errno):""
|
|
|
|
);
|
2004-12-07 22:54:54 +00:00
|
|
|
exit(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set buffering to line buffered, since we are outputing XML on a
|
|
|
|
// line-by-line basis.
|
|
|
|
//
|
|
|
|
setlinebuf(f);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
void close_archive(const char *filename, FILE*& fp){
|
2004-12-07 22:54:54 +00:00
|
|
|
char path[256];
|
|
|
|
|
2004-12-27 06:54:23 +00:00
|
|
|
// Set file pointer to NULL after closing file to indicate that it's closed.
|
|
|
|
//
|
|
|
|
if (!fp) return;
|
2004-12-07 22:54:54 +00:00
|
|
|
|
|
|
|
// In case of errors, carry on anyway. This is deliberate, not lazy
|
2004-12-27 06:54:23 +00:00
|
|
|
//
|
2004-12-27 21:53:38 +00:00
|
|
|
if (compression_type==COMPRESSION_NONE) {
|
2004-12-07 22:54:54 +00:00
|
|
|
fclose(fp);
|
2004-12-27 06:54:23 +00:00
|
|
|
} else {
|
2004-12-07 22:54:54 +00:00
|
|
|
pclose(fp);
|
2004-12-27 06:54:23 +00:00
|
|
|
}
|
2004-12-07 22:54:54 +00:00
|
|
|
|
2005-08-11 00:17:00 +00:00
|
|
|
fp = NULL;
|
2004-12-07 22:54:54 +00:00
|
|
|
|
|
|
|
// append appropriate file type
|
|
|
|
sprintf(path, "../archives/%s_%d.xml", filename, time_int);
|
2004-12-27 21:53:38 +00:00
|
|
|
strcat(path, suffix[compression_type]);
|
2004-12-07 22:54:54 +00:00
|
|
|
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
|
2004-12-07 22:54:54 +00:00
|
|
|
"Closed archive file %s containing records of %d workunits\n",
|
2004-12-27 06:54:23 +00:00
|
|
|
path, wu_stored_in_file
|
|
|
|
);
|
2004-09-13 21:56:02 +00:00
|
|
|
|
2004-12-07 22:54:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// opens the various archive files. Guarantees that the timestamp
|
|
|
|
// does not equal the previous timestamp
|
|
|
|
//
|
|
|
|
void open_all_archives() {
|
|
|
|
int old_time=time_int;
|
|
|
|
|
|
|
|
// make sure we get a NEW value of the file timestamp!
|
2005-08-11 00:17:00 +00:00
|
|
|
//
|
2004-12-27 06:54:23 +00:00
|
|
|
while (old_time == (time_int = (int)time(0))) {
|
2004-12-07 22:54:54 +00:00
|
|
|
sleep(1);
|
2004-12-27 06:54:23 +00:00
|
|
|
}
|
2004-12-07 22:54:54 +00:00
|
|
|
|
|
|
|
// open all the archives.
|
2005-08-11 00:17:00 +00:00
|
|
|
open_archive(WU_FILENAME_PREFIX, wu_stream);
|
|
|
|
open_archive(RESULT_FILENAME_PREFIX, re_stream);
|
2004-12-07 22:54:54 +00:00
|
|
|
open_archive(RESULT_INDEX_FILENAME_PREFIX, re_index_stream);
|
2005-08-11 00:17:00 +00:00
|
|
|
open_archive(WU_INDEX_FILENAME_PREFIX, wu_index_stream);
|
|
|
|
fprintf(wu_stream, "<archive>\n");
|
|
|
|
fprintf(re_stream, "<archive>\n");
|
2004-12-07 22:54:54 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2004-10-18 23:33:04 +00:00
|
|
|
|
2004-12-07 22:54:54 +00:00
|
|
|
// closes (and optionally compresses) the archive files. Clears file
|
|
|
|
// pointers to indicate that files are not open.
|
|
|
|
//
|
|
|
|
void close_all_archives() {
|
2007-09-08 21:34:20 +00:00
|
|
|
if (wu_stream) fprintf(wu_stream, "</archive>\n");
|
|
|
|
if (re_stream) fprintf(re_stream, "</archive>\n");
|
2005-08-11 00:17:00 +00:00
|
|
|
close_archive(WU_FILENAME_PREFIX, wu_stream);
|
|
|
|
close_archive(RESULT_FILENAME_PREFIX, re_stream);
|
2004-12-07 22:54:54 +00:00
|
|
|
close_archive(RESULT_INDEX_FILENAME_PREFIX, re_index_stream);
|
2005-08-11 00:17:00 +00:00
|
|
|
close_archive(WU_INDEX_FILENAME_PREFIX, wu_index_stream);
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
|
2004-12-08 11:17:41 +00:00
|
|
|
"Closed archive files with %d workunits\n",
|
|
|
|
wu_stored_in_file
|
|
|
|
);
|
2004-09-13 21:56:02 +00:00
|
|
|
|
2004-12-07 22:54:54 +00:00
|
|
|
return;
|
2004-09-13 18:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-07 22:54:54 +00:00
|
|
|
// The exit handler always calls this at the end to be sure that the
|
|
|
|
// database is closed cleanly.
|
2005-08-11 00:17:00 +00:00
|
|
|
//
|
2004-12-07 22:54:54 +00:00
|
|
|
void close_db_exit_handler() {
|
|
|
|
boinc_db.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-09-13 21:56:02 +00:00
|
|
|
int archive_result(DB_RESULT& result) {
|
2004-09-13 18:10:23 +00:00
|
|
|
fprintf(re_stream,
|
2004-09-20 21:05:45 +00:00
|
|
|
"<result_archive>\n"
|
2004-09-13 18:10:23 +00:00
|
|
|
" <id>%d</id>\n",
|
|
|
|
result.id
|
|
|
|
);
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2006-06-01 19:59:57 +00:00
|
|
|
// xml_escape can increase size by factor of 6, e.g. x -> &#NNN;
|
|
|
|
//
|
|
|
|
char buf[LARGE_BLOB_SIZE*6];
|
2006-04-17 22:41:29 +00:00
|
|
|
xml_escape(result.stderr_out, buf);
|
2004-09-13 19:05:19 +00:00
|
|
|
|
2004-09-13 21:56:02 +00:00
|
|
|
fprintf(
|
|
|
|
re_stream,
|
|
|
|
" <create_time>%d</create_time>\n"
|
|
|
|
" <workunitid>%d</workunitid>\n"
|
|
|
|
" <server_state>%d</server_state>\n"
|
|
|
|
" <outcome>%d</outcome>\n"
|
|
|
|
" <client_state>%d</client_state>\n"
|
|
|
|
" <hostid>%d</hostid>\n"
|
|
|
|
" <userid>%d</userid>\n"
|
|
|
|
" <report_deadline>%d</report_deadline>\n"
|
|
|
|
" <sent_time>%d</sent_time>\n"
|
|
|
|
" <received_time>%d</received_time>\n"
|
|
|
|
" <name>%s</name>\n"
|
2004-09-13 22:00:45 +00:00
|
|
|
" <cpu_time>%.15e</cpu_time>\n"
|
|
|
|
" <xml_doc_in>%s</xml_doc_in>\n"
|
|
|
|
" <xml_doc_out>%s</xml_doc_out>\n"
|
|
|
|
" <stderr_out>%s</stderr_out>\n"
|
|
|
|
" <batch>%d</batch>\n"
|
|
|
|
" <file_delete_state>%d</file_delete_state>\n"
|
|
|
|
" <validate_state>%d</validate_state>\n"
|
|
|
|
" <claimed_credit>%.15e</claimed_credit>\n"
|
|
|
|
" <granted_credit>%.15e</granted_credit>\n"
|
|
|
|
" <opaque>%f</opaque>\n"
|
|
|
|
" <random>%d</random>\n"
|
|
|
|
" <app_version_num>%d</app_version_num>\n"
|
|
|
|
" <appid>%d</appid>\n"
|
|
|
|
" <exit_status>%d</exit_status>\n"
|
2004-12-06 22:41:19 +00:00
|
|
|
" <teamid>%d</teamid>\n"
|
|
|
|
" <priority>%d</priority>\n"
|
|
|
|
" <mod_time>%s</mod_time>\n",
|
|
|
|
result.create_time,
|
2004-09-13 22:00:45 +00:00
|
|
|
result.workunitid,
|
2004-12-06 22:41:19 +00:00
|
|
|
result.server_state,
|
2004-09-13 22:00:45 +00:00
|
|
|
result.outcome,
|
|
|
|
result.client_state,
|
2004-12-06 22:41:19 +00:00
|
|
|
result.hostid,
|
2004-09-13 22:00:45 +00:00
|
|
|
result.userid,
|
2004-12-06 22:41:19 +00:00
|
|
|
result.report_deadline,
|
|
|
|
result.sent_time,
|
2004-09-13 22:00:45 +00:00
|
|
|
result.received_time,
|
2004-12-06 22:41:19 +00:00
|
|
|
result.name,
|
2004-09-13 22:00:45 +00:00
|
|
|
result.cpu_time,
|
2004-12-06 22:41:19 +00:00
|
|
|
result.xml_doc_in,
|
|
|
|
result.xml_doc_out,
|
2006-04-17 22:41:29 +00:00
|
|
|
buf,
|
2004-12-06 22:41:19 +00:00
|
|
|
result.batch,
|
|
|
|
result.file_delete_state,
|
2004-09-13 22:00:45 +00:00
|
|
|
result.validate_state,
|
2004-12-06 22:41:19 +00:00
|
|
|
result.claimed_credit,
|
|
|
|
result.granted_credit,
|
|
|
|
result.opaque,
|
2004-09-13 22:00:45 +00:00
|
|
|
result.random,
|
2004-12-06 22:41:19 +00:00
|
|
|
result.app_version_num,
|
|
|
|
result.appid,
|
|
|
|
result.exit_status,
|
|
|
|
result.teamid,
|
|
|
|
result.priority,
|
|
|
|
result.mod_time
|
2004-09-13 22:00:45 +00:00
|
|
|
);
|
2004-09-13 18:10:23 +00:00
|
|
|
|
|
|
|
fprintf(re_stream,
|
2004-09-20 21:05:45 +00:00
|
|
|
"</result_archive>\n"
|
2004-09-13 18:10:23 +00:00
|
|
|
);
|
2004-10-18 23:33:04 +00:00
|
|
|
|
|
|
|
fprintf(re_index_stream,
|
|
|
|
"%d %d\n",
|
|
|
|
result.id, time_int
|
|
|
|
);
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2004-09-13 21:56:02 +00:00
|
|
|
return 0;
|
2004-09-13 18:10:23 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 21:56:02 +00:00
|
|
|
int archive_wu(DB_WORKUNIT& wu) {
|
2004-09-13 18:10:23 +00:00
|
|
|
fprintf(wu_stream,
|
2004-09-20 21:05:45 +00:00
|
|
|
"<workunit_archive>\n"
|
2004-09-13 18:10:23 +00:00
|
|
|
" <id>%d</id>\n",
|
|
|
|
wu.id
|
|
|
|
);
|
2004-09-13 21:56:02 +00:00
|
|
|
fprintf(wu_stream,
|
|
|
|
" <create_time>%d</create_time>\n"
|
|
|
|
" <appid>%d</appid>\n"
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
" <xml_doc>%s</xml_doc>\n"
|
|
|
|
" <batch>%d</batch>\n"
|
|
|
|
" <rsc_fpops_est>%.15e</rsc_fpops_est>\n"
|
|
|
|
" <rsc_fpops_bound>%.15e</rsc_fpops_bound>\n"
|
|
|
|
" <rsc_memory_bound>%.15e</rsc_memory_bound>\n"
|
|
|
|
" <rsc_disk_bound>%.15e</rsc_disk_bound>\n"
|
|
|
|
" <need_validate>%d</need_validate>\n"
|
|
|
|
" <canonical_resultid>%d</canonical_resultid>\n"
|
|
|
|
" <canonical_credit>%.15e</canonical_credit>\n"
|
|
|
|
" <transition_time>%d</transition_time>\n"
|
|
|
|
" <delay_bound>%d</delay_bound>\n"
|
|
|
|
" <error_mask>%d</error_mask>\n"
|
|
|
|
" <file_delete_state>%d</file_delete_state>\n"
|
|
|
|
" <assimilate_state>%d</assimilate_state>\n"
|
2004-12-06 22:41:19 +00:00
|
|
|
" <hr_class>%d</hr_class>\n"
|
2004-09-13 22:00:45 +00:00
|
|
|
" <opaque>%f</opaque>\n"
|
|
|
|
" <min_quorum>%d</min_quorum>\n"
|
|
|
|
" <target_nresults>%d</target_nresults>\n"
|
|
|
|
" <max_error_results>%d</max_error_results>\n"
|
|
|
|
" <max_total_results>%d</max_total_results>\n"
|
|
|
|
" <max_success_results>%d</max_success_results>\n"
|
2004-12-06 22:41:19 +00:00
|
|
|
" <result_template_file>%s</result_template_file>\n"
|
|
|
|
" <priority>%d</priority>\n"
|
|
|
|
" <mod_time>%s</mod_time>\n",
|
|
|
|
wu.create_time,
|
2004-09-13 21:56:02 +00:00
|
|
|
wu.appid,
|
2004-12-06 22:41:19 +00:00
|
|
|
wu.name,
|
|
|
|
wu.xml_doc,
|
2004-09-13 22:00:45 +00:00
|
|
|
wu.batch,
|
2004-12-06 22:41:19 +00:00
|
|
|
wu.rsc_fpops_est,
|
|
|
|
wu.rsc_fpops_bound,
|
|
|
|
wu.rsc_memory_bound,
|
2004-09-13 22:00:45 +00:00
|
|
|
wu.rsc_disk_bound,
|
|
|
|
wu.need_validate,
|
2004-12-06 22:41:19 +00:00
|
|
|
wu.canonical_resultid,
|
2004-09-13 22:00:45 +00:00
|
|
|
wu.canonical_credit,
|
2004-12-06 22:41:19 +00:00
|
|
|
wu.transition_time,
|
2004-09-13 22:00:45 +00:00
|
|
|
wu.delay_bound,
|
2004-12-06 22:41:19 +00:00
|
|
|
wu.error_mask,
|
|
|
|
wu.file_delete_state,
|
2004-09-13 22:00:45 +00:00
|
|
|
wu.assimilate_state,
|
2004-12-06 22:41:19 +00:00
|
|
|
wu.hr_class,
|
2004-09-13 22:00:45 +00:00
|
|
|
wu.opaque,
|
|
|
|
wu.min_quorum,
|
|
|
|
wu.target_nresults,
|
|
|
|
wu.max_error_results,
|
|
|
|
wu.max_total_results,
|
|
|
|
wu.max_success_results,
|
2004-12-06 22:41:19 +00:00
|
|
|
wu.result_template_file,
|
|
|
|
wu.priority,
|
|
|
|
wu.mod_time
|
2004-09-13 21:56:02 +00:00
|
|
|
);
|
2004-09-13 18:10:23 +00:00
|
|
|
|
|
|
|
fprintf(wu_stream,
|
2004-09-20 21:05:45 +00:00
|
|
|
"</workunit_archive>\n"
|
2004-09-13 18:10:23 +00:00
|
|
|
);
|
2004-10-18 23:33:04 +00:00
|
|
|
|
|
|
|
fprintf(wu_index_stream,
|
|
|
|
"%d %d\n",
|
|
|
|
wu.id, time_int
|
|
|
|
);
|
|
|
|
|
2004-09-13 21:56:02 +00:00
|
|
|
return 0;
|
2004-09-13 18:10:23 +00:00
|
|
|
}
|
|
|
|
|
2004-09-13 19:05:19 +00:00
|
|
|
int purge_and_archive_results(DB_WORKUNIT& wu, int& number_results) {
|
2004-09-13 21:56:02 +00:00
|
|
|
int retval= 0;
|
2004-09-13 18:10:23 +00:00
|
|
|
DB_RESULT result;
|
2004-09-13 21:56:02 +00:00
|
|
|
char buf[256];
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2004-09-13 21:56:02 +00:00
|
|
|
number_results=0;
|
2004-09-13 19:05:19 +00:00
|
|
|
|
2004-10-18 23:33:04 +00:00
|
|
|
sprintf(buf, "where workunitid=%d", wu.id);
|
2004-09-13 21:56:02 +00:00
|
|
|
while (!result.enumerate(buf)) {
|
2007-08-21 20:07:50 +00:00
|
|
|
if (!no_archive) {
|
|
|
|
retval= archive_result(result);
|
|
|
|
if (retval) return retval;
|
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::MSG_DEBUG,
|
|
|
|
"Archived result [%d] to a file\n", result.id
|
|
|
|
);
|
|
|
|
}
|
2004-12-27 06:54:23 +00:00
|
|
|
retval= result.delete_from_db();
|
|
|
|
if (retval) return retval;
|
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_DEBUG,
|
2004-12-27 06:54:23 +00:00
|
|
|
"Purged result [%d] from database\n", result.id
|
|
|
|
);
|
|
|
|
number_results++;
|
2004-09-13 21:56:02 +00:00
|
|
|
}
|
2004-09-13 19:05:19 +00:00
|
|
|
return 0;
|
2004-09-13 18:10:23 +00:00
|
|
|
}
|
|
|
|
|
2004-12-27 06:54:23 +00:00
|
|
|
// return true if did anything
|
2004-10-20 19:38:10 +00:00
|
|
|
//
|
|
|
|
bool do_pass() {
|
2004-09-13 18:10:23 +00:00
|
|
|
int retval= 0;
|
2004-12-07 22:54:54 +00:00
|
|
|
|
2004-12-27 06:54:23 +00:00
|
|
|
// The number of workunits/results purged in a single pass of do_pass().
|
|
|
|
// Since do_pass() may be invoked multiple times,
|
2004-11-30 15:58:34 +00:00
|
|
|
// corresponding global variables store global totals.
|
|
|
|
//
|
|
|
|
int do_pass_purged_workunits = 0;
|
|
|
|
int do_pass_purged_results = 0;
|
2004-10-20 22:12:30 +00:00
|
|
|
|
2004-12-27 06:54:23 +00:00
|
|
|
// check to see if we got a stop signal.
|
|
|
|
// Note that if we do catch a stop signal here,
|
|
|
|
// we call an exit handler that closes [and optionally compresses] files
|
|
|
|
// before returning to the OS.
|
2004-12-07 22:54:54 +00:00
|
|
|
//
|
2004-10-20 19:38:10 +00:00
|
|
|
check_stop_daemons();
|
2004-10-18 23:33:04 +00:00
|
|
|
|
2004-09-13 21:56:02 +00:00
|
|
|
bool did_something = false;
|
|
|
|
DB_WORKUNIT wu;
|
2004-09-13 18:10:23 +00:00
|
|
|
char buf[256];
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2004-12-27 21:14:18 +00:00
|
|
|
if (min_age_days) {
|
|
|
|
char timestamp[15];
|
|
|
|
mysql_timestamp(dtime()-min_age_days*86400, timestamp);
|
|
|
|
sprintf(buf,
|
|
|
|
"where file_delete_state=%d and mod_time<'%s' limit %d",
|
|
|
|
FILE_DELETE_DONE, timestamp, DB_QUERY_LIMIT
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
sprintf(buf,
|
|
|
|
"where file_delete_state=%d limit %d",
|
|
|
|
FILE_DELETE_DONE, DB_QUERY_LIMIT
|
|
|
|
);
|
|
|
|
}
|
2004-11-30 15:58:34 +00:00
|
|
|
|
2004-12-27 06:54:23 +00:00
|
|
|
int n=0;
|
2004-09-13 21:56:02 +00:00
|
|
|
while (!wu.enumerate(buf)) {
|
2005-01-29 23:29:54 +00:00
|
|
|
if (strstr(wu.name, "nodelete")) continue;
|
2004-09-13 18:10:23 +00:00
|
|
|
did_something = true;
|
2004-12-07 22:54:54 +00:00
|
|
|
|
|
|
|
// if archives have not already been opened, then open them.
|
2007-08-21 20:07:50 +00:00
|
|
|
//
|
|
|
|
if (!no_archive && !wu_stream) {
|
2004-12-07 22:54:54 +00:00
|
|
|
open_all_archives();
|
2004-12-27 06:54:23 +00:00
|
|
|
}
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2004-09-13 19:05:19 +00:00
|
|
|
retval = purge_and_archive_results(wu, n);
|
2004-11-30 15:58:34 +00:00
|
|
|
do_pass_purged_results += n;
|
|
|
|
|
2007-08-21 20:07:50 +00:00
|
|
|
if (!no_archive) {
|
|
|
|
retval= archive_wu(wu);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
|
|
|
|
"Failed to write to XML file workunit:%d\n", wu.id
|
|
|
|
);
|
|
|
|
exit(5);
|
|
|
|
}
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
|
|
|
|
"Archived workunit [%d] to a file\n", wu.id
|
2004-09-13 22:00:45 +00:00
|
|
|
);
|
|
|
|
}
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2007-08-21 20:07:50 +00:00
|
|
|
// purge workunit from DB
|
|
|
|
//
|
2004-09-13 18:10:23 +00:00
|
|
|
retval= wu.delete_from_db();
|
2004-09-13 22:00:45 +00:00
|
|
|
if (retval) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
|
|
|
|
"Can't delete workunit [%d] from database:%d\n", wu.id, retval
|
|
|
|
);
|
2004-12-07 22:54:54 +00:00
|
|
|
exit(6);
|
2004-09-13 22:00:45 +00:00
|
|
|
}
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
|
|
|
|
"Purged workunit [%d] from database\n", wu.id
|
|
|
|
);
|
2004-09-13 18:10:23 +00:00
|
|
|
|
|
|
|
purged_workunits++;
|
2004-11-30 15:58:34 +00:00
|
|
|
do_pass_purged_workunits++;
|
2004-12-07 22:54:54 +00:00
|
|
|
wu_stored_in_file++;
|
|
|
|
|
2007-08-21 20:07:50 +00:00
|
|
|
if (!no_archive) {
|
|
|
|
fflush(NULL);
|
2004-11-30 15:58:34 +00:00
|
|
|
|
2007-08-21 20:07:50 +00:00
|
|
|
// if file has got max # of workunits, close and compress it.
|
|
|
|
// This sets file pointers to NULL
|
|
|
|
//
|
|
|
|
if (max_wu_per_file && wu_stored_in_file>=max_wu_per_file) {
|
|
|
|
close_all_archives();
|
|
|
|
wu_stored_in_file=0;
|
|
|
|
}
|
2004-12-07 22:54:54 +00:00
|
|
|
}
|
2004-11-30 15:58:34 +00:00
|
|
|
|
2004-12-27 06:54:23 +00:00
|
|
|
if (time_to_quit()) {
|
2004-10-20 20:54:14 +00:00
|
|
|
break;
|
2004-12-27 06:54:23 +00:00
|
|
|
}
|
2004-10-20 20:54:14 +00:00
|
|
|
|
2004-09-13 18:10:23 +00:00
|
|
|
}
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2005-08-12 19:19:46 +00:00
|
|
|
if (do_pass_purged_workunits) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
|
2005-02-17 03:17:49 +00:00
|
|
|
"Archived %d workunits and %d results\n",
|
2007-08-21 20:07:50 +00:00
|
|
|
do_pass_purged_workunits, do_pass_purged_results
|
2005-02-17 03:17:49 +00:00
|
|
|
);
|
2005-08-12 19:19:46 +00:00
|
|
|
}
|
2004-10-18 23:33:04 +00:00
|
|
|
|
2005-02-17 03:17:49 +00:00
|
|
|
if (did_something && wu_stored_in_file>0) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
|
2004-12-08 11:59:31 +00:00
|
|
|
"Currently open archive files contain %d workunits\n",
|
2007-08-21 20:07:50 +00:00
|
|
|
wu_stored_in_file
|
|
|
|
);
|
2004-12-08 11:59:31 +00:00
|
|
|
}
|
|
|
|
|
2005-08-12 19:19:46 +00:00
|
|
|
if (do_pass_purged_workunits > DB_QUERY_LIMIT/2) {
|
2007-08-21 20:07:50 +00:00
|
|
|
return true;
|
2005-08-12 19:19:46 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2004-10-20 19:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
int retval;
|
2007-04-18 20:49:58 +00:00
|
|
|
bool one_pass = false;
|
2004-10-20 19:38:10 +00:00
|
|
|
int i;
|
2006-06-01 13:51:10 +00:00
|
|
|
int sleep_sec = 600;
|
2004-10-20 19:38:10 +00:00
|
|
|
check_stop_daemons();
|
|
|
|
for (i=1; i<argc; i++) {
|
2007-04-18 20:49:58 +00:00
|
|
|
if (!strcmp(argv[i], "-one_pass")) {
|
2004-10-20 19:38:10 +00:00
|
|
|
one_pass = true;
|
|
|
|
} else if (!strcmp(argv[i], "-d")) {
|
|
|
|
log_messages.set_debug_level(atoi(argv[++i]));
|
2004-12-27 21:14:18 +00:00
|
|
|
} else if (!strcmp(argv[i], "-min_age_days")) {
|
|
|
|
min_age_days = atoi(argv[++i]);
|
2004-10-20 20:54:14 +00:00
|
|
|
} else if (!strcmp(argv[i], "-max")) {
|
|
|
|
max_number_workunits_to_purge= atoi(argv[++i]);
|
2004-12-07 22:54:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-zip")) {
|
2004-12-27 21:53:38 +00:00
|
|
|
compression_type=COMPRESSION_ZIP;
|
2004-12-07 22:54:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-gzip")) {
|
2004-12-27 21:53:38 +00:00
|
|
|
compression_type=COMPRESSION_GZIP;
|
2004-12-07 22:54:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-max_wu_per_file")) {
|
|
|
|
max_wu_per_file = atoi(argv[++i]);
|
2007-08-21 20:07:50 +00:00
|
|
|
} else if (!strcmp(argv[i], "-no_archive")) {
|
|
|
|
no_archive = true;
|
2006-06-01 13:51:10 +00:00
|
|
|
} else if (!strcmp(argv[i], "-sleep")) {
|
|
|
|
sleep_sec = atoi(argv[++i]);
|
|
|
|
if (sleep_sec < 1 || sleep_sec > 86400) {
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
|
|
|
|
"Unreasonable value of sleep interval: %d seconds\n",
|
|
|
|
sleep_sec
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-10-20 19:38:10 +00:00
|
|
|
} else {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
|
|
|
|
"Unrecognized arg: %s\n", argv[i]
|
2004-10-20 19:38:10 +00:00
|
|
|
);
|
2004-12-27 21:14:18 +00:00
|
|
|
exit(1);
|
2004-12-06 22:41:19 +00:00
|
|
|
}
|
2004-10-20 19:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retval = config.parse_file("..");
|
|
|
|
if (retval) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
|
2004-10-20 19:38:10 +00:00
|
|
|
"Can't parse config file\n"
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL, "Starting\n");
|
2004-10-20 19:38:10 +00:00
|
|
|
|
2004-12-27 06:54:23 +00:00
|
|
|
retval = boinc_db.open(
|
|
|
|
config.db_name, config.db_host, config.db_user, config.db_passwd
|
|
|
|
);
|
2004-10-20 19:38:10 +00:00
|
|
|
if (retval) {
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "Can't open DB\n");
|
2004-12-07 22:54:54 +00:00
|
|
|
exit(2);
|
2004-10-20 19:38:10 +00:00
|
|
|
}
|
|
|
|
install_stop_signal_handler();
|
2007-06-26 21:14:58 +00:00
|
|
|
boinc_mkdir("../archives");
|
2004-10-20 19:38:10 +00:00
|
|
|
|
2004-12-07 22:54:54 +00:00
|
|
|
// on exit, either via the check_stop_daemons signal handler, or
|
|
|
|
// through a regular call to exit, these functions will be called
|
|
|
|
// in the opposite order of registration.
|
2004-12-27 06:54:23 +00:00
|
|
|
//
|
2004-12-07 22:54:54 +00:00
|
|
|
atexit(close_db_exit_handler);
|
|
|
|
atexit(close_all_archives);
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2005-07-17 19:52:44 +00:00
|
|
|
while (1) {
|
|
|
|
if (time_to_quit()) {
|
|
|
|
break;
|
2004-10-20 19:38:10 +00:00
|
|
|
}
|
2005-07-17 19:52:44 +00:00
|
|
|
if (!do_pass()) {
|
|
|
|
if (one_pass) break;
|
2005-09-26 23:28:48 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
|
2005-08-12 19:19:46 +00:00
|
|
|
"Sleeping....\n"
|
|
|
|
);
|
2006-06-01 13:51:10 +00:00
|
|
|
sleep(sleep_sec);
|
2005-07-17 19:52:44 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-06 22:41:19 +00:00
|
|
|
|
2004-12-07 22:54:54 +00:00
|
|
|
// files and database are closed by exit handler
|
|
|
|
exit(0);
|
2004-12-06 22:41:19 +00:00
|
|
|
}
|
2004-12-08 00:26:12 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_0c1c4336f1 = "$Id$";
|