|
24 | 24 | // then deleting it and the results from the DB. |
25 | 25 | // |
26 | 26 | // Purge WUs for which file_delete_state == FILE_DELETE_DONE |
27 | | -// and the WU is either |
| 27 | +// and if --batch: |
| 28 | +// the WU is either |
28 | 29 | // - in a retired batch |
29 | 30 | // - not in a batch |
30 | 31 | // |
@@ -69,6 +70,7 @@ void usage() { |
69 | 70 | "Purge workunit and result records that are no longer needed.\n\n" |
70 | 71 | "Usage: db_purge [options]\n" |
71 | 72 | " -d N or --debug_level N Set verbosity level (1-4; 3=normal, 4=debug)\n" |
| 73 | + " --batch purge batch jobs only if retired\n" |
72 | 74 | " --min_age_days N Purge Wus w/ mod time at least N days ago\n" |
73 | 75 | " --max N Purge at most N WUs\n" |
74 | 76 | " --zip Compress output files by piping through zip\n" |
@@ -232,6 +234,7 @@ void* re_index_stream=NULL; |
232 | 234 | int time_int=0; |
233 | 235 | double min_age_days = 0; |
234 | 236 | bool no_archive = false; |
| 237 | +bool batch = false; |
235 | 238 | bool dont_delete = false; |
236 | 239 | bool daily_dir = false; |
237 | 240 | int max_number_workunits_to_purge = 0; |
@@ -677,9 +680,11 @@ bool do_pass(string &retired_batch_ids) { |
677 | 680 | sprintf(buf, " and appid=%lu", app.id); |
678 | 681 | clause += buf; |
679 | 682 | } |
680 | | - clause += " and batch in ("; |
681 | | - clause += retired_batch_ids; |
682 | | - clause += ")"; |
| 683 | + if (batch) { |
| 684 | + clause += " and batch in ("; |
| 685 | + clause += retired_batch_ids; |
| 686 | + clause += ")"; |
| 687 | + } |
683 | 688 |
|
684 | 689 | sprintf(buf, " limit %d", DB_QUERY_LIMIT); |
685 | 690 | clause += buf; |
@@ -808,6 +813,8 @@ int main(int argc, char** argv) { |
808 | 813 | for (i=1; i<argc; i++) { |
809 | 814 | if (is_arg(argv[i], "one_pass")) { |
810 | 815 | one_pass = true; |
| 816 | + } else if (is_arg(argv[i], "batch")) { |
| 817 | + batch = true; |
811 | 818 | } else if (is_arg(argv[i], "dont_delete")) { |
812 | 819 | dont_delete = true; |
813 | 820 | } else if (is_arg(argv[i], "d") || is_arg(argv[i], "debug_level")) { |
@@ -946,10 +953,15 @@ int main(int argc, char** argv) { |
946 | 953 | break; |
947 | 954 | } |
948 | 955 | 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); |
| 956 | + if (batch) { |
| 957 | + retval = get_retired_batch_ids(retired_batch_ids); |
| 958 | + if (retval) { |
| 959 | + log_messages.printf(MSG_CRITICAL, |
| 960 | + "Can't get retired batch IDs; retval %d\n", |
| 961 | + retval |
| 962 | + ); |
| 963 | + exit(1); |
| 964 | + } |
953 | 965 | } |
954 | 966 |
|
955 | 967 | bool did_something = do_pass(retired_batch_ids); |
|
0 commit comments