2323// to XML archive files,
2424// then deleting it and the results from the DB.
2525//
26- // if --retired_wus:
27- // purge WUs for which file_delete_state=FILE_DELETE_DONE
28- // and the WU is in a retired batch
29- // otherwise
30- // purge WUs for which file_delete_state=FILE_DELETE_DONE.
26+ // Purge WUs for which file_delete_state == FILE_DELETE_DONE
27+ // and the WU is either
28+ // - in a retired batch
29+ // - not in a batch
3130//
3231// The XML files have names of the form
3332// wu_archive_TIME and result_archive_TIME
@@ -70,7 +69,6 @@ void usage() {
7069 " Purge workunit and result records that are no longer needed.\n\n "
7170 " Usage: db_purge [options]\n "
7271 " -d N or --debug_level N Set verbosity level (1-4; 3=normal, 4=debug)\n "
73- " --retired_wus purge WUs only from retired batches\n "
7472 " --min_age_days N Purge Wus w/ mod time at least N days ago\n "
7573 " --max N Purge at most N WUs\n "
7674 " --zip Compress output files by piping through zip\n "
@@ -236,7 +234,6 @@ double min_age_days = 0;
236234bool no_archive = false ;
237235bool dont_delete = false ;
238236bool daily_dir = false ;
239- bool retired_wus = false ;
240237int max_number_workunits_to_purge = 0 ;
241238 // If nonzero, maximum number of workunits to purge.
242239 // Since all results associated with a purged workunit are also purged,
@@ -255,8 +252,6 @@ int id_modulus=0, id_remainder=0;
255252 // allow more than one to run - doesn't work if archiving is enabled
256253char app_name[256 ];
257254DB_APP app;
258- string retired_batch_ids;
259- // if --retired_wus, a list of retired batch IDs as "id1,id2,..."
260255
261256bool time_to_quit () {
262257 if (max_number_workunits_to_purge) {
@@ -611,38 +606,37 @@ int purge_and_archive_results(DB_WORKUNIT& wu, int& number_results) {
611606 return 0 ;
612607}
613608
614- // get list of IDs of retired batches
609+ // get list of IDs of retired batches (and 0, = no batch)
615610//
616611int get_retired_batch_ids (string &out) {
617- out. clear () ;
612+ out = " 0 " ;
618613 char query[256 ];
619614 sprintf (query, " select id from batch where state=%d" , BATCH_STATE_RETIRED );
620615 int retval = boinc_db.do_query (query);
621- if (retval) return mysql_errno (boinc_db.mysql );
616+ if (retval) {
617+ return mysql_errno (boinc_db.mysql );
618+ }
622619
623620 MYSQL_RES *rp;
624621 rp = mysql_store_result (boinc_db.mysql );
625- if (!rp) return mysql_errno (boinc_db.mysql );
626- bool first = true ;
622+ if (!rp) {
623+ return mysql_errno (boinc_db.mysql );
624+ }
627625 while (1 ) {
628626 MYSQL_ROW row = mysql_fetch_row (rp);
629627 if (!row) {
630628 mysql_free_result (rp);
631629 break ;
632630 }
633- if (first) {
634- first = false ;
635- } else {
636- out += " ," ;
637- }
631+ out += " ," ;
638632 out += row[0 ];
639633 }
640634 return 0 ;
641635}
642636
643637// return true if did anything
644638//
645- bool do_pass () {
639+ bool do_pass (string &retired_batch_ids ) {
646640 int retval = 0 ;
647641
648642 // The number of workunits/results purged in a single pass of do_pass().
@@ -683,13 +677,9 @@ bool do_pass() {
683677 sprintf (buf, " and appid=%lu" , app.id );
684678 clause += buf;
685679 }
686- if (retired_wus) {
687- clause += " and batch in (" ;
688- clause += retired_batch_ids;
689- clause += " )" ;
690- } else {
691- clause += " and batch=0" ;
692- }
680+ clause += " and batch in (" ;
681+ clause += retired_batch_ids;
682+ clause += " )" ;
693683
694684 sprintf (buf, " limit %d" , DB_QUERY_LIMIT );
695685 clause += buf;
@@ -862,8 +852,6 @@ int main(int argc, char** argv) {
862852 max_wu_per_file = atoi (argv[i]);
863853 } else if (is_arg (argv[i], " no_archive" )) {
864854 no_archive = true ;
865- } else if (is_arg (argv[i], " retired_wus" )) {
866- retired_wus = true ;
867855 } else if (is_arg (argv[i], " sleep" )) {
868856 if (!argv[++i]) {
869857 log_messages.printf (MSG_CRITICAL , " %s requires an argument\n\n " , argv[--i]);
@@ -957,25 +945,14 @@ int main(int argc, char** argv) {
957945 if (time_to_quit ()) {
958946 break ;
959947 }
960- if (retired_wus) {
961- retval = get_retired_batch_ids (retired_batch_ids);
962- if (retval) {
963- log_messages.printf (MSG_CRITICAL ,
964- " Can't get retired batch IDs"
965- );
966- exit (1 );
967- }
968- if (retired_batch_ids.empty ()) {
969- log_messages.printf (MSG_NORMAL ,
970- " no retired batches; sleeping %d\n " ,
971- sleep_sec
972- );
973- daemon_sleep (sleep_sec);
974- continue ;
975- }
948+ string retired_batch_ids;
949+ retval = get_retired_batch_ids (retired_batch_ids);
950+ if (retval) {
951+ log_messages.printf (MSG_CRITICAL , " Can't get retired batch IDs" );
952+ exit (1 );
976953 }
977954
978- bool did_something = do_pass ();
955+ bool did_something = do_pass (retired_batch_ids );
979956 if (one_pass) {
980957 break ;
981958 }
0 commit comments