Skip to content

Commit

Permalink
crush/CrushWrapper: add_simple_ruleset[_at] -> add_simple_rule[_at]
Browse files Browse the repository at this point in the history
Signed-off-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Jun 15, 2017
1 parent 6ac7594 commit 637e92e
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 68 deletions.
22 changes: 12 additions & 10 deletions src/crush/CrushWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1297,10 +1297,11 @@ void CrushWrapper::reweight(CephContext *cct)
}
}

int CrushWrapper::add_simple_ruleset_at(string name, string root_name,
string failure_domain_name,
string mode, int rule_type,
int rno, ostream *err)
int CrushWrapper::add_simple_rule_at(
string name, string root_name,
string failure_domain_name,
string mode, int rule_type,
int rno, ostream *err)
{
if (rule_exists(name)) {
if (err)
Expand Down Expand Up @@ -1383,13 +1384,14 @@ int CrushWrapper::add_simple_ruleset_at(string name, string root_name,
return rno;
}

int CrushWrapper::add_simple_ruleset(string name, string root_name,
string failure_domain_name,
string mode, int rule_type,
ostream *err)
int CrushWrapper::add_simple_rule(
string name, string root_name,
string failure_domain_name,
string mode, int rule_type,
ostream *err)
{
return add_simple_ruleset_at(name, root_name, failure_domain_name, mode,
rule_type, -1, err);
return add_simple_rule_at(name, root_name, failure_domain_name, mode,
rule_type, -1, err);
}

int CrushWrapper::get_rule_weight_osd_map(unsigned ruleno, map<int,float> *pmap)
Expand Down
15 changes: 9 additions & 6 deletions src/crush/CrushWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -997,14 +997,17 @@ class CrushWrapper {
return set_rule_step(ruleno, step, CRUSH_RULE_EMIT, 0, 0);
}

int add_simple_ruleset(string name, string root_name, string failure_domain_type,
string mode, int rule_type, ostream *err = 0);
int add_simple_rule(
string name, string root_name, string failure_domain_type,
string mode, int rule_type, ostream *err = 0);

/**
* @param rno ruleset id to use, -1 to pick the lowest available
* @param rno rule[set] id to use, -1 to pick the lowest available
*/
int add_simple_ruleset_at(string name, string root_name,
string failure_domain_type, string mode,
int rule_type, int rno, ostream *err = 0);
int add_simple_rule_at(
string name, string root_name,
string failure_domain_type, string mode,
int rule_type, int rno, ostream *err = 0);

int remove_rule(int ruleno);

Expand Down
13 changes: 7 additions & 6 deletions src/erasure-code/isa/ErasureCodeIsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ ErasureCodeIsa::create_ruleset(const string &name,
CrushWrapper &crush,
ostream *ss) const
{
int ruleid = crush.add_simple_ruleset(name,
ruleset_root,
ruleset_failure_domain,
"indep",
pg_pool_t::TYPE_ERASURE,
ss);
int ruleid = crush.add_simple_rule(
name,
ruleset_root,
ruleset_failure_domain,
"indep",
pg_pool_t::TYPE_ERASURE,
ss);

if (ruleid < 0)
return ruleid;
Expand Down
5 changes: 3 additions & 2 deletions src/erasure-code/jerasure/ErasureCodeJerasure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ int ErasureCodeJerasure::create_ruleset(const string &name,
CrushWrapper &crush,
ostream *ss) const
{
int ruleid = crush.add_simple_ruleset(name, ruleset_root, ruleset_failure_domain,
"indep", pg_pool_t::TYPE_ERASURE, ss);
int ruleid = crush.add_simple_rule(
name, ruleset_root, ruleset_failure_domain,
"indep", pg_pool_t::TYPE_ERASURE, ss);
if (ruleid < 0)
return ruleid;
else {
Expand Down
5 changes: 3 additions & 2 deletions src/erasure-code/shec/ErasureCodeShec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ int ErasureCodeShec::create_ruleset(const string &name,
CrushWrapper &crush,
ostream *ss) const
{
int ruleid = crush.add_simple_ruleset(name, ruleset_root, ruleset_failure_domain,
"indep", pg_pool_t::TYPE_ERASURE, ss);
int ruleid = crush.add_simple_rule(
name, ruleset_root, ruleset_failure_domain,
"indep", pg_pool_t::TYPE_ERASURE, ss);
if (ruleid < 0) {
return ruleid;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7977,7 +7977,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
ss << "rule " << name << " already exists";
err = 0;
} else {
int ruleno = newcrush.add_simple_ruleset(name, root, type, mode,
int ruleno = newcrush.add_simple_rule(name, root, type, mode,
pg_pool_t::TYPE_REPLICATED, &ss);
if (ruleno < 0) {
err = ruleno;
Expand Down
7 changes: 4 additions & 3 deletions src/osd/OSDMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3450,9 +3450,10 @@ int OSDMap::build_simple_crush_rules(
crush.get_type_name(cct->_conf->osd_crush_chooseleaf_type);

int r;
r = crush.add_simple_ruleset_at("replicated_ruleset", root, failure_domain,
"firstn", pg_pool_t::TYPE_REPLICATED,
crush_rule, ss);
r = crush.add_simple_rule_at(
"replicated_ruleset", root, failure_domain,
"firstn", pg_pool_t::TYPE_REPLICATED,
crush_rule, ss);
if (r < 0)
return r;
// do not add an erasure rule by default or else we will implicitly
Expand Down
18 changes: 9 additions & 9 deletions src/test/crush/CrushWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ TEST(CrushWrapper, dump_rules) {
"osd.0", loc));
}

// no ruleset by default
// no rule by default
{
Formatter *f = Formatter::create("json-pretty");
f->open_array_section("rules");
Expand All @@ -909,9 +909,9 @@ TEST(CrushWrapper, dump_rules) {
}

string name("NAME");
int ruleset = c->add_simple_ruleset(name, root_name, failure_domain_type,
"firstn", pg_pool_t::TYPE_ERASURE);
EXPECT_EQ(0, ruleset);
int rule = c->add_simple_rule(name, root_name, failure_domain_type,
"firstn", pg_pool_t::TYPE_ERASURE);
EXPECT_EQ(0, rule);

{
Formatter *f = Formatter::create("xml");
Expand All @@ -924,7 +924,7 @@ TEST(CrushWrapper, dump_rules) {

{
Formatter *f = Formatter::create("xml");
c->dump_rule(ruleset, f);
c->dump_rule(rule, f);
stringstream ss;
f->flush(ss);
delete f;
Expand Down Expand Up @@ -1032,7 +1032,7 @@ TEST(CrushWrapper, choose_args_compat) {
item = 2;
c.insert_item(g_ceph_context, item, weight, "osd.2", loc);

assert(c.add_simple_ruleset("rule1", "r11", "host", "firstn", pg_pool_t::TYPE_ERASURE) >= 0);
assert(c.add_simple_rule("rule1", "r11", "host", "firstn", pg_pool_t::TYPE_ERASURE) >= 0);

int id = c.get_item_id("b1");

Expand Down Expand Up @@ -1102,7 +1102,7 @@ TEST(CrushWrapper, remove_unused_root) {
loc["root"] = "default";
c.insert_item(g_ceph_context, item, weight, "osd.2", loc);

assert(c.add_simple_ruleset("rule1", "r11", "host", "firstn", pg_pool_t::TYPE_ERASURE) >= 0);
assert(c.add_simple_rule("rule1", "r11", "host", "firstn", pg_pool_t::TYPE_ERASURE) >= 0);
ASSERT_TRUE(c.name_exists("default"));
ASSERT_TRUE(c.name_exists("r11"));
ASSERT_TRUE(c.name_exists("r12"));
Expand Down Expand Up @@ -1346,7 +1346,7 @@ TEST(CrushWrapper, try_remap_rule) {
{
cout << "take + choose + emit" << std::endl;
ostringstream err;
int rule = c.add_simple_ruleset("one", "default", "osd", "firstn", 0, &err);
int rule = c.add_simple_rule("one", "default", "osd", "firstn", 0, &err);
ASSERT_EQ(rule, 0);

vector<int> orig = { 0, 3, 9 };
Expand Down Expand Up @@ -1382,7 +1382,7 @@ TEST(CrushWrapper, try_remap_rule) {
{
cout << "take + chooseleaf + emit" << std::endl;
ostringstream err;
int rule = c.add_simple_ruleset("two", "default", "host", "firstn", 0, &err);
int rule = c.add_simple_rule("two", "default", "host", "firstn", 0, &err);
ASSERT_EQ(rule, 1);

vector<int> orig = { 0, 3, 9 };
Expand Down
46 changes: 23 additions & 23 deletions src/test/crush/crush.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ std::unique_ptr<CrushWrapper> build_indep_map(CephContext *cct, int num_rack,
}
int ret;
int ruleno = 0;
int ruleset = 0;
ruleno = ruleset;
ret = c->add_rule(4, ruleset, 123, 1, 20, ruleno);
int rule = 0;
ruleno = rule;
ret = c->add_rule(4, rule, 123, 1, 20, ruleno);
assert(ret == ruleno);
ret = c->set_rule_step(ruleno, 0, CRUSH_RULE_SET_CHOOSELEAF_TRIES, 10, 0);
assert(ret == 0);
Expand Down Expand Up @@ -271,9 +271,9 @@ TEST(CRUSH, straw_zero) {
EXPECT_EQ(0, c->set_item_name(root0, root_name0));

string name0("rule0");
int ruleset0 = c->add_simple_ruleset(name0, root_name0, "osd",
int rule0 = c->add_simple_rule(name0, root_name0, "osd",
"firstn", pg_pool_t::TYPE_REPLICATED);
EXPECT_EQ(0, ruleset0);
EXPECT_EQ(0, rule0);

string root_name1("root1");
int root1;
Expand All @@ -282,18 +282,18 @@ TEST(CRUSH, straw_zero) {
EXPECT_EQ(0, c->set_item_name(root1, root_name1));

string name1("rule1");
int ruleset1 = c->add_simple_ruleset(name1, root_name1, "osd",
int rule1 = c->add_simple_rule(name1, root_name1, "osd",
"firstn", pg_pool_t::TYPE_REPLICATED);
EXPECT_EQ(1, ruleset1);
EXPECT_EQ(1, rule1);

c->finalize();

vector<unsigned> reweight(n, 0x10000);
for (int i=0; i<10000; ++i) {
vector<int> out0, out1;
c->do_rule(ruleset0, i, out0, 1, reweight, 0);
c->do_rule(rule0, i, out0, 1, reweight, 0);
ASSERT_EQ(1u, out0.size());
c->do_rule(ruleset1, i, out1, 1, reweight, 0);
c->do_rule(rule1, i, out1, 1, reweight, 0);
ASSERT_EQ(1u, out1.size());
ASSERT_EQ(out0[0], out1[0]);
//cout << i << "\t" << out0 << "\t" << out1 << std::endl;
Expand Down Expand Up @@ -336,9 +336,9 @@ TEST(CRUSH, straw_same) {
EXPECT_EQ(0, c->set_item_name(root0, root_name0));

string name0("rule0");
int ruleset0 = c->add_simple_ruleset(name0, root_name0, "osd",
int rule0 = c->add_simple_rule(name0, root_name0, "osd",
"firstn", pg_pool_t::TYPE_REPLICATED);
EXPECT_EQ(0, ruleset0);
EXPECT_EQ(0, rule0);

for (int i=0; i <n; ++i) {
items[i] = i;
Expand All @@ -352,9 +352,9 @@ TEST(CRUSH, straw_same) {
EXPECT_EQ(0, c->set_item_name(root1, root_name1));

string name1("rule1");
int ruleset1 = c->add_simple_ruleset(name1, root_name1, "osd",
int rule1 = c->add_simple_rule(name1, root_name1, "osd",
"firstn", pg_pool_t::TYPE_REPLICATED);
EXPECT_EQ(1, ruleset1);
EXPECT_EQ(1, rule1);

if (0) {
crush_bucket_straw *sb0 = reinterpret_cast<crush_bucket_straw*>(c->get_crush_map()->buckets[-1-root0]);
Expand Down Expand Up @@ -387,9 +387,9 @@ TEST(CRUSH, straw_same) {
int max = 100000;
for (int i=0; i<max; ++i) {
vector<int> out0, out1;
c->do_rule(ruleset0, i, out0, 1, reweight, 0);
c->do_rule(rule0, i, out0, 1, reweight, 0);
ASSERT_EQ(1u, out0.size());
c->do_rule(ruleset1, i, out1, 1, reweight, 0);
c->do_rule(rule1, i, out1, 1, reweight, 0);
ASSERT_EQ(1u, out1.size());
sum0[out0[0]]++;
sum1[out1[0]]++;
Expand Down Expand Up @@ -436,7 +436,7 @@ double calc_straw2_stddev(int *weights, int n, bool verbose)
c->set_item_name(root0, root_name0);

string name0("rule0");
int ruleset0 = c->add_simple_ruleset(name0, root_name0, "osd",
int rule0 = c->add_simple_rule(name0, root_name0, "osd",
"firstn", pg_pool_t::TYPE_REPLICATED);

int sum[n];
Expand All @@ -455,7 +455,7 @@ double calc_straw2_stddev(int *weights, int n, bool verbose)
int total = 1000000;
for (int i=0; i<total; ++i) {
vector<int> out;
c->do_rule(ruleset0, i, out, 1, reweight, 0);
c->do_rule(rule0, i, out, 1, reweight, 0);
sum[out[0]]++;
}

Expand Down Expand Up @@ -561,9 +561,9 @@ TEST(CRUSH, straw2_reweight) {
EXPECT_EQ(0, c->set_item_name(root0, root_name0));

string name0("rule0");
int ruleset0 = c->add_simple_ruleset(name0, root_name0, "osd",
int rule0 = c->add_simple_rule(name0, root_name0, "osd",
"firstn", pg_pool_t::TYPE_REPLICATED);
EXPECT_EQ(0, ruleset0);
EXPECT_EQ(0, rule0);

int changed = 1;
weights[changed] = weights[changed] / 10 * (rand() % 10);
Expand All @@ -577,9 +577,9 @@ TEST(CRUSH, straw2_reweight) {
EXPECT_EQ(0, c->set_item_name(root1, root_name1));

string name1("rule1");
int ruleset1 = c->add_simple_ruleset(name1, root_name1, "osd",
int rule1 = c->add_simple_rule(name1, root_name1, "osd",
"firstn", pg_pool_t::TYPE_REPLICATED);
EXPECT_EQ(1, ruleset1);
EXPECT_EQ(1, rule1);

int sum[n];
double totalweight = 0;
Expand All @@ -597,10 +597,10 @@ TEST(CRUSH, straw2_reweight) {
int total = 1000000;
for (int i=0; i<total; ++i) {
vector<int> out0, out1;
c->do_rule(ruleset0, i, out0, 1, reweight, 0);
c->do_rule(rule0, i, out0, 1, reweight, 0);
ASSERT_EQ(1u, out0.size());

c->do_rule(ruleset1, i, out1, 1, reweight, 0);
c->do_rule(rule1, i, out1, 1, reweight, 0);
ASSERT_EQ(1u, out1.size());

sum[out1[0]]++;
Expand Down
4 changes: 2 additions & 2 deletions src/test/erasure-code/ErasureCodeExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ErasureCodeExample : public ErasureCode {
int create_ruleset(const string &name,
CrushWrapper &crush,
ostream *ss) const override {
return crush.add_simple_ruleset(name, "default", "host",
"indep", pg_pool_t::TYPE_ERASURE, ss);
return crush.add_simple_rule(name, "default", "host",
"indep", pg_pool_t::TYPE_ERASURE, ss);
}

int minimum_to_decode(const set<int> &want_to_read,
Expand Down
7 changes: 4 additions & 3 deletions src/test/osd/TestOSDMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ class OSDMapTest : public testing::Test {
osdmap.apply_incremental(pending_inc);

// Create an EC ruleset and a pool using it
int r = osdmap.crush->add_simple_ruleset("erasure", "default", "osd",
"indep", pg_pool_t::TYPE_ERASURE,
&cerr);
int r = osdmap.crush->add_simple_rule(
"erasure", "default", "osd",
"indep", pg_pool_t::TYPE_ERASURE,
&cerr);

OSDMap::Incremental new_pool_inc(osdmap.get_epoch() + 1);
new_pool_inc.new_pool_max = osdmap.get_pool_max();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/crushtool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ int main(int argc, const char **argv)
cerr << "rule " << rule_name << " already exists" << std::endl;
return EXIT_FAILURE;
}
int r = crush.add_simple_ruleset(rule_name, rule_root, rule_type, rule_mode,
int r = crush.add_simple_rule(rule_name, rule_root, rule_type, rule_mode,
pg_pool_t::TYPE_REPLICATED, &err);
if (r < 0) {
cerr << err.str() << std::endl;
Expand Down

0 comments on commit 637e92e

Please sign in to comment.