// if there aren't enough replicas of this chunk, // pick new hosts and start downloads // int CHUNK::assign() { if (!present_on_server) return 0; VDA_FILE_AUX* fp = parent->dfile; while ((int)(hosts.size()) < fp->policy.replication) { #if 0 if (parent->dfile->unused_hosts.size() == 0) { die("no more hosts!\n"); } set<SIM_HOST*>::iterator i = fp->unused_hosts.begin(); SIM_HOST* h = *i; fp->unused_hosts.erase(i); #else SIM_HOST* h = new SIM_HOST; sim.insert(h); #endif CHUNK_ON_HOST *c = new CHUNK_ON_HOST(); sprintf(c->physical_file_name, "chunk %s on host %d", name, h->id); #ifdef EVENT_DEBUG printf("%s: assigning chunk %s to host %d\n", now_str(), name, h->id); #endif c->host = h; c->chunk = this; h->chunks.insert(c); hosts.insert(c); c->start_download(); } return 0; }
// if there aren't enough replicas of this chunk, // pick new hosts and start downloads // void CHUNK::assign() { if (!present_on_server) return; while ((int)(hosts.size()) < p.replication) { #if 0 if (parent->dfile->unused_hosts.size() == 0) { die("no more hosts!\n"); } set<HOST*>::iterator i = parent->dfile->unused_hosts.begin(); HOST* h = *i; parent->dfile->unused_hosts.erase(i); #else HOST* h = new HOST; sim.insert(h); #endif CHUNK_ON_HOST *c = new CHUNK_ON_HOST(); sprintf(c->name, "chunk %s on host %d", name, h->id); #ifdef EVENT_DEBUG printf("%s: assigning chunk %s to host %d\n", now_str(), name, h->id); #endif c->host = h; c->chunk = this; h->chunks.insert(c); hosts.insert(c); c->start_download(); } }
bool CHUNK::download_in_progress() { set<CHUNK_ON_HOST*>::iterator i; for (i=hosts.begin(); i!=hosts.end(); i++) { CHUNK_ON_HOST* c = *i; if (c->download_in_progress()) return true; } return false; }
void CHUNK::start_upload() { // if no upload of this chunk is in progress, start one. // NOTE: all instances are inherently present_on_host, // since this is only called if chunk is not present on server // CHUNK_ON_HOST* c; set<CHUNK_ON_HOST*>::iterator i; for (i=hosts.begin(); i!=hosts.end(); i++) { c = *i; if (c->transfer_in_progress) return; } c = *(hosts.begin()); c->start_upload(); }
// the host has failed // void SIM_HOST::handle() { set<SIM_HOST*>::iterator i = hosts.find(this); hosts.erase(i); #ifdef EVENT_DEBUG printf("%s: host %d failed\n", now_str(), id); #endif set<CHUNK_ON_HOST*>::iterator p; for (p = chunks.begin(); p != chunks.end(); p++) { CHUNK_ON_HOST* c = *p; c->chunk->host_failed(c); c->remove(); delete c; } }