BOINC /
boinc
| 1 | <?php |
||
| 2 | // This file is part of BOINC. |
||
| 3 | // http://boinc.berkeley.edu |
||
| 4 | // Copyright (C) 2008 University of California |
||
| 5 | // |
||
| 6 | // BOINC is free software; you can redistribute it and/or modify it |
||
| 7 | // under the terms of the GNU Lesser General Public License |
||
| 8 | // as published by the Free Software Foundation, |
||
| 9 | // either version 3 of the License, or (at your option) any later version. |
||
| 10 | // |
||
| 11 | // BOINC is distributed in the hope that it will be useful, |
||
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 14 | // See the GNU Lesser General Public License for more details. |
||
| 15 | // |
||
| 16 | // You should have received a copy of the GNU Lesser General Public License |
||
| 17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
| 18 | |||
| 19 | // script to delete results with no corresponding workunit. |
||
| 20 | // In theory these shouldn't exist, |
||
| 21 | // but (because of crashes or bugs) they sometimes do. |
||
| 22 | // db_purge doesn't get rid of them; this does |
||
| 23 | |||
| 24 | $cli_only = true; |
||
| 25 | require_once("../inc/util_ops.inc"); |
||
| 26 | require_once("../inc/db.inc"); |
||
| 27 | |||
| 28 | set_time_limit(0); |
||
| 29 | |||
| 30 | // get lists of current results and WUs. |
||
| 31 | // Do selects in this order so that we'll get all relevant results |
||
| 32 | // |
||
| 33 | function get_lists() { |
||
| 34 | $config = get_config(); |
||
| 35 | $db_name = parse_config($config, "<db_name>"); |
||
| 36 | $db_host = parse_config($config, "<db_host>"); |
||
| 37 | system("mysql $db_name -h $db_host -e \"select workunitid, id from result \" | tail -n +2 | sort -n > dbc_res.dat"); |
||
| 38 | system("mysql $db_name -h $db_host -e \"select id from workunit\" | tail -n +2 | sort -n > dbc_wu.dat"); |
||
| 39 | } |
||
| 40 | |||
| 41 | // N.B.: on Linux we can use join -v to find results without WU. |
||
| 42 | // But for some reason this doesn't work on Solaris (*&^@#). |
||
| 43 | // So we roll our own. |
||
| 44 | // Note: it's |
||
| 45 | // |
||
| 46 | function join_lists() { |
||
| 47 | $fwu = fopen('dbc_wu.dat', 'r'); |
||
| 48 | $fres = fopen('dbc_res.dat', 'r'); |
||
| 49 | $fout = fopen('dbc_out.dat', 'w'); |
||
| 50 | $wuid = 0; |
||
| 51 | $n = 0; |
||
| 52 | while (1) { |
||
| 53 | $n++; |
||
| 54 | if ($n % 1000 == 0) echo "$n\n"; |
||
| 55 | $x = fgets($fres); |
||
| 56 | if (!$x) break; |
||
| 57 | list($reswuid, $resid) = sscanf($x, "%d %d"); |
||
| 58 | if (feof($fwu)) { |
||
| 59 | fputs($fout, "$resid\n"); |
||
| 60 | continue; |
||
| 61 | } |
||
| 62 | while ($wuid < $reswuid) { |
||
| 63 | $y = fgets($fwu); |
||
| 64 | if (!$y) { |
||
| 65 | $wuid = 999999999999; |
||
| 66 | break; |
||
| 67 | } |
||
| 68 | sscanf($y, "%d", $wuid); |
||
| 69 | } |
||
| 70 | if ($wuid == $reswuid) continue; |
||
| 71 | if ($wuid > $reswuid) { |
||
| 72 | fputs($fout, "$resid\n"); |
||
| 73 | continue; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | // It would be better to have db_purge delete the results |
||
| 79 | // (and write them to XML archive) |
||
| 80 | // but it's not clear how to do this. |
||
| 81 | // So just delete them. |
||
| 82 | // |
||
| 83 | function delete_results() { |
||
| 84 | db_init(); |
||
| 85 | $f = fopen('dbc_out.dat', 'r'); |
||
| 86 | while (1) { |
||
| 87 | $x = fgets($f); |
||
| 88 | if (!$x) break; |
||
| 89 | $n = sscanf($x, "%d", $resid); |
||
| 90 | if ($n != 1) { |
||
| 91 | echo "bad line: $x\n"; |
||
| 92 | continue; |
||
| 93 | } |
||
| 94 | $result = BoincResult::lookup_id($resid); |
||
| 95 | if (!$result) { |
||
| 96 | echo "no result $resultid\n"; |
||
| 97 | continue; |
||
| 98 | } |
||
| 99 | $wu = BoincWorkunit::lookup_id($result->workunitid); |
||
| 100 | if ($wu) { |
||
| 101 | echo "result has WU: $resid\n"; |
||
| 102 | continue; |
||
| 103 | } |
||
| 104 | echo "deleting $resid\n"; |
||
| 105 | |||
| 106 | // uncomment the following to actually delete |
||
| 107 | |||
| 108 | die("edit script to enable deletion\n"); |
||
|
0 ignored issues
–
show
|
|||
| 109 | //_mysql_query("delete from result where id=$resid"); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | get_lists(); |
||
| 114 | join_lists(); |
||
| 115 | delete_results(); |
||
| 116 | |||
| 117 | ?> |
||
| 118 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.