#include "../crush.h" using namespace crush; #include #include #include using namespace std; Bucket *make_bucket(Crush& c, vector& wid, int h, map< int, list >& buckets, int& ndisks) { if (h == 0) { // uniform Hash hash(123); vector disks; for (int i=0; imake_primes(hash); c.add_bucket(b); //cout << h << " uniformbucket with " << wid[h] << " disks" << endl; buckets[h].push_back(b); return b; } else { // mixed Bucket *b = new TreeBucket(h+1); c.add_bucket(b); for (int i=0; iadd_item(n->get_id(), n->get_weight()); n->set_parent(b->get_id()); } buckets[h].push_back(b); //cout << b->get_id() << " mixedbucket with " << wid[h] << " at " << h << endl; return b; } } int make_hierarchy(Crush& c, vector& wid, map< int, list >& buckets, int& ndisks) { Bucket *b = make_bucket(c, wid, wid.size()-1, buckets, ndisks); return b->get_id(); } void place(Crush& c, Rule& rule, int numpg, int numrep, vector& ocount) { vector v(numrep); //map ocount; for (int x=1; x<=numpg; x++) { //cout << H(x) << "\t" << h(x) << endl; c.do_rule(rule, x, v); //cout << "v = " << v << endl;// " " << v[0] << " " << v[1] << " " << v[2] << endl; bool bad = false; for (int i=0; i wid; wid.push_back(10); wid.push_back(2); map< int, list > buckets; root = make_hierarchy(c, wid, buckets, ndisks); // add small bucket vector disks; for (int i=0; i<3; i++) disks.push_back(ndisks++); UniformBucket *b = new UniformBucket(1, 0, 1, disks); b->make_primes(h); Bucket *o = buckets[1].back(); c.add_bucket(b); //cout << " adding under " << o->get_id() << endl; c.add_item(o->get_id(), b->get_id(), b->get_weight()); // rule int numrep = 6; Rule rule; rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, root)); rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, numrep, 0)); rule.steps.push_back(RuleStep(CRUSH_RULE_EMIT)); //c.overload[10] = .1; int pg_per = 10000; int numpg = pg_per*ndisks/numrep; vector ocount(ndisks); c.print(cout, root); place(c, rule, numpg, numrep, ocount); for (int i=0; i