~ubuntu-branches/ubuntu/lucid/boinc/lucid

« back to all changes in this revision

Viewing changes to sched/sched_resend.C

  • Committer: Bazaar Package Importer
  • Author(s): Frank S. Thomas, Frank S. Thomas
  • Date: 2008-05-31 08:02:47 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20080531080247-4ce890lp2rc768cr
Tags: 6.2.7-1
[ Frank S. Thomas ]
* New upstream release.
  - BOINC Manager: Redraw disk usage charts immediately after connecting to
    a (different) client. (closes: 463823)
* debian/copyright:
  - Added the instructions from debian/README.Debian-source about how
    repackaged BOINC tarballs can be reproduced because DevRef now
    recommends to put this here instead of in the afore-mentioned file.
  - Updated for the new release.
* Removed the obsolete debian/README.Debian-source.
* For consistency upstream renamed the core client and the command tool
  ("boinc_client" to "boinc" and "boinc_cmd" to "boinccmd"). Done the same
  in all packages and created symlinks with the old names for the binaries
  and man pages. Also added an entry in debian/boinc-client.NEWS explaining
  this change.
* debian/rules: Do not list Makefile.ins in the clean target individually,
  just remove all that can be found.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
// To view the GNU Lesser General Public License visit
16
16
// http://www.gnu.org/copyleft/lesser.html
17
17
// or write to the Free Software Foundation, Inc.,
18
 
// 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 
20
20
// scheduler code related to sending "lost" work
21
21
// (i.e. results we sent to the host, but which they're not reporting)
26
26
//   this result may have been the cause of reset
27
27
//   (need to pass last reset time from client)
28
28
 
 
29
#include <cstdlib>
 
30
#include <cstring>
 
31
#include <string>
 
32
 
29
33
#include "config.h"
30
34
#include "error_numbers.h"
31
35
 
54
58
    DB_RESULT& result, WORKUNIT& wu, SCHEDULER_REPLY& reply
55
59
) {
56
60
    const double resend_frac = 0.5;  // range [0, 1)
57
 
    int result_sent_time = time(0);
58
 
    int result_report_deadline = result_sent_time + (int)(resend_frac*(result.report_deadline - result.sent_time));
 
61
    int now = time(0);
 
62
    int result_report_deadline = now + (int)(resend_frac*(result.report_deadline - result.sent_time));
59
63
 
60
64
    if (result_report_deadline < result.report_deadline) {
61
65
        result_report_deadline = result.report_deadline;
62
66
    }
63
 
    if (result_report_deadline > result_sent_time + wu.delay_bound) {
64
 
        result_report_deadline = result_sent_time + wu.delay_bound;
 
67
    if (result_report_deadline > now + wu.delay_bound) {
 
68
        result_report_deadline = now + wu.delay_bound;
65
69
    }
66
70
 
67
71
    // If infeasible, return without modifying result
68
72
    //
69
 
    if (estimate_cpu_duration(wu, reply) > result_report_deadline-result_sent_time) {
70
 
        log_messages.printf(
71
 
            SCHED_MSG_LOG::MSG_DEBUG,
 
73
    if (estimate_cpu_duration(wu, reply) > result_report_deadline-now) {
 
74
        log_messages.printf(MSG_DEBUG,
72
75
            "[RESULT#%d] [HOST#%d] not resending lost result: can't complete in time\n",
73
76
            result.id, reply.host.id
74
77
        );
77
80
    
78
81
    // update result with new report time and sent time
79
82
    //
80
 
    log_messages.printf(
81
 
        SCHED_MSG_LOG::MSG_DEBUG,
 
83
    log_messages.printf(MSG_DEBUG,
82
84
        "[RESULT#%d] [HOST#%d] %s report_deadline (resend lost work)\n",
83
85
        result.id, reply.host.id,
84
86
        result_report_deadline==result.report_deadline?"NO update to":"Updated"
85
87
    );
86
 
    result.sent_time = result_sent_time;
 
88
    result.sent_time = now;
87
89
    result.report_deadline = result_report_deadline;
88
90
    return 0;
89
91
}
90
92
 
91
 
bool resend_lost_work(
92
 
    SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply,
93
 
    PLATFORM_LIST& platforms, SCHED_SHMEM& ss
94
 
) {
 
93
// resend any jobs that:
 
94
// 1) we already sent to this host;
 
95
// 2) are still in progress (i.e. haven't timed out) and
 
96
// 3) aren't present on the host
 
97
// Return true if there were any such jobs
 
98
//
 
99
bool resend_lost_work(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
95
100
    DB_RESULT result;
96
101
    std::vector<DB_RESULT>results;
97
102
    unsigned int i;
98
103
    char buf[256];
 
104
    char warning_msg[256];
99
105
    bool did_any = false;
100
 
    int num_to_resend=0;
 
106
    int num_eligible_to_resend=0;
101
107
    int num_resent=0;
102
 
    int num_on_host=0;
103
 
    APP* app;
104
 
    APP_VERSION* avp;
 
108
    BEST_APP_VERSION* bavp;
105
109
    int retval;
106
110
 
107
 
    // print list of results on host
108
 
    //
109
 
    for (i=0; i<sreq.other_results.size(); i++) {
110
 
        OTHER_RESULT& orp=sreq.other_results[i];
111
 
        log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
112
 
            "Result is on [HOST#%d]: %s\n",
113
 
            reply.host.id, orp.name.c_str()
114
 
        );
115
 
    }
116
 
 
117
111
    sprintf(buf, " where hostid=%d and server_state=%d ",
118
112
        reply.host.id, RESULT_SERVER_STATE_IN_PROGRESS
119
113
    );
120
114
    while (!result.enumerate(buf)) {
121
115
        bool found = false;
122
 
        num_on_host++;
123
116
        for (i=0; i<sreq.other_results.size(); i++) {
124
117
            OTHER_RESULT& orp = sreq.other_results[i];
125
118
            if (!strcmp(orp.name.c_str(), result.name)) {
126
119
                found = true;
127
 
            }
128
 
        }
129
 
        if (!found) {
130
 
            num_to_resend++;
131
 
            log_messages.printf(
132
 
                SCHED_MSG_LOG::MSG_DEBUG,
133
 
                "[HOST#%d] found lost [RESULT#%d]: %s\n",
134
 
                reply.host.id, result.id, result.name
135
 
            );
136
 
 
137
 
            DB_WORKUNIT wu;
138
 
            retval = wu.lookup_id(result.workunitid);
139
 
            if (retval) {
140
 
                log_messages.printf( SCHED_MSG_LOG::MSG_CRITICAL,
141
 
                    "[HOST#%d] WU not found for [RESULT#%d]\n",
142
 
                    reply.host.id, result.id
143
 
                );
144
 
                continue;
145
 
            }
146
 
 
147
 
            reply.wreq.core_client_version =
148
 
                sreq.core_client_major_version*100 + sreq.core_client_minor_version;
149
 
 
150
 
            retval = get_app_version(
151
 
                wu, app, avp, sreq, reply, platforms, ss
152
 
            );
153
 
            if (retval) {
154
 
                log_messages.printf( SCHED_MSG_LOG::MSG_CRITICAL,
155
 
                    "[HOST#%d] no app version [RESULT#%d]\n",
156
 
                    reply.host.id, result.id
157
 
                );
158
 
                continue;
159
 
            }
160
 
 
161
 
            // If time is too close to the deadline,
162
 
            // or we already have a canonical result,
163
 
            // or WU error flag is set,
164
 
            // then don't bother to resend this result.
165
 
            // Instead make it time out right away
166
 
            // so that the transitioner does 'the right thing'.
167
 
            //
168
 
            char warning_msg[256];
169
 
            if (
170
 
                wu.error_mask ||
171
 
                wu.canonical_resultid ||
172
 
                possibly_give_result_new_deadline(result, wu, reply)
173
 
            ) {
174
 
                result.report_deadline = time(0);
175
 
                retval = result.mark_as_sent(result.server_state);
176
 
                if (retval==ERR_DB_NOT_FOUND) {
177
 
                    log_messages.printf(
178
 
                        SCHED_MSG_LOG::MSG_CRITICAL,
179
 
                        "[RESULT#%d] [HOST#%d]: CAN'T SEND, already sent to another host\n",
180
 
                        result.id, reply.host.id
181
 
                    );
182
 
                } else if (retval) {
183
 
                    log_messages.printf(
184
 
                        SCHED_MSG_LOG::MSG_CRITICAL,
185
 
                        "resend_lost_result: can't update result deadline: %d\n", retval
186
 
                    );
187
 
                }
188
 
                if (retval) continue;
189
 
 
190
 
                retval = update_wu_transition_time(wu, result.report_deadline);
191
 
                if (retval) {
192
 
                    log_messages.printf(
193
 
                        SCHED_MSG_LOG::MSG_CRITICAL,
194
 
                        "resend_lost_result: can't update WU transition time: %d\n", retval
195
 
                    );
196
 
                    continue;
197
 
                }
198
 
                log_messages.printf(
199
 
                    SCHED_MSG_LOG::MSG_DEBUG,
200
 
                    "[HOST#%d][RESULT#%d] not needed or too close to deadline, expiring\n",
201
 
                    reply.host.id, result.id
202
 
                );
203
 
                sprintf(warning_msg, "Didn't resend lost result %s (expired)", result.name);
204
 
                USER_MESSAGE um(warning_msg, "high");
205
 
                reply.insert_message(um);
206
 
                continue;
207
 
            }
208
 
 
209
 
            retval = add_result_to_reply(
210
 
                result, wu, sreq, reply, platforms, app, avp
211
 
            );
212
 
            if (retval) {
213
 
                log_messages.printf( SCHED_MSG_LOG::MSG_CRITICAL,
 
120
                break;
 
121
            }
 
122
        }
 
123
        if (found) continue;
 
124
 
 
125
        num_eligible_to_resend++;
 
126
        log_messages.printf(MSG_DEBUG,
 
127
            "[HOST#%d] found lost [RESULT#%d]: %s\n",
 
128
            reply.host.id, result.id, result.name
 
129
        );
 
130
 
 
131
        DB_WORKUNIT wu;
 
132
        retval = wu.lookup_id(result.workunitid);
 
133
        if (retval) {
 
134
            log_messages.printf(MSG_CRITICAL,
 
135
                "[HOST#%d] WU not found for [RESULT#%d]\n",
 
136
                reply.host.id, result.id
 
137
            );
 
138
            continue;
 
139
        }
 
140
 
 
141
        bavp = get_app_version(sreq, reply, wu);
 
142
        if (!bavp) {
 
143
            log_messages.printf(MSG_CRITICAL,
 
144
                "[HOST#%d] no app version [RESULT#%d]\n",
 
145
                reply.host.id, result.id
 
146
            );
 
147
            continue;
 
148
        }
 
149
 
 
150
        // If time is too close to the deadline,
 
151
        // or we already have a canonical result,
 
152
        // or WU error flag is set,
 
153
        // then don't bother to resend this result.
 
154
        // Instead make it time out right away
 
155
        // so that the transitioner does 'the right thing'.
 
156
        //
 
157
        if (
 
158
            wu.error_mask ||
 
159
            wu.canonical_resultid ||
 
160
            possibly_give_result_new_deadline(result, wu, reply)
 
161
        ) {
 
162
            log_messages.printf(MSG_DEBUG,
 
163
                "[HOST#%d][RESULT#%d] not needed or too close to deadline, expiring\n",
 
164
                reply.host.id, result.id
 
165
            );
 
166
            result.report_deadline = time(0)-1;
 
167
            retval = result.mark_as_sent(result.server_state);
 
168
            if (retval) {
 
169
                log_messages.printf(MSG_CRITICAL,
 
170
                    "resend_lost_work: can't update result deadline: %d\n", retval
 
171
                );
 
172
                continue;
 
173
            }
 
174
 
 
175
            retval = update_wu_transition_time(wu, result.report_deadline);
 
176
            if (retval) {
 
177
                log_messages.printf(MSG_CRITICAL,
 
178
                    "resend_lost_result: can't update WU transition time: %d\n", retval
 
179
                );
 
180
                continue;
 
181
            }
 
182
            sprintf(warning_msg,
 
183
                "Didn't resend lost result %s (expired)", result.name
 
184
            );
 
185
            USER_MESSAGE um(warning_msg, "high");
 
186
            reply.insert_message(um);
 
187
        } else {
 
188
            retval = add_result_to_reply(result, wu, sreq, reply, bavp);
 
189
            if (retval) {
 
190
                log_messages.printf(MSG_CRITICAL,
214
191
                    "[HOST#%d] failed to send [RESULT#%d]\n",
215
192
                    reply.host.id, result.id
216
193
                );
224
201
        }
225
202
    }
226
203
 
227
 
    reply.wreq.nresults_on_host = num_on_host;
228
 
    log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
229
 
        "[HOST#%d] %d results in progress, set for later checking\n",
230
 
        reply.host.id, num_on_host
231
 
    );
232
 
 
233
 
    if (num_to_resend) {
234
 
        log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
235
 
            "[HOST#%d] %d lost results, resent %d\n", reply.host.id, num_to_resend, num_resent 
 
204
    if (num_eligible_to_resend) {
 
205
        log_messages.printf(MSG_DEBUG,
 
206
            "[HOST#%d] %d lost results, resent %d\n", reply.host.id, num_eligible_to_resend, num_resent 
236
207
        );
237
208
    }
238
209
 
239
210
    return did_any;
240
211
}
241
212
 
242
 
const char *BOINC_RCSID_3be23838b4="$Id: sched_resend.C 12661 2007-05-14 15:21:38Z boincadm $";
 
213
const char *BOINC_RCSID_3be23838b4="$Id: sched_resend.C 14966 2008-03-27 18:25:29Z davea $";