From c0c7f45522355f2c07994a1ceb10501d0f746766 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 23 May 2018 12:40:36 -0500 Subject: [PATCH] mon/MonMap: simplify encode() flow We only need legacy_mon_addr for the !MONENC case. Signed-off-by: Sage Weil --- src/mon/MonMap.cc | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc index f09ec68e25789..6e87f4df61435 100644 --- a/src/mon/MonMap.cc +++ b/src/mon/MonMap.cc @@ -136,28 +136,14 @@ void MonMap::calc_ranks() { void MonMap::encode(bufferlist& blist, uint64_t con_features) const { - /* we keep the mon_addr map when encoding to ensure compatibility - * with clients and other monitors that do not yet support the 'mons' - * map. This map keeps its original behavior, containing a mapping of - * monitor id (i.e., 'foo' in 'mon.foo') to the monitor's public - * address -- which is obtained from the public address of each entry - * in the 'mons' map. - */ - map mon_addr; - for (map::const_iterator p = mon_info.begin(); - p != mon_info.end(); - ++p) { - mon_addr[p->first] = p->second.public_addr; - } - if ((con_features & CEPH_FEATURE_MONNAMES) == 0) { using ceph::encode; __u16 v = 1; encode(v, blist); encode_raw(fsid, blist); encode(epoch, blist); - vector mon_inst(mon_addr.size()); - for (unsigned n = 0; n < mon_addr.size(); n++) + vector mon_inst(ranks.size()); + for (unsigned n = 0; n < ranks.size(); n++) mon_inst[n] = get_inst(n); encode(mon_inst, blist, con_features); encode(last_changed, blist); @@ -166,12 +152,26 @@ void MonMap::encode(bufferlist& blist, uint64_t con_features) const } if ((con_features & CEPH_FEATURE_MONENC) == 0) { + /* we keep the mon_addr map when encoding to ensure compatibility + * with clients and other monitors that do not yet support the 'mons' + * map. This map keeps its original behavior, containing a mapping of + * monitor id (i.e., 'foo' in 'mon.foo') to the monitor's public + * address -- which is obtained from the public address of each entry + * in the 'mons' map. + */ + map legacy_mon_addr; + for (map::const_iterator p = mon_info.begin(); + p != mon_info.end(); + ++p) { + legacy_mon_addr[p->first] = p->second.public_addr; + } + using ceph::encode; __u16 v = 2; encode(v, blist); encode_raw(fsid, blist); encode(epoch, blist); - encode(mon_addr, blist, con_features); + encode(legacy_mon_addr, blist, con_features); encode(last_changed, blist); encode(created, blist); } @@ -184,7 +184,6 @@ void MonMap::encode(bufferlist& blist, uint64_t con_features) const encode(created, blist); encode(persistent_features, blist); encode(optional_features, blist); - // this superseeds 'mon_addr' encode(mon_info, blist, con_features); ENCODE_FINISH(blist); } -- 2.39.5