#include "../crush.h" using namespace crush; #include #include #include using namespace std; 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 n, float f, int buckettype) { Hash h(73232313); // crush Crush c; int ndisks = 0; // bucket Bucket *b; if (buckettype == 0) b = new TreeBucket(1); else if (buckettype == 1 || buckettype == 2) b = new ListBucket(1); else if (buckettype == 3) b = new StrawBucket(1); else if (buckettype == 4) b = new UniformBucket(0,0); for (int i=0; iadd_item(ndisks++,1); c.add_bucket(b); int root = b->get_id(); //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 = 1000; 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); // ORIGINAL place(c, rule, numpg, numrep, placement1); int olddisks = ndisks; // add item if (buckettype == 2) { // start over! ndisks = 0; b = new ListBucket(1); for (int i=0; i<=n; i++) b->add_item(ndisks++,1); c.add_bucket(b); root = b->get_id(); rule.steps.clear(); 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)); } else b->add_item(ndisks++, 1); // ADDED //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