File: db_cleanse.php

package info (click to toggle)
boinc 7.14.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,132 kB
  • sloc: cpp: 163,589; php: 113,173; ansic: 49,284; pascal: 35,620; xml: 17,864; java: 13,521; python: 6,551; sh: 4,082; perl: 1,843; makefile: 1,796; objc: 1,543; sql: 959; csh: 126; lisp: 47
file content (117 lines) | stat: -rw-r--r-- 3,524 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC 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 3 of the License, or (at your option) any later version.
//
// BOINC 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.

// script to delete results with no corresponding workunit.
// In theory these shouldn't exist,
// but (because of crashes or bugs) they sometimes do.
// db_purge doesn't get rid of them; this does

$cli_only = true;
require_once("../inc/util_ops.inc");
require_once("../inc/db.inc");

set_time_limit(0);

// get lists of current results and WUs.
// Do selects in this order so that we'll get all relevant results
//
function get_lists() {
    $config = get_config();
    $db_name = parse_config($config, "<db_name>");
    $db_host = parse_config($config, "<db_host>");
    system("mysql $db_name -h $db_host -e \"select workunitid, id from result \" | tail -n +2 | sort -n > dbc_res.dat");
    system("mysql $db_name -h $db_host -e \"select id from workunit\" | tail -n +2 | sort -n > dbc_wu.dat");
}

// N.B.: on Linux we can use join -v to find results without WU.
// But for some reason this doesn't work on Solaris (*&^@#).
// So we roll our own.
// Note: it's
//
function join_lists() {
    $fwu = fopen('dbc_wu.dat', 'r');
    $fres = fopen('dbc_res.dat', 'r');
    $fout = fopen('dbc_out.dat', 'w');
    $wuid = 0;
    $n = 0;
    while (1) {
        $n++;
        if ($n % 1000 == 0) echo "$n\n";
        $x = fgets($fres);
        if (!$x) break;
        list($reswuid, $resid) = sscanf($x, "%d %d");
        if (feof($fwu)) {
            fputs($fout, "$resid\n");
            continue;
        }
        while ($wuid < $reswuid) {
            $y = fgets($fwu);
            if (!$y) {
                $wuid = 999999999999;
                break;
            }
            sscanf($y, "%d", $wuid);
        }
        if ($wuid == $reswuid) continue;
        if ($wuid > $reswuid) {
            fputs($fout, "$resid\n");
            continue;
        }
    }
}

// It would be better to have db_purge delete the results
// (and write them to XML archive)
// but it's not clear how to do this.
// So just delete them.
//
function delete_results() {
    db_init();
    $f = fopen('dbc_out.dat', 'r');
    while (1) {
        $x = fgets($f);
        if (!$x) break;
        $n = sscanf($x, "%d", $resid);
        if ($n != 1) {
            echo "bad line: $x\n";
            continue;
        }
        $result = BoincResult::lookup_id($resid);
        if (!$result) {
            echo "no result $resultid\n";
            continue;
        }
        $wu = BoincWorkunit::lookup_id($result->workunitid);
        if ($wu) {
            echo "result has WU: $resid\n";
            continue;
        }
        echo "deleting $resid\n";

        // uncomment the following to actually delete

        die("edit script to enable deletion\n");
        //_mysql_query("delete from result where id=$resid");
    }
}

get_lists();
join_lists();
delete_results();

?>