#include "../crush.h" using namespace crush; #include #include #include using namespace std; int buckettype = 2; // 0 = mixed, 1 = linear, 2 = straw int big_one_skip = 255; int big_one_size; Bucket *big_one = 0; Bucket *make_bucket(Crush& c, vector& wid, int h, map< int, list >& buckets, int& ndisks) { if (h == 0) { // uniform Hash hash(123); vector disks; int s = wid[h]; if (big_one_skip > 0) big_one_skip--; if (!big_one_skip && !big_one) s = big_one_size; for (int i=0; imake_primes(hash); c.add_bucket(b); //cout << h << " uniformbucket with " << wid[h] << " disks " << disks.size()<< endl; buckets[h].push_back(b); return b; } else { // mixed Bucket *b; if (buckettype == 0) b = new TreeBucket(h+1); else if (buckettype == 1) b = new ListBucket(h+1); else if (buckettype == 2) b = new StrawBucket(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, map >& placement) { 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::iterator it = ocount.begin(); it != ocount.end(); it++) cout << it->first << "\t" << it->second << endl; } float testmovement(int depth, int branching, int udisks, int add) { Hash h(73232313); // crush Crush c; // buckets int root = -1; int ndisks = 0; vector wid; wid.push_back(udisks); for (int d=1; d > buckets; big_one_size = add; big_one = 0; //cout << "making tree" << endl; root = make_hierarchy(c, wid, buckets, ndisks); //c.print(cout, root); // rule int numrep = 2; 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 = 100; int numpg = pg_per*ndisks/numrep; vector ocount(ndisks); /* cout << ndisks << " disks, " << endl; cout << pg_per << " pgs per disk" << endl; cout << numpg << " logical pgs" << endl; cout << "numrep is " << numrep << endl; */ map > placement1, placement2; //c.print(cout, root); int olddisks = ndisks; place(c, rule, numpg, numrep, placement1); if (1) { // remove disks assert(big_one); c.adjust_item(big_one->get_id(), 0); } int newdisks = ndisks - add; //c.print(cout, root); place(c, rule, numpg, numrep, placement2); int moved = 0; for (int x=1; x<=numpg; x++) if (placement1[x] != placement2[x]) for (int j=0; j >::iterator i = r.begin(); i != r.end(); i++) { cout << i->first; for (map::iterator j = i->second.begin(); j != i->second.end(); j++) cout << "\t" << j->first << "\t" << j->second; cout << endl; } */ }