2006-06-09 23:17:05 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
|
|
|
//
|
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This software 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.
|
|
|
|
//
|
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-06-09 23:17:05 +00:00
|
|
|
|
|
|
|
// Simple validator framework:
|
|
|
|
// Lets you create a custom validator by supplying three simple functions.
|
|
|
|
// See http://boinc.berkeley.edu/validate_simple.php
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <vector>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
2006-06-09 23:17:05 +00:00
|
|
|
|
|
|
|
#include "boinc_db.h"
|
2006-06-20 17:36:28 +00:00
|
|
|
#include "error_numbers.h"
|
2006-06-09 23:17:05 +00:00
|
|
|
|
2006-06-10 12:55:23 +00:00
|
|
|
#include "sched_config.h"
|
2006-06-09 23:17:05 +00:00
|
|
|
#include "sched_msgs.h"
|
|
|
|
|
2006-06-10 21:29:51 +00:00
|
|
|
#include "validator.h"
|
2006-06-09 23:17:05 +00:00
|
|
|
#include "validate_util.h"
|
|
|
|
#include "validate_util2.h"
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
2006-06-20 17:36:28 +00:00
|
|
|
// invariants:
|
|
|
|
// results.size() >= wu.min_quorum
|
|
|
|
// for each result:
|
|
|
|
// result.outcome == SUCCESS
|
|
|
|
// result.validate_state == INIT
|
|
|
|
|
2006-06-09 23:17:05 +00:00
|
|
|
int check_set(
|
2006-06-20 17:36:28 +00:00
|
|
|
vector<RESULT>& results, WORKUNIT& wu,
|
|
|
|
int& canonicalid, double& credit, bool& retry
|
2006-06-09 23:17:05 +00:00
|
|
|
) {
|
|
|
|
vector<void*> data;
|
2006-06-20 17:36:28 +00:00
|
|
|
vector<bool> had_error;
|
|
|
|
int i, j, neq = 0, n, retval;
|
2006-06-09 23:17:05 +00:00
|
|
|
int min_valid = wu.min_quorum/2+1;
|
|
|
|
|
|
|
|
retry = false;
|
|
|
|
n = results.size();
|
|
|
|
data.resize(n);
|
2006-06-20 17:36:28 +00:00
|
|
|
had_error.resize(n);
|
2006-06-09 23:17:05 +00:00
|
|
|
|
2006-06-20 17:36:28 +00:00
|
|
|
// Initialize results
|
2006-06-09 23:17:05 +00:00
|
|
|
|
2006-06-20 17:36:28 +00:00
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
data[i] = NULL;
|
|
|
|
had_error[i] = false;
|
|
|
|
}
|
|
|
|
int good_results = 0;
|
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
retval = init_result(results[i], data[i]);
|
|
|
|
if (retval == ERR_OPENDIR) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2006-06-20 17:36:28 +00:00
|
|
|
"check_set: init_result([RESULT#%d %s]) transient failure\n",
|
2006-06-09 23:17:05 +00:00
|
|
|
results[i].id, results[i].name
|
|
|
|
);
|
2006-06-20 17:36:28 +00:00
|
|
|
had_error[i] = true;
|
|
|
|
} else if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2006-06-20 17:36:28 +00:00
|
|
|
"check_set: init_result([RESULT#%d %s]) failed: %d\n",
|
|
|
|
results[i].id, results[i].name, retval
|
|
|
|
);
|
|
|
|
results[i].outcome = RESULT_OUTCOME_VALIDATE_ERROR;
|
|
|
|
results[i].validate_state = VALIDATE_STATE_INVALID;
|
2006-11-26 03:17:44 +00:00
|
|
|
had_error[i] = true;
|
2006-06-20 17:36:28 +00:00
|
|
|
} else {
|
|
|
|
good_results++;
|
2006-06-09 23:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-20 17:36:28 +00:00
|
|
|
if (good_results < wu.min_quorum) goto cleanup;
|
2006-06-09 23:17:05 +00:00
|
|
|
|
2006-06-20 17:36:28 +00:00
|
|
|
// Compare results
|
2006-06-09 23:17:05 +00:00
|
|
|
|
2006-06-20 17:36:28 +00:00
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
if (had_error[i]) continue;
|
2006-06-09 23:17:05 +00:00
|
|
|
vector<bool> matches;
|
|
|
|
matches.resize(n);
|
|
|
|
neq = 0;
|
|
|
|
for (j=0; j!=n; j++) {
|
2006-06-20 17:36:28 +00:00
|
|
|
if (had_error[j]) continue;
|
2006-06-09 23:17:05 +00:00
|
|
|
bool match = false;
|
|
|
|
if (i == j) {
|
|
|
|
++neq;
|
|
|
|
matches[j] = true;
|
|
|
|
} else if (compare_results(results[i], data[i], results[j], data[j], match)) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2006-06-09 23:17:05 +00:00
|
|
|
"generic_check_set: check_pair_with_data([RESULT#%d %s], [RESULT#%d %s]) failed\n",
|
|
|
|
results[i].id, results[i].name, results[j].id, results[j].name
|
|
|
|
);
|
|
|
|
} else if (match) {
|
|
|
|
++neq;
|
|
|
|
matches[j] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (neq >= min_valid) {
|
|
|
|
|
|
|
|
// set validate state for each result
|
|
|
|
//
|
|
|
|
for (j=0; j!=n; j++) {
|
2006-06-20 17:36:28 +00:00
|
|
|
if (had_error[j]) continue;
|
2006-11-28 03:27:13 +00:00
|
|
|
if (max_claimed_credit && results[j].claimed_credit > max_claimed_credit) {
|
2006-06-09 23:17:05 +00:00
|
|
|
results[j].validate_state = VALIDATE_STATE_INVALID;
|
|
|
|
} else {
|
|
|
|
results[j].validate_state = matches[j] ? VALIDATE_STATE_VALID : VALIDATE_STATE_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canonicalid = results[i].id;
|
2007-01-30 18:19:30 +00:00
|
|
|
credit = compute_granted_credit(wu, results);
|
2006-06-09 23:17:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
2006-06-20 17:36:28 +00:00
|
|
|
for (i=0; i<n; i++) {
|
2006-06-09 23:17:05 +00:00
|
|
|
cleanup_result(results[i], data[i]);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-27 01:07:00 +00:00
|
|
|
// r1 is the new result; r2 is canonical result
|
|
|
|
//
|
2008-03-13 23:35:13 +00:00
|
|
|
void check_pair(RESULT& r1, RESULT& r2, bool& retry) {
|
2006-06-09 23:17:05 +00:00
|
|
|
void* data1;
|
|
|
|
void* data2;
|
|
|
|
int retval;
|
|
|
|
bool match;
|
|
|
|
|
|
|
|
retry = false;
|
|
|
|
retval = init_result(r1, data1);
|
2006-11-27 01:07:00 +00:00
|
|
|
if (retval == ERR_OPENDIR) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2006-11-27 01:07:00 +00:00
|
|
|
"check_pair: init_result([RESULT#%d %s]) transient failure 1\n",
|
|
|
|
r1.id, r1.name
|
|
|
|
);
|
|
|
|
retry = true;
|
|
|
|
return;
|
|
|
|
} else if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2006-11-27 01:07:00 +00:00
|
|
|
"check_pair: init_result([RESULT#%d %s]) perm failure 1\n",
|
|
|
|
r1.id, r1.name
|
2006-06-09 23:17:05 +00:00
|
|
|
);
|
2006-11-27 01:07:00 +00:00
|
|
|
r1.outcome = RESULT_OUTCOME_VALIDATE_ERROR;
|
|
|
|
r1.validate_state = VALIDATE_STATE_INVALID;
|
|
|
|
return;
|
2006-06-09 23:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retval = init_result(r2, data2);
|
2006-11-27 01:07:00 +00:00
|
|
|
if (retval == ERR_OPENDIR) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2006-11-27 01:07:00 +00:00
|
|
|
"check_pair: init_result([RESULT#%d %s]) transient failure 2\n",
|
|
|
|
r2.id, r2.name
|
2006-06-09 23:17:05 +00:00
|
|
|
);
|
|
|
|
cleanup_result(r1, data1);
|
2006-11-27 01:07:00 +00:00
|
|
|
retry = true;
|
|
|
|
return;
|
|
|
|
} else if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2006-11-27 01:07:00 +00:00
|
|
|
"check_pair: init_result([RESULT#%d %s]) perm failure2\n",
|
|
|
|
r2.id, r2.name
|
|
|
|
);
|
|
|
|
cleanup_result(r1, data1);
|
|
|
|
r1.outcome = RESULT_OUTCOME_VALIDATE_ERROR;
|
|
|
|
r1.validate_state = VALIDATE_STATE_INVALID;
|
|
|
|
return;
|
2006-06-09 23:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retval = compare_results(r1, data1, r2, data2, match);
|
2006-11-28 03:27:13 +00:00
|
|
|
if (max_claimed_credit && r1.claimed_credit > max_claimed_credit) {
|
2006-06-09 23:17:05 +00:00
|
|
|
r1.validate_state = VALIDATE_STATE_INVALID;
|
|
|
|
} else {
|
|
|
|
r1.validate_state = match?VALIDATE_STATE_VALID:VALIDATE_STATE_INVALID;
|
|
|
|
}
|
|
|
|
cleanup_result(r1, data1);
|
|
|
|
cleanup_result(r2, data2);
|
|
|
|
}
|