From 2a7fcc35b8ceeff1e07da28b10ced4a2a4ed09ec Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Thu, 26 Dec 2013 11:20:41 +0100 Subject: [PATCH] osd: use CrushWrapper::add_simple_ruleset Replace the manually crafted ruleset in OSDMap::build_simple_crush_map* with calls to add_simple_ruleset. The generated ruleset do not have the same behavior but that presumably do not cause any backward compatibility problem because they are only created when a new cluster is being initialized. The prototypes of OSDMap::build_simple* are modified to allow for a return code and display of a human readable error message. The --osd-min-rep and --osd-max-rep configuration options are removed : they were only used in the code that was removed. Signed-off-by: Loic Dachary --- .../configuration/pool-pg-config-ref.rst | 14 ---- src/common/config_opts.h | 2 - src/osd/OSDMap.cc | 77 +++++++------------ src/osd/OSDMap.h | 9 ++- 4 files changed, 32 insertions(+), 70 deletions(-) diff --git a/doc/rados/configuration/pool-pg-config-ref.rst b/doc/rados/configuration/pool-pg-config-ref.rst index 82d9185205ecb..8c6632764a453 100644 --- a/doc/rados/configuration/pool-pg-config-ref.rst +++ b/doc/rados/configuration/pool-pg-config-ref.rst @@ -66,20 +66,6 @@ Ceph configuration file. :Default: ``1``. Typically a host containing one or more Ceph OSD Daemons. -``osd min rep`` - -:Description: The minimum number of replicas for a ruleset. -:Type: 32-bit Integer -:Default: ``1`` - - -``osd max rep`` - -:Description: The maximum number of replicas for a ruleset. -:Type: 32-bit Integer -:Default: ``10`` - - ``osd pool default crush rule`` :Description: The default CRUSH ruleset to use when creating a pool. diff --git a/src/common/config_opts.h b/src/common/config_opts.h index d2296b41f34cb..57b1b26b410e1 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -393,8 +393,6 @@ OPTION(osd_client_message_cap, OPT_U64, 100) // num client messages OPTION(osd_pg_bits, OPT_INT, 6) // bits per osd OPTION(osd_pgp_bits, OPT_INT, 6) // bits per osd OPTION(osd_crush_chooseleaf_type, OPT_INT, 1) // 1 = host -OPTION(osd_min_rep, OPT_INT, 1) -OPTION(osd_max_rep, OPT_INT, 10) OPTION(osd_pool_default_crush_rule, OPT_INT, CEPH_DEFAULT_CRUSH_REPLICATED_RULESET) OPTION(osd_pool_default_size, OPT_INT, 3) OPTION(osd_pool_default_min_size, OPT_INT, 0) // 0 means no specific default; ceph will use size-size/2 diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 0a1ad6bc8cd14..4a02ab4d36b55 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -1910,17 +1910,22 @@ int OSDMap::build_simple(CephContext *cct, epoch_t e, uuid_d &fsid, name_pool[*p] = pool; } + stringstream ss; + int r; if (nosd >= 0) - build_simple_crush_map(cct, *crush, nosd); + r = build_simple_crush_map(cct, *crush, nosd, &ss); else - build_simple_crush_map_from_conf(cct, *crush); + r = build_simple_crush_map_from_conf(cct, *crush, &ss); + if (r < 0) + lderr(cct) << ss.str() << dendl; + for (int i=0; i_conf; - crush.create(); // root @@ -1965,28 +1968,19 @@ void OSDMap::build_simple_crush_map(CephContext *cct, CrushWrapper& crush, crush.insert_item(cct, o, 1.0, name, loc); } - // rules - int minrep = conf->osd_min_rep; - int maxrep = conf->osd_max_rep; - assert(maxrep >= minrep); - { - crush_rule *rule = crush_make_rule(3, cct->_conf->osd_pool_default_crush_rule, - pg_pool_t::TYPE_REPLICATED, - minrep, maxrep); - assert(rule); - crush_rule_set_step(rule, 0, CRUSH_RULE_TAKE, rootid, 0); - crush_rule_set_step(rule, 1, - cct->_conf->osd_crush_chooseleaf_type ? CRUSH_RULE_CHOOSELEAF_FIRSTN : CRUSH_RULE_CHOOSE_FIRSTN, - CRUSH_CHOOSE_N, - cct->_conf->osd_crush_chooseleaf_type); - crush_rule_set_step(rule, 2, CRUSH_RULE_EMIT, 0, 0); - int rno = crush_add_rule(crush.crush, rule, -1); - crush.set_rule_name(rno, "replicated_rule"); - } + r = crush.add_simple_ruleset("replicated_ruleset", "default", "host", + "firstn", pg_pool_t::TYPE_REPLICATED, ss); + if (r < 0) + return r; + crush.finalize(); + + return 0; } -void OSDMap::build_simple_crush_map_from_conf(CephContext *cct, CrushWrapper& crush) +int OSDMap::build_simple_crush_map_from_conf(CephContext *cct, + CrushWrapper& crush, + stringstream *ss) { const md_config_t *conf = cct->_conf; @@ -2049,31 +2043,14 @@ void OSDMap::build_simple_crush_map_from_conf(CephContext *cct, CrushWrapper& cr crush.insert_item(cct, o, 1.0, *i, loc); } - // rules - int minrep = conf->osd_min_rep; - int maxrep = conf->osd_max_rep; - { - crush_rule *rule = crush_make_rule(3, cct->_conf->osd_pool_default_crush_rule, - pg_pool_t::TYPE_REPLICATED, - minrep, maxrep); - assert(rule); - crush_rule_set_step(rule, 0, CRUSH_RULE_TAKE, rootid, 0); - - if (racks.size() > 3) { - // spread replicas across hosts - crush_rule_set_step(rule, 1, CRUSH_RULE_CHOOSELEAF_FIRSTN, CRUSH_CHOOSE_N, 2); - } else if (hosts.size() > 1) { - // spread replicas across hosts - crush_rule_set_step(rule, 1, CRUSH_RULE_CHOOSELEAF_FIRSTN, CRUSH_CHOOSE_N, 1); - } else { - // just spread across osds - crush_rule_set_step(rule, 1, CRUSH_RULE_CHOOSE_FIRSTN, CRUSH_CHOOSE_N, 0); - } - crush_rule_set_step(rule, 2, CRUSH_RULE_EMIT, 0, 0); - int rno = crush_add_rule(crush.crush, rule, -1); - crush.set_rule_name(rno, "replicated_rule"); - } + r = crush.add_simple_ruleset("replicated_ruleset", "default", "host", + "firstn", pg_pool_t::TYPE_REPLICATED, ss); + if (r < 0) + return r; + crush.finalize(); + + return 0; } diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 87e8e68f49df3..dae46450dca0c 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -616,10 +616,11 @@ public: int build_simple(CephContext *cct, epoch_t e, uuid_d &fsid, int num_osd, int pg_bits, int pgp_bits); static int _build_crush_types(CrushWrapper& crush); - static void build_simple_crush_map(CephContext *cct, CrushWrapper& crush, - int num_osd); - static void build_simple_crush_map_from_conf(CephContext *cct, - CrushWrapper& crush); + static int build_simple_crush_map(CephContext *cct, CrushWrapper& crush, + int num_osd, stringstream *ss); + static int build_simple_crush_map_from_conf(CephContext *cct, + CrushWrapper& crush, + stringstream *ss); bool crush_ruleset_in_use(int ruleset) const; -- 2.39.5