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)
|
2012-07-07 19:44:48 +00:00
|
|
|
// and the VDA server software (vdad.cpp, sched_vda.cpp)
|
2012-02-10 22:54:00 +00:00
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2012-08-26 21:24:18 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2012-02-10 22:54:00 +00:00
|
|
|
|
|
|
|
#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-08-25 04:09:24 +00:00
|
|
|
inline bool outdated_client(HOST& h) {
|
|
|
|
char* p = strstr(h.serialnum, "BOINC|");
|
|
|
|
if (!p) return true;
|
|
|
|
int n = atoi(p + strlen("BOINC|"));
|
|
|
|
return (n < 7);
|
|
|
|
}
|
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-08-01 20:04:05 +00:00
|
|
|
// the following 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-08-22 04:02:52 +00:00
|
|
|
VDA_FILE_AUX(){
|
|
|
|
meta_chunk = NULL;
|
|
|
|
}
|
2012-02-15 04:40:50 +00:00
|
|
|
|
|
|
|
// the following for vdad
|
|
|
|
//
|
2012-08-22 04:02:52 +00:00
|
|
|
DB_HOST enum_host;
|
|
|
|
char enum_query[256];
|
|
|
|
int max_chunks;
|
|
|
|
int last_id;
|
|
|
|
bool enum_active;
|
|
|
|
bool found_this_scan;
|
|
|
|
bool found_any_this_scan;
|
|
|
|
bool found_any_this_enum;
|
|
|
|
|
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-08-22 04:02:52 +00:00
|
|
|
|
|
|
|
VDA_FILE_AUX(DB_VDA_FILE f) : VDA_FILE(f) {
|
|
|
|
max_chunks = 0;
|
|
|
|
enum_active = false;
|
2012-08-22 18:23:01 +00:00
|
|
|
last_id = 0;
|
2012-08-22 04:02:52 +00:00
|
|
|
}
|
2012-02-10 22:54:00 +00:00
|
|
|
};
|
|
|
|
|
2012-08-13 23:15:50 +00:00
|
|
|
#define PRESENT 0
|
2012-08-03 16:41:00 +00:00
|
|
|
// this unit is present on the server
|
2012-08-01 20:04:05 +00:00
|
|
|
// (in the case of meta-chunks, this means that enough chunks
|
|
|
|
// to reconstruct the meta-chunk are present on the server)
|
2012-08-13 23:15:50 +00:00
|
|
|
#define RECOVERABLE 1
|
2012-08-03 16:41:00 +00:00
|
|
|
// this unit is not present, but could be recovered from data on clients
|
2012-08-13 23:15:50 +00:00
|
|
|
#define UNRECOVERABLE 2
|
2012-08-01 20:04:05 +00:00
|
|
|
// not present or recoverable
|
2012-02-10 22:54:00 +00:00
|
|
|
|
|
|
|
// base class for chunks and meta-chunks
|
|
|
|
//
|
|
|
|
struct DATA_UNIT {
|
2012-08-15 21:27:38 +00:00
|
|
|
virtual void recovery_plan(){};
|
2012-02-21 20:55:09 +00:00
|
|
|
virtual int recovery_action(double){return 0;};
|
2012-08-15 21:27:38 +00:00
|
|
|
virtual int compute_min_failures(){return 0;};
|
|
|
|
virtual int upload_all(){return 0;};
|
2012-08-01 20:04:05 +00:00
|
|
|
|
|
|
|
char name[64];
|
|
|
|
char dir[1024];
|
|
|
|
|
|
|
|
// the following are determined during recovery_plan()
|
|
|
|
// and used during recovery_action()
|
|
|
|
//
|
2012-02-10 22:54:00 +00:00
|
|
|
int status;
|
|
|
|
bool in_recovery_set;
|
2012-08-01 20:04:05 +00:00
|
|
|
// if we need to reconstruct the parent, we'll use this unit
|
2012-02-10 22:54:00 +00:00
|
|
|
bool data_now_present;
|
2012-08-01 20:04:05 +00:00
|
|
|
// vdad: this unit was initially unrecoverable,
|
2012-08-12 06:54:20 +00:00
|
|
|
// but the parent has become present so now this unit is present
|
2012-02-10 22:54:00 +00:00
|
|
|
bool data_needed;
|
2012-08-13 23:15:50 +00:00
|
|
|
// this unit is not currently present;
|
2012-08-01 20:04:05 +00:00
|
|
|
// we need to take action (e.g. start uploads)
|
2012-08-13 23:15:50 +00:00
|
|
|
// to make it present
|
2012-02-10 22:54:00 +00:00
|
|
|
double cost;
|
2012-03-11 01:51:07 +00:00
|
|
|
bool keep_present;
|
2012-08-01 20:04:05 +00:00
|
|
|
// this unit is present and we need to keep it present
|
2012-03-11 01:51:07 +00:00
|
|
|
bool need_present;
|
2012-08-01 20:04:05 +00:00
|
|
|
// delete this??
|
|
|
|
int min_failures;
|
|
|
|
// min # of host failures that would make this unrecoverable
|
2012-03-11 01:51:07 +00:00
|
|
|
|
|
|
|
int delete_file();
|
2012-08-01 20:04:05 +00:00
|
|
|
// delete the file on server corresponding to this unit
|
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;
|
|
|
|
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-08-15 21:27:38 +00:00
|
|
|
virtual void recovery_plan();
|
2012-02-21 20:55:09 +00:00
|
|
|
virtual int recovery_action(double);
|
2012-08-15 21:27:38 +00:00
|
|
|
virtual int compute_min_failures();
|
|
|
|
virtual int upload_all();
|
2012-03-11 01:51:07 +00:00
|
|
|
|
2012-08-03 16:41:00 +00:00
|
|
|
int decide_reconstruct();
|
2012-03-11 01:51:07 +00:00
|
|
|
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();
|
2012-08-13 23:15:50 +00:00
|
|
|
int encode(bool first);
|
2012-08-15 21:27:38 +00:00
|
|
|
int reconstruct();
|
2012-07-23 21:53:09 +00:00
|
|
|
|
|
|
|
// used by vda
|
|
|
|
void print_status(int indent_level);
|
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;
|
|
|
|
|
|
|
|
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();
|
2012-08-15 21:27:38 +00:00
|
|
|
virtual void recovery_plan();
|
2012-02-21 20:55:09 +00:00
|
|
|
virtual int recovery_action(double);
|
2012-08-15 21:27:38 +00:00
|
|
|
virtual int compute_min_failures();
|
|
|
|
virtual int upload_all();
|
2012-03-11 01:51:07 +00:00
|
|
|
bool need_more_replicas() {
|
|
|
|
return ((int)hosts.size() < parent->dfile->policy.replication);
|
|
|
|
}
|
2012-07-23 21:53:09 +00:00
|
|
|
|
|
|
|
// used by vda
|
|
|
|
void print_status(int indent_level);
|
2012-08-15 21:27:38 +00:00
|
|
|
|
|
|
|
// used by vdad
|
|
|
|
int start_upload_from_host(VDA_CHUNK_HOST&);
|
2012-02-10 22:54:00 +00:00
|
|
|
};
|
2012-07-07 19:44:48 +00:00
|
|
|
|
|
|
|
// names
|
|
|
|
//
|
|
|
|
// chunk name: c1.c2.cn
|
|
|
|
// (in VDA_CHUNK_HOST)
|
|
|
|
//
|
|
|
|
// chunk/file name: c1.c2.cn_filename.ext
|
|
|
|
//
|
|
|
|
// physical file name: vda_hostid_c1.c2.cn_filename.ext
|
|
|
|
|
|
|
|
inline void physical_file_name(
|
|
|
|
int hostid, char* chunk_name, char* file_name, char* buf
|
|
|
|
) {
|
|
|
|
sprintf(buf, "vda_%d_%s_%s", hostid, chunk_name, file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void physical_file_name(
|
|
|
|
int hostid, char* chunk_file_name, char* buf
|
|
|
|
) {
|
|
|
|
sprintf(buf, "vda_%d_%s", hostid, chunk_file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-08-17 23:27:44 +00:00
|
|
|
// download WU/result name: download_vda_c1.c2.cn_filename.ext
|
2012-07-07 19:44:48 +00:00
|
|
|
//
|
2012-08-17 23:27:44 +00:00
|
|
|
// upload WU/result name: upload_vda_c1.c2.cn_filename.ext
|