]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
OSDMonitor: when adding bucket, delay response if pending map has name
authorSamuel Just <sam.just@inktank.com>
Sat, 27 Apr 2013 00:16:53 +0000 (17:16 -0700)
committerSamuel Just <sam.just@inktank.com>
Sat, 27 Apr 2013 00:19:59 +0000 (17:19 -0700)
Fixes: #4836
Signed-off-by: Samuel Just <sam.just@inktank.com>
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h

index e8a277a7b01dba338c97eb8b5ed5b0d5ac324759..d46c28f6ff277b9b2625d50b2f415c578fcf3815 100644 (file)
@@ -58,6 +58,15 @@ static ostream& _prefix(std::ostream *_dout, Monitor *mon, OSDMap& osdmap) {
                << ").osd e" << osdmap.get_epoch() << " ";
 }
 
+bool OSDMonitor::_have_pending_crush()
+{
+  return pending_inc.crush.length();
+}
+
+CrushWrapper &OSDMonitor::_get_stable_crush()
+{
+  return *osdmap.crush;
+}
 
 void OSDMonitor::_get_pending_crush(CrushWrapper& newcrush)
 {
@@ -2534,27 +2543,33 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
     else if (m->cmd.size() == 5 && m->cmd[1] == "crush" && (m->cmd[2] == "add-bucket")) {
       do {
        // osd crush add-bucket <name> <type>
+       if (!_have_pending_crush() &&
+           _get_stable_crush().name_exists(m->cmd[3])) {
+         ss << "bucket '" << m->cmd[3] << "' already exists";
+         err = 0;
+         break;
+       }
+
        CrushWrapper newcrush;
        _get_pending_crush(newcrush);
-
        if (newcrush.name_exists(m->cmd[3])) {
          ss << "bucket '" << m->cmd[3] << "' already exists";
          err = 0;
-         break;
-       }
-       int type = newcrush.get_type_id(m->cmd[4]);
-       if (type <= 0) {
-         ss << "type '" << m->cmd[4] << "' does not exist";
-         err = -EINVAL;
-         break;
-       }
-       int bucketno = newcrush.add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT,
-                                          type, 0, NULL, NULL);
-       newcrush.set_item_name(bucketno, m->cmd[3]);
+       } else {
+         int type = newcrush.get_type_id(m->cmd[4]);
+         if (type <= 0) {
+           ss << "type '" << m->cmd[4] << "' does not exist";
+           err = -EINVAL;
+           break;
+         }
+         int bucketno = newcrush.add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT,
+                                            type, 0, NULL, NULL);
+         newcrush.set_item_name(bucketno, m->cmd[3]);
 
-       pending_inc.crush.clear();
-       newcrush.encode(pending_inc.crush);
-       ss << "added bucket " << m->cmd[3] << " type " << m->cmd[4] << " to crush map";
+         pending_inc.crush.clear();
+         newcrush.encode(pending_inc.crush);
+         ss << "added bucket " << m->cmd[3] << " type " << m->cmd[4] << " to crush map";
+       }
        getline(ss, rs);
        wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, get_version()));
        return true;
index 0034bb0baca4bbb4ea8e5585f7e54d7b8b4a1501..30fd09fa499973ea396d14633a13bfe262e7b4bd 100644 (file)
@@ -137,6 +137,8 @@ private:
   int thrash_last_up_osd;
   bool thrash();
 
+  bool _have_pending_crush();
+  CrushWrapper &_get_stable_crush();
   void _get_pending_crush(CrushWrapper& newcrush);
 
   // svc