2012-01-20 20:21:29 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2012 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/>.
|
|
|
|
|
2012-07-23 21:53:09 +00:00
|
|
|
// Code that's shared by the simulator, vda, and vdad
|
2012-03-11 01:51:07 +00:00
|
|
|
|
2012-02-10 22:54:00 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <limits.h>
|
2013-05-27 23:44:22 +00:00
|
|
|
#include <cmath>
|
2012-07-23 21:53:09 +00:00
|
|
|
#include <set>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "vda_lib.h"
|
2012-02-10 22:54:00 +00:00
|
|
|
|
|
|
|
using std::vector;
|
2012-02-24 22:55:11 +00:00
|
|
|
using std::set;
|
2012-02-10 22:54:00 +00:00
|
|
|
|
2013-05-09 21:53:26 +00:00
|
|
|
bool debug_status = false;
|
|
|
|
bool debug_ft = false;
|
2012-06-15 20:49:11 +00:00
|
|
|
|
2012-07-23 21:53:09 +00:00
|
|
|
///////////////// Utility functions ///////////////////////
|
|
|
|
|
|
|
|
// sort by increasing cost
|
|
|
|
//
|
|
|
|
bool compare_cost(const DATA_UNIT* d1, const DATA_UNIT* d2) {
|
|
|
|
return d1->cost < d2->cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort by increase min_failures
|
|
|
|
//
|
|
|
|
bool compare_min_failures(const DATA_UNIT* d1, const DATA_UNIT* d2) {
|
|
|
|
return d1->min_failures < d2->min_failures;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* time_str(double t) {
|
|
|
|
static char buf[256];
|
2013-05-09 21:53:26 +00:00
|
|
|
int nsec = (int)fmod(t, 60);
|
|
|
|
t /= 60;
|
|
|
|
int nmin = (int)fmod(t, 60);
|
|
|
|
t /= 60;
|
|
|
|
int nhour = (int)fmod(t, 24);
|
|
|
|
t /= 24;
|
|
|
|
sprintf(buf, "%4d days %02d:%02d:%02d", (int)t, nhour, nmin, nsec);
|
2012-07-23 21:53:09 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* status_str(int status) {
|
|
|
|
switch (status) {
|
|
|
|
case PRESENT: return "present";
|
|
|
|
case RECOVERABLE: return "recoverable";
|
|
|
|
case UNRECOVERABLE: return "unrecoverable";
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////// META_CHUNK ///////////////////////
|
|
|
|
|
2012-02-10 22:54:00 +00:00
|
|
|
META_CHUNK::META_CHUNK(
|
|
|
|
VDA_FILE_AUX* d, META_CHUNK* par, double size,
|
|
|
|
int coding_level, int index
|
|
|
|
) {
|
|
|
|
dfile = d;
|
|
|
|
parent = par;
|
|
|
|
coding = d->policy.codings[coding_level];
|
|
|
|
if (parent) {
|
2020-05-02 18:49:28 +00:00
|
|
|
sprintf(name, "%.64s.%d", parent->name, index);
|
2012-02-10 22:54:00 +00:00
|
|
|
} else {
|
|
|
|
sprintf(name, "%d", index);
|
|
|
|
}
|
|
|
|
if (coding_level<d->policy.coding_levels-1) {
|
|
|
|
for (int j=0; j<coding.m; j++) {
|
|
|
|
children.push_back(new META_CHUNK(
|
|
|
|
d,
|
|
|
|
this,
|
|
|
|
size/coding.n,
|
|
|
|
coding_level+1,
|
|
|
|
j
|
|
|
|
));
|
|
|
|
}
|
2012-03-11 01:51:07 +00:00
|
|
|
bottom_level = false;
|
2012-02-10 22:54:00 +00:00
|
|
|
} else {
|
|
|
|
for (int j=0; j<coding.m; j++) {
|
|
|
|
children.push_back(
|
|
|
|
new CHUNK(this, size/coding.n, j)
|
|
|
|
);
|
|
|
|
}
|
2012-03-11 01:51:07 +00:00
|
|
|
bottom_level = true;
|
2012-02-10 22:54:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recovery logic: decide what to do in response to
|
|
|
|
// host failures and upload/download completions.
|
|
|
|
//
|
|
|
|
// One way to do this would be to store a bunch of state info
|
|
|
|
// with each node in the file's tree,
|
|
|
|
// and do things by local tree traversal.
|
|
|
|
//
|
2012-02-29 20:58:45 +00:00
|
|
|
// However, it's simpler to store minimal state info,
|
2012-02-10 22:54:00 +00:00
|
|
|
// and to reconstruct state info using
|
|
|
|
// a top-down tree traversal in response to each event.
|
|
|
|
// Actually we do 2 traversals:
|
2012-08-03 16:41:00 +00:00
|
|
|
// 1) recovery_plan()
|
2012-02-29 20:58:45 +00:00
|
|
|
// We see whether each node is recoverable,
|
2012-02-10 22:54:00 +00:00
|
|
|
// and if so compute its "recovery set":
|
|
|
|
// the set of children from which it can be recovered
|
|
|
|
// with minimal cost (i.e. network traffic).
|
|
|
|
// Decide whether each chunk currently on the server needs to remain.
|
2012-08-03 16:41:00 +00:00
|
|
|
// 2) decide_reconstruct()
|
|
|
|
// Decide which meta-chunks should be reconstructed
|
|
|
|
// 3) reconstruct_and_cleanup()
|
|
|
|
// Reconstruct meta-chunks and chunks, then delete meta-chunk files
|
|
|
|
// 4) recovery_action()
|
2012-02-10 22:54:00 +00:00
|
|
|
// decide whether to start upload/download of chunks,
|
2012-08-03 16:41:00 +00:00
|
|
|
// and whether to delete chunk data currently on server.
|
|
|
|
// Also compute min_failures
|
2012-02-10 22:54:00 +00:00
|
|
|
//
|
2012-08-15 21:27:38 +00:00
|
|
|
void META_CHUNK::recovery_plan() {
|
2012-02-10 22:54:00 +00:00
|
|
|
vector<DATA_UNIT*> recoverable;
|
|
|
|
vector<DATA_UNIT*> present;
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
have_unrecoverable_children = false;
|
2012-08-08 21:37:51 +00:00
|
|
|
need_reconstruct = false;
|
|
|
|
needed_by_parent = false;
|
2012-08-12 06:54:20 +00:00
|
|
|
data_now_present = false;
|
2012-08-13 23:15:50 +00:00
|
|
|
keep_present = false;
|
2012-02-10 22:54:00 +00:00
|
|
|
|
|
|
|
// make lists of children in various states
|
|
|
|
//
|
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
DATA_UNIT* c = children[i];
|
|
|
|
c->in_recovery_set = false;
|
|
|
|
c->data_needed = false;
|
|
|
|
c->data_now_present = false;
|
2012-08-15 21:27:38 +00:00
|
|
|
c->recovery_plan();
|
2012-02-10 22:54:00 +00:00
|
|
|
switch (c->status) {
|
|
|
|
case PRESENT:
|
|
|
|
present.push_back(c);
|
|
|
|
break;
|
|
|
|
case RECOVERABLE:
|
|
|
|
recoverable.push_back(c);
|
|
|
|
break;
|
|
|
|
case UNRECOVERABLE:
|
|
|
|
have_unrecoverable_children = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// based on states of children, decide what state we're in
|
|
|
|
//
|
|
|
|
if ((int)(present.size()) >= coding.n) {
|
|
|
|
status = PRESENT;
|
|
|
|
sort(present.begin(), present.end(), compare_cost);
|
|
|
|
present.resize(coding.n);
|
|
|
|
cost = 0;
|
|
|
|
for (i=0; i<present.size(); i++) {
|
|
|
|
DATA_UNIT* c= present[i];
|
|
|
|
cost += c->cost;
|
|
|
|
c->in_recovery_set = true;
|
|
|
|
}
|
|
|
|
} else if ((int)(present.size() + recoverable.size()) >= coding.n) {
|
|
|
|
status = RECOVERABLE;
|
|
|
|
unsigned int j = coding.n - present.size();
|
|
|
|
sort(recoverable.begin(), recoverable.end(), compare_cost);
|
|
|
|
cost = 0;
|
|
|
|
for (i=0; i<present.size(); i++) {
|
|
|
|
DATA_UNIT* c= present[i];
|
|
|
|
c->in_recovery_set = true;
|
|
|
|
}
|
|
|
|
for (i=0; i<j; i++) {
|
|
|
|
DATA_UNIT* c= recoverable[i];
|
|
|
|
c->in_recovery_set = true;
|
|
|
|
cost += c->cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
status = UNRECOVERABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-21 20:55:09 +00:00
|
|
|
int META_CHUNK::recovery_action(double now) {
|
2012-02-10 22:54:00 +00:00
|
|
|
unsigned int i;
|
2012-02-24 03:09:56 +00:00
|
|
|
int retval;
|
|
|
|
|
2012-02-10 22:54:00 +00:00
|
|
|
if (data_now_present) {
|
|
|
|
status = PRESENT;
|
|
|
|
}
|
2013-05-09 21:53:26 +00:00
|
|
|
if (debug_status) {
|
|
|
|
printf(" meta chunk %s: status %s have_unrec_children %d\n",
|
|
|
|
name, status_str(status), have_unrecoverable_children
|
|
|
|
);
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
DATA_UNIT* c = children[i];
|
2013-05-09 21:53:26 +00:00
|
|
|
if (debug_status) {
|
|
|
|
printf(" child %s status %s in rec set %d\n",
|
|
|
|
c->name, status_str(c->status), c->in_recovery_set
|
|
|
|
);
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
switch (status) {
|
|
|
|
case PRESENT:
|
|
|
|
if (c->status == UNRECOVERABLE) {
|
|
|
|
c->data_now_present = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RECOVERABLE:
|
|
|
|
if (c->in_recovery_set && have_unrecoverable_children) {
|
|
|
|
c->data_needed = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UNRECOVERABLE:
|
|
|
|
break;
|
|
|
|
}
|
2012-02-24 03:09:56 +00:00
|
|
|
retval = c->recovery_action(now);
|
|
|
|
if (retval) return retval;
|
2012-02-10 22:54:00 +00:00
|
|
|
}
|
2012-08-15 21:27:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute min_failures: the smallest # of host failures
|
|
|
|
// that would make this unit unrecoverable.
|
|
|
|
//
|
|
|
|
int META_CHUNK::compute_min_failures() {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
DATA_UNIT* c = children[i];
|
|
|
|
c->compute_min_failures();
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
|
2012-08-03 16:41:00 +00:00
|
|
|
// Because of recovery action,
|
2012-02-29 20:58:45 +00:00
|
|
|
// some of our children may have changed status and fault tolerance,
|
|
|
|
// so ours may have changed too.
|
2012-02-10 22:54:00 +00:00
|
|
|
// Recompute them.
|
|
|
|
//
|
|
|
|
vector<DATA_UNIT*> recoverable;
|
|
|
|
vector<DATA_UNIT*> present;
|
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
DATA_UNIT* c = children[i];
|
|
|
|
switch (c->status) {
|
|
|
|
case PRESENT:
|
|
|
|
present.push_back(c);
|
|
|
|
break;
|
|
|
|
case RECOVERABLE:
|
|
|
|
recoverable.push_back(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((int)(present.size()) >= coding.n) {
|
|
|
|
status = PRESENT;
|
2013-05-09 21:53:26 +00:00
|
|
|
min_failures = dfile->policy.max_ft;
|
2012-02-10 22:54:00 +00:00
|
|
|
} else if ((int)(present.size() + recoverable.size()) >= coding.n) {
|
|
|
|
status = RECOVERABLE;
|
|
|
|
|
|
|
|
// our min_failures is the least X such that some X host failures
|
|
|
|
// would make this node unrecoverable
|
|
|
|
//
|
|
|
|
sort(recoverable.begin(), recoverable.end(), compare_min_failures);
|
|
|
|
min_failures = 0;
|
|
|
|
unsigned int k = coding.n - present.size();
|
|
|
|
// we'd need to recover K recoverable children
|
|
|
|
unsigned int j = recoverable.size() - k + 1;
|
|
|
|
// a loss of J recoverable children would make this impossible
|
|
|
|
|
|
|
|
// the loss of J recoverable children would make us unrecoverable
|
|
|
|
// Sum the min_failures of the J children with smallest min_failures
|
|
|
|
//
|
|
|
|
for (i=0; i<j; i++) {
|
|
|
|
DATA_UNIT* c = recoverable[i];
|
2013-05-09 21:53:26 +00:00
|
|
|
if (debug_ft) {
|
|
|
|
printf(" Min failures of %s: %d\n", c->name, c->min_failures);
|
|
|
|
};
|
2012-02-10 22:54:00 +00:00
|
|
|
min_failures += c->min_failures;
|
|
|
|
}
|
2013-05-09 21:53:26 +00:00
|
|
|
if (debug_ft) {
|
|
|
|
printf(" our min failures: %d\n", min_failures);
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
}
|
2012-02-21 20:55:09 +00:00
|
|
|
return 0;
|
2012-02-10 22:54:00 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 16:41:00 +00:00
|
|
|
// set the following:
|
|
|
|
// need_reconstruct: if we should reconstruct this from children
|
|
|
|
// need_present: not present, but needs to be present in the future
|
|
|
|
// keep_present: present, and needs to remain so
|
|
|
|
//
|
|
|
|
// Also set in children:
|
|
|
|
// needed_by_parent: ?
|
|
|
|
// keep_present
|
|
|
|
//
|
|
|
|
int META_CHUNK::decide_reconstruct() {
|
2012-03-11 01:51:07 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2012-08-03 16:41:00 +00:00
|
|
|
need_reconstruct = false;
|
2012-03-09 19:46:49 +00:00
|
|
|
if (some_child_is_unrecoverable()) {
|
|
|
|
if (status == PRESENT) {
|
|
|
|
need_reconstruct = true;
|
|
|
|
} else if (status == RECOVERABLE) {
|
|
|
|
need_present = true;
|
|
|
|
for (i=0; i<children.size(); i++) {
|
2012-03-11 01:51:07 +00:00
|
|
|
DATA_UNIT& c = *(children[i]);
|
2012-03-09 19:46:49 +00:00
|
|
|
if (c.in_recovery_set) {
|
|
|
|
if (c.status == PRESENT) {
|
|
|
|
c.keep_present = true;
|
|
|
|
} else {
|
|
|
|
c.need_present = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needed_by_parent) {
|
|
|
|
need_reconstruct = true;
|
|
|
|
}
|
2012-03-11 01:51:07 +00:00
|
|
|
if (need_reconstruct and !bottom_level) {
|
2012-08-03 16:41:00 +00:00
|
|
|
// mark n PRESENT children as needed_by_parent
|
2012-03-09 19:46:49 +00:00
|
|
|
int n = 0;
|
|
|
|
for (i=0; i<children.size(); i++) {
|
2012-03-11 01:51:07 +00:00
|
|
|
META_CHUNK& c = *(META_CHUNK*)children[i];
|
2012-03-09 19:46:49 +00:00
|
|
|
if (c.status == PRESENT) {
|
|
|
|
c.needed_by_parent = true;
|
|
|
|
n++;
|
|
|
|
if (n == coding.n) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 16:41:00 +00:00
|
|
|
|
|
|
|
// if we need to stay present, so do a quorum of our present children
|
|
|
|
//
|
2012-03-09 19:46:49 +00:00
|
|
|
if (keep_present) {
|
|
|
|
int n = 0;
|
|
|
|
for (i=0; i<children.size(); i++) {
|
2012-03-11 01:51:07 +00:00
|
|
|
DATA_UNIT& c = *(children[i]);
|
2012-03-09 19:46:49 +00:00
|
|
|
if (c.status == PRESENT) {
|
|
|
|
c.keep_present = true;
|
|
|
|
n++;
|
|
|
|
if (n == coding.n) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 16:41:00 +00:00
|
|
|
|
|
|
|
// recurse
|
|
|
|
//
|
2012-03-11 01:51:07 +00:00
|
|
|
if (!bottom_level) {
|
2012-03-09 19:46:49 +00:00
|
|
|
for (i=0; i<children.size(); i++) {
|
2012-03-11 01:51:07 +00:00
|
|
|
META_CHUNK& c = *(META_CHUNK*)children[i];
|
2012-03-09 19:46:49 +00:00
|
|
|
c.decide_reconstruct();
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 16:41:00 +00:00
|
|
|
return 0;
|
2012-03-09 19:46:49 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 16:41:00 +00:00
|
|
|
// Recurse first, so children will be available
|
|
|
|
// If needed, reconstruct this unit (from present children)
|
|
|
|
// and then expand() (for unrecoverable children)
|
|
|
|
//
|
2012-03-11 01:51:07 +00:00
|
|
|
int META_CHUNK::reconstruct_and_cleanup() {
|
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!bottom_level) {
|
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
META_CHUNK& c = *(META_CHUNK*)children[i];
|
|
|
|
retval = c.reconstruct_and_cleanup();
|
|
|
|
if (retval) return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (need_reconstruct) {
|
|
|
|
retval = decode();
|
|
|
|
if (retval) return retval;
|
|
|
|
retval = expand();
|
|
|
|
if (retval) return retval;
|
|
|
|
if (!needed_by_parent) {
|
|
|
|
delete_file();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-13 23:15:50 +00:00
|
|
|
// We just decoded this chunk from a subset of its children.
|
|
|
|
// Decide whether we should now encode it (to create all of its children)
|
|
|
|
//
|
2012-03-11 01:51:07 +00:00
|
|
|
int META_CHUNK::expand() {
|
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (bottom_level) {
|
|
|
|
bool do_encode = false;
|
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
CHUNK& c = *(CHUNK*)children[i];
|
|
|
|
if (c.status != PRESENT && c.need_more_replicas()) {
|
|
|
|
do_encode = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (do_encode) {
|
2012-08-13 23:15:50 +00:00
|
|
|
retval = encode(false);
|
2012-03-11 01:51:07 +00:00
|
|
|
if (retval) return retval;
|
2012-08-13 23:15:50 +00:00
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
CHUNK& c = *(CHUNK*)children[i];
|
|
|
|
c.present_on_server = true;
|
2012-03-11 01:51:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bool do_encode = false;
|
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
META_CHUNK& c = *(META_CHUNK*)children[i];
|
|
|
|
if (c.status == UNRECOVERABLE) {
|
|
|
|
do_encode = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (do_encode) {
|
2012-08-13 23:15:50 +00:00
|
|
|
retval = encode(false);
|
2012-03-11 01:51:07 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
META_CHUNK& c = *(META_CHUNK*)children[i];
|
|
|
|
if (c.status != UNRECOVERABLE) {
|
|
|
|
c.delete_file();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<children.size(); i++) {
|
|
|
|
META_CHUNK& c = *(META_CHUNK*)children[i];
|
|
|
|
if (c.status == UNRECOVERABLE) {
|
|
|
|
retval = c.expand();
|
|
|
|
if (retval) return retval;
|
|
|
|
c.delete_file();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-06-14 17:14:52 +00:00
|
|
|
|
2012-07-23 21:53:09 +00:00
|
|
|
///////////////// CHUNK ///////////////////////
|
|
|
|
|
2012-08-15 21:27:38 +00:00
|
|
|
void CHUNK::recovery_plan() {
|
2012-08-13 23:15:50 +00:00
|
|
|
keep_present = false;
|
2012-07-23 21:53:09 +00:00
|
|
|
if (present_on_server) {
|
|
|
|
status = PRESENT;
|
|
|
|
cost = 0;
|
2015-01-15 21:10:34 +00:00
|
|
|
} else if (!hosts.empty()) {
|
2012-08-03 16:41:00 +00:00
|
|
|
// if file is not present on server, assume that it's present
|
|
|
|
// on all hosts (otherwise we wouldn't have downloaded it).
|
|
|
|
//
|
2012-07-23 21:53:09 +00:00
|
|
|
status = RECOVERABLE;
|
|
|
|
cost = size;
|
|
|
|
if ((int)(hosts.size()) < parent->dfile->policy.replication) {
|
|
|
|
data_needed = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
status = UNRECOVERABLE;
|
|
|
|
}
|
2013-05-09 21:53:26 +00:00
|
|
|
if (debug_status) {
|
|
|
|
printf(" chunk %s: status %s\n", name, status_str(status));
|
|
|
|
}
|
2012-08-15 21:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CHUNK::compute_min_failures() {
|
|
|
|
if (present_on_server) {
|
2013-05-09 21:53:26 +00:00
|
|
|
min_failures = parent->dfile->policy.max_ft;
|
2012-08-15 21:27:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int nreplicas = 0;
|
|
|
|
set<VDA_CHUNK_HOST*>::iterator i;
|
2015-01-14 20:18:29 +00:00
|
|
|
for (i=hosts.begin(); i!=hosts.end(); ++i) {
|
2012-08-15 21:27:38 +00:00
|
|
|
VDA_CHUNK_HOST* ch = *i;
|
|
|
|
if (ch->present_on_host) {
|
|
|
|
nreplicas++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
min_failures = nreplicas;
|
2012-07-23 21:53:09 +00:00
|
|
|
return 0;
|
2012-06-14 17:14:52 +00:00
|
|
|
}
|
2012-06-15 20:49:11 +00:00
|
|
|
|
2012-07-23 21:53:09 +00:00
|
|
|
bool CHUNK::download_in_progress() {
|
|
|
|
set<VDA_CHUNK_HOST*>::iterator i;
|
2015-01-14 20:18:29 +00:00
|
|
|
for (i=hosts.begin(); i!=hosts.end(); ++i) {
|
2012-07-23 21:53:09 +00:00
|
|
|
VDA_CHUNK_HOST* ch = *i;
|
|
|
|
if (ch->download_in_progress()) return true;
|
2012-06-15 20:49:11 +00:00
|
|
|
}
|
2012-07-23 21:53:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHUNK::recovery_action(double now) {
|
|
|
|
int retval;
|
2020-05-02 18:49:28 +00:00
|
|
|
char buf[1024];
|
2012-07-23 21:53:09 +00:00
|
|
|
|
|
|
|
VDA_FILE_AUX* fp = parent->dfile;
|
|
|
|
if (data_now_present) {
|
|
|
|
present_on_server = true;
|
2013-05-09 21:53:26 +00:00
|
|
|
#if 0
|
2012-07-23 21:53:09 +00:00
|
|
|
fp->disk_usage.sample_inc(
|
|
|
|
size,
|
|
|
|
fp->collecting_stats(),
|
2013-05-09 21:53:26 +00:00
|
|
|
now,
|
|
|
|
"recovery_action: now present"
|
2012-07-23 21:53:09 +00:00
|
|
|
);
|
2013-05-09 21:53:26 +00:00
|
|
|
#endif
|
2012-07-23 21:53:09 +00:00
|
|
|
status = PRESENT;
|
|
|
|
}
|
|
|
|
if (status == PRESENT && (int)(hosts.size()) < fp->policy.replication) {
|
|
|
|
retval = assign();
|
|
|
|
if (retval) return retval;
|
2012-08-13 23:15:50 +00:00
|
|
|
keep_present = true;
|
2012-07-23 21:53:09 +00:00
|
|
|
}
|
|
|
|
if (download_in_progress()) {
|
2012-08-13 23:15:50 +00:00
|
|
|
keep_present = true;
|
2012-07-23 21:53:09 +00:00
|
|
|
}
|
2013-05-09 21:53:26 +00:00
|
|
|
if (debug_status) {
|
|
|
|
printf(" chunk %s: data_needed %d present_on_server %d keep_present %d\n",
|
|
|
|
name, data_needed, present_on_server, keep_present
|
|
|
|
);
|
|
|
|
}
|
2012-08-13 23:15:50 +00:00
|
|
|
if (present_on_server) {
|
|
|
|
if (!keep_present) {
|
2012-08-08 21:37:51 +00:00
|
|
|
sprintf(buf,
|
|
|
|
" chunk %s: not needed, removing from server\n", name
|
|
|
|
);
|
|
|
|
show_msg(buf);
|
|
|
|
retval = delete_file();
|
|
|
|
if (retval) return retval;
|
2012-07-23 21:53:09 +00:00
|
|
|
present_on_server = false;
|
|
|
|
status = RECOVERABLE;
|
|
|
|
min_failures = fp->policy.replication;
|
|
|
|
parent->dfile->disk_usage.sample_inc(
|
|
|
|
-size,
|
|
|
|
fp->collecting_stats(),
|
2013-05-09 21:53:26 +00:00
|
|
|
now,
|
|
|
|
"recovery_action: don't need"
|
2012-07-23 21:53:09 +00:00
|
|
|
);
|
|
|
|
}
|
2012-08-13 23:15:50 +00:00
|
|
|
} else {
|
|
|
|
if (data_needed) {
|
|
|
|
retval = start_upload();
|
|
|
|
if (retval) return retval;
|
|
|
|
}
|
2012-07-23 21:53:09 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2012-06-15 20:49:11 +00:00
|
|
|
}
|