示例#1
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();
    }
}
示例#2
0
// 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;
}