]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon/MonMap: add min_quorum_size() helper
authorSage Weil <sage@redhat.com>
Mon, 1 Apr 2019 15:20:46 +0000 (10:20 -0500)
committerSage Weil <sage@redhat.com>
Mon, 1 Apr 2019 19:58:50 +0000 (14:58 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/MonMap.h
src/mon/Monitor.cc

index 97db1e64c1cc592c84b6a83e2cfbda817eff4be7..e35a218cae0d2a0f11ec2b2d924b68437c449b90 100644 (file)
@@ -166,6 +166,13 @@ public:
     return mon_info.size();
   }
 
+  unsigned min_quorum_size(unsigned total_mons=0) const {
+    if (total_mons == 0) {
+      total_mons = size();
+    }
+    return total_mons / 2 + 1;
+  }
+
   epoch_t get_epoch() const { return epoch; }
   void set_epoch(epoch_t e) { epoch = e; }
 
index a670af6e456bf63b9fbd399a35f18dde30b811c7..328b42583ce0ec6f0ed025ddad16a897b4aa44fd 100644 (file)
@@ -2046,7 +2046,7 @@ void Monitor::handle_probe_reply(MonOpRequestRef op)
       return;
     }
 
-    unsigned need = monmap->size() / 2 + 1;
+    unsigned need = monmap->min_quorum_size();
     dout(10) << " outside_quorum now " << outside_quorum << ", need " << need << dendl;
     if (outside_quorum.size() >= need) {
       if (outside_quorum.count(name)) {
@@ -3715,7 +3715,7 @@ void Monitor::handle_command(MonOpRequestRef op)
        wouldbe.erase(n);
       }
     }
-    if (wouldbe.size() < monmap->size() / 2 + 1) {
+    if (wouldbe.size() < monmap->min_quorum_size()) {
       r = -EBUSY;
       rs = "not enough monitors would be available (" + stringify(wouldbe) +
        ") after stopping mons " + stringify(ids);
@@ -3725,7 +3725,7 @@ void Monitor::handle_command(MonOpRequestRef op)
     rs = "quorum should be preserved (" + stringify(wouldbe) +
       ") after stopping " + stringify(ids);
   } else if (prefix == "mon ok-to-add-offline") {
-    if (quorum.size() < (monmap->size() + 1) / 2 + 1) {
+    if (quorum.size() < monmap->min_quorum_size(monmap->size() + 1)) {
       rs = "adding a monitor may break quorum (until that monitor starts)";
       r = -EBUSY;
       goto out;
@@ -3746,7 +3746,7 @@ void Monitor::handle_command(MonOpRequestRef op)
     }
     int rank = monmap->get_rank(id);
     if (quorum.count(rank) &&
-       quorum.size() - 1 < (monmap->size() - 1) / 2 + 1) {
+       quorum.size() - 1 < monmap->min_quorum_size(monmap->size() - 1)) {
       r = -EBUSY;
       rs = "removing mon." + id + " would break quorum";
       goto out;