From c143b9a3db4492e5a2ee7919b22581955fc2a119 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 1 Apr 2019 10:20:46 -0500 Subject: [PATCH] mon/MonMap: add min_quorum_size() helper Signed-off-by: Sage Weil --- src/mon/MonMap.h | 7 +++++++ src/mon/Monitor.cc | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index 97db1e64c1c..e35a218cae0 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -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; } diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index a670af6e456..328b42583ce 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -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; -- 2.39.5