]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: move initial_members filtering into MonMap method
authorSage Weil <sage@inktank.com>
Fri, 18 May 2012 16:52:09 +0000 (09:52 -0700)
committerSage Weil <sage@inktank.com>
Fri, 18 May 2012 23:23:58 +0000 (16:23 -0700)
This is cleaner.  Also, we can perform/test this functionality from the
monmaptool.

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/MonMap.cc
src/mon/MonMap.h
src/mon/Monitor.cc

index a1f6a0bf1bc0da4aa9639dbea14b0197601b3ac2..47a04720626c42ee60eda3391d9a85e4448c2d19 100644 (file)
@@ -11,6 +11,8 @@
 #include "include/addr_parsing.h"
 #include "common/ceph_argparse.h"
 
+#include "common/dout.h"
+
 using ceph::Formatter;
 
 void MonMap::encode(bufferlist& blist, uint64_t features) const
@@ -184,3 +186,47 @@ int MonMap::build_from_host_list(std::string hostlist, std::string prefix)
   }
   return 0;
 }
+
+void MonMap::filter_initial_members(CephContext *cct,
+                                   list<std::string>& initial_members,
+                                   string my_name, entity_addr_t my_addr,
+                                   set<entity_addr_t> *removed)
+{
+  // remove non-initial members
+  unsigned i = 0;
+  while (i < size()) {
+    string n = get_name(i);
+    if (std::find(initial_members.begin(), initial_members.end(), n) != initial_members.end()) {
+      lgeneric_dout(cct, 1) << " keeping " << n << " " << get_addr(i) << dendl;
+      i++;
+      continue;
+    }
+
+    lgeneric_dout(cct, 1) << " removing " << get_name(i) << " " << get_addr(i) << dendl;
+    if (removed)
+      removed->insert(get_addr(i));
+    remove(n);
+    assert(!contains(n));
+  }
+
+  // add missing initial members
+  for (list<string>::iterator p = initial_members.begin(); p != initial_members.end(); ++p) {
+    if (!contains(*p)) {
+      if (*p == my_name) {
+       lgeneric_dout(cct, 1) << " adding self " << *p << " " << my_addr << dendl;
+       add(*p, my_addr);
+      } else {
+       entity_addr_t a;
+       a.set_family(AF_INET);
+       for (int n=1; ; n++) {
+         a.set_nonce(n);
+         if (!contains(a))
+           break;
+       }
+       lgeneric_dout(cct, 1) << " adding " << *p << " " << a << dendl;
+       add(*p, a);
+      }
+      assert(contains(*p));
+    }
+  }
+}
index e7982f137651bdcbbf333fc1eee5520bdc9e4acc..ea7a257abdb4b812d14aea4cb63d9864987adb55 100644 (file)
@@ -198,8 +198,35 @@ class MonMap {
   int write(const char *fn);
   int read(const char *fn);
 
+  /**
+   * build a monmap from a list of hosts or ips
+   *
+   * Resolve dns as needed.  Give mons dummy names.
+   *
+   * @param hosts  list of hosts, space or comma separated
+   * @param prefix prefix to prepend to generated mon names
+   * @return 0 for success, -errno on error
+   */
   int build_from_host_list(std::string hosts, std::string prefix);
 
+  /**
+   * filter monmap given a set of initial members.
+   *
+   * Remove mons that aren't in the initial_members list.  Add missing
+   * mons and give them dummy IPs (blank IPv4, with a non-zero
+   * nonce). If the name matches my_name, then my_addr will be used in
+   * place of a dummy addr.
+   *
+   * @param initial_members list of initial member names
+   * @param my_name name of self, can be blank
+   * @param my_addr my addr
+   * @param removed optional pointer to set to insert removed mon addrs to
+   */
+  void filter_initial_members(CephContext *cct,
+                             list<std::string>& initial_members,
+                             string my_name, entity_addr_t my_addr,
+                             set<entity_addr_t> *removed);
+
   void print(ostream& out) const;
   void print_summary(ostream& out) const;
   void dump(ceph::Formatter *f) const;
index 81f43ce888df610071ae6ce0e7a48e4fae748bb2..3b1bc4fa07915ff750cc6df3ba93cc369402c1bc 100644 (file)
@@ -292,42 +292,8 @@ int Monitor::init()
     if (initial_members.size()) {
       dout(1) << " initial_members " << initial_members << ", filtering seed monmap" << dendl;
 
-      // remove non-initial members
-      unsigned i = 0;
-      while (i < monmap->size()) {
-       string n = monmap->get_name(i);
-       if (std::find(initial_members.begin(), initial_members.end(), n) != initial_members.end()) {
-         dout(1) << " keeping " << n << " " << monmap->get_addr(i) << dendl;
-         i++;
-         continue;
-       }
-
-       dout(1) << " removing " << monmap->get_name(i) << " " << monmap->get_addr(i) << dendl;
-       extra_probe_peers.insert(monmap->get_addr(i));
-       monmap->remove(n);
-       assert(!monmap->contains(n));
-      }
-
-      // add missing initial members
-      for (list<string>::iterator p = initial_members.begin(); p != initial_members.end(); ++p) {
-       if (!monmap->contains(*p)) {
-         if (*p == name) {
-           dout(1) << " adding self " << *p << " " << messenger->get_myaddr() << dendl;
-           monmap->add(*p, messenger->get_myaddr());
-         } else {
-           entity_addr_t a;
-           a.set_family(AF_INET);
-           for (int n=1; ; n++) {
-             a.set_nonce(n);
-             if (!monmap->contains(a))
-               break;
-           }
-           dout(1) << " adding " << *p << " " << a << dendl;
-           monmap->add(*p, a);
-         }
-         assert(monmap->contains(*p));
-       }
-      }
+      monmap->filter_initial_members(g_ceph_context, initial_members, name, messenger->get_myaddr(),
+                                    &extra_probe_peers);
 
       // (re)calc my rank, in case it changed
       rank = monmap->get_rank(name);