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-02-10 22:54:00 +00:00
|
|
|
// classes for volunteer data archival (VDA)
|
|
|
|
//
|
|
|
|
// Note: these classes are used by both the simulator (ssim.cpp)
|
|
|
|
// and the VDA daemon (vdad.cpp)
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "boinc_db.h"
|
2012-01-20 20:21:29 +00:00
|
|
|
|
2012-03-08 22:42:44 +00:00
|
|
|
#include "stats.h"
|
2012-02-24 22:55:11 +00:00
|
|
|
#include "vda_policy.h"
|
|
|
|
|
2012-02-16 00:08:40 +00:00
|
|
|
// a host with rpc_time < now-HOST_TIMEOUT is considered dead.
|
|
|
|
// Make sure you set next_rpc_delay accordingly (e.g., to 86400)
|
|
|
|
//
|
|
|
|
#define VDA_HOST_TIMEOUT (86400*4)
|
|
|
|
|
2012-06-14 17:14:52 +00:00
|
|
|
extern void show_msg(char*);
|
|
|
|
extern char* time_str(double);
|
2012-06-15 20:49:11 +00:00
|
|
|
extern const char* status_str(int status);
|
2012-06-14 17:14:52 +00:00
|
|
|
|
2012-02-13 08:41:48 +00:00
|
|
|
struct META_CHUNK;
|
|
|
|
|
2012-02-10 22:54:00 +00:00
|
|
|
struct VDA_FILE_AUX : VDA_FILE {
|
|
|
|
POLICY policy;
|
2012-02-13 08:41:48 +00:00
|
|
|
META_CHUNK* meta_chunk;
|
2012-02-10 22:54:00 +00:00
|
|
|
|
2012-02-29 20:58:45 +00:00
|
|
|
VDA_FILE_AUX(){
|
|
|
|
meta_chunk = NULL;
|
|
|
|
}
|
|
|
|
VDA_FILE_AUX(DB_VDA_FILE f) : VDA_FILE(f){}
|
2012-02-16 00:08:40 +00:00
|
|
|
|
2012-02-10 22:54:00 +00:00
|
|
|
// the following stuff is for the simulator
|
2012-02-16 00:08:40 +00:00
|
|
|
//
|
2012-02-10 22:54:00 +00:00
|
|
|
double accounting_start_time;
|
|
|
|
STATS_ITEM disk_usage;
|
|
|
|
STATS_ITEM upload_rate;
|
|
|
|
STATS_ITEM download_rate;
|
|
|
|
STATS_ITEM fault_tolerance;
|
|
|
|
|
|
|
|
int pending_init_downloads;
|
|
|
|
// # of initial downloads pending.
|
|
|
|
// When this is zero, we start collecting stats for the file
|
|
|
|
|
|
|
|
inline bool collecting_stats() {
|
|
|
|
return (pending_init_downloads == 0);
|
|
|
|
}
|
2012-02-15 04:40:50 +00:00
|
|
|
|
|
|
|
// the following for vdad
|
|
|
|
//
|
2012-02-16 00:08:40 +00:00
|
|
|
std::vector<int> available_hosts;
|
|
|
|
// list of IDs of hosts with no chunks of this file
|
2012-02-15 04:40:50 +00:00
|
|
|
int init();
|
|
|
|
int get_state();
|
2012-02-16 00:08:40 +00:00
|
|
|
int choose_host();
|
2012-02-10 22:54:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define PRESENT 0
|
|
|
|
#define RECOVERABLE 1
|
|
|
|
#define UNRECOVERABLE 2
|
|
|
|
|
|
|
|
// base class for chunks and meta-chunks
|
|
|
|
//
|
|
|
|
struct DATA_UNIT {
|
2012-02-21 20:55:09 +00:00
|
|
|
virtual int recovery_plan(){return 0;};
|
|
|
|
virtual int recovery_action(double){return 0;};
|
2012-02-10 22:54:00 +00:00
|
|
|
int status;
|
|
|
|
bool in_recovery_set;
|
|
|
|
bool data_now_present;
|
|
|
|
bool data_needed;
|
|
|
|
double cost;
|
|
|
|
int min_failures;
|
|
|
|
// min # of host failures that would make this unrecoverable
|
|
|
|
char name[64];
|
2012-03-11 01:51:07 +00:00
|
|
|
char dir[1024];
|
|
|
|
bool keep_present;
|
|
|
|
bool need_present;
|
|
|
|
|
|
|
|
int delete_file();
|
2012-02-10 22:54:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct META_CHUNK : DATA_UNIT {
|
|
|
|
std::vector<DATA_UNIT*> children;
|
|
|
|
META_CHUNK* parent;
|
|
|
|
int n_children_present;
|
|
|
|
bool have_unrecoverable_children;
|
|
|
|
VDA_FILE_AUX* dfile;
|
|
|
|
bool uploading;
|
|
|
|
CODING coding;
|
2012-03-11 01:51:07 +00:00
|
|
|
bool bottom_level;
|
|
|
|
bool need_reconstruct;
|
|
|
|
bool needed_by_parent;
|
|
|
|
double child_size;
|
2012-02-10 22:54:00 +00:00
|
|
|
|
2012-02-15 04:40:50 +00:00
|
|
|
// used by ssim
|
2012-02-10 22:54:00 +00:00
|
|
|
META_CHUNK(
|
|
|
|
VDA_FILE_AUX* d, META_CHUNK* par, double size,
|
|
|
|
int coding_level, int index
|
|
|
|
);
|
|
|
|
|
2012-02-15 04:40:50 +00:00
|
|
|
// used by vdad
|
2012-02-24 21:13:00 +00:00
|
|
|
META_CHUNK(VDA_FILE_AUX* d, META_CHUNK* p, int index);
|
|
|
|
int init(const char* dir, POLICY&, int level);
|
|
|
|
int get_state(const char* dir, POLICY&, int level);
|
2012-02-15 04:40:50 +00:00
|
|
|
|
2012-02-21 20:55:09 +00:00
|
|
|
virtual int recovery_plan();
|
|
|
|
virtual int recovery_action(double);
|
2012-03-11 01:51:07 +00:00
|
|
|
|
|
|
|
void decide_reconstruct();
|
|
|
|
int reconstruct_and_cleanup();
|
|
|
|
int expand();
|
|
|
|
bool some_child_is_unrecoverable() {
|
|
|
|
for (unsigned int i=0; i<children.size(); i++) {
|
|
|
|
DATA_UNIT& d = *(children[i]);
|
|
|
|
if (d.status == UNRECOVERABLE) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int decode();
|
|
|
|
int encode();
|
2012-02-10 22:54:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CHUNK : DATA_UNIT {
|
|
|
|
std::set<VDA_CHUNK_HOST*> hosts;
|
|
|
|
META_CHUNK* parent;
|
|
|
|
double size;
|
|
|
|
bool present_on_server;
|
2012-03-11 01:51:07 +00:00
|
|
|
bool new_present_on_server;
|
2012-02-10 22:54:00 +00:00
|
|
|
|
|
|
|
CHUNK(META_CHUNK* mc, double s, int index);
|
|
|
|
|
2012-02-24 22:55:11 +00:00
|
|
|
int start_upload();
|
2012-02-10 22:54:00 +00:00
|
|
|
void host_failed(VDA_CHUNK_HOST* p);
|
|
|
|
bool download_in_progress();
|
|
|
|
void upload_complete();
|
|
|
|
void download_complete();
|
2012-02-21 20:55:09 +00:00
|
|
|
int assign();
|
|
|
|
virtual int recovery_plan();
|
|
|
|
virtual int recovery_action(double);
|
2012-03-11 01:51:07 +00:00
|
|
|
bool need_more_replicas() {
|
|
|
|
return ((int)hosts.size() < parent->dfile->policy.replication);
|
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
};
|