From 7378581fd56b59d4864ef2844faabd5a32b656db Mon Sep 17 00:00:00 2001 From: Kamoltat Sirivadhna Date: Thu, 29 Aug 2024 18:23:43 +0000 Subject: [PATCH] [Stretch Mode] mon: restrict changing mon election strategy post stretch mode Problem: It is possible to modify the monitor election strategy once stretch mode is enabled. Solution: Restrict the ability for Ceph to change election strategy while using stretch mode. Also, notify the user if they attempt to change to the current election strategy. This change prevents unnecessary resource usage by informing the user when they try to switch to an election strategy that is already in use. This avoids redundant updates to the monmap. Fixes: https://tracker.ceph.com/issues/67801 Signed-off-by: Kamoltat Sirivadhna --- src/mon/MonmapMonitor.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc index 61942da6d8e4d..b608a802b5271 100644 --- a/src/mon/MonmapMonitor.cc +++ b/src/mon/MonmapMonitor.cc @@ -920,11 +920,32 @@ bool MonmapMonitor::prepare_command(MonOpRequestRef op) err = -EINVAL; goto reply_no_propose; } + if (pending_map.stretch_mode_enabled) { + err = -EINVAL; + ss << "Stretch mode is enabled, so you cannot change the election strategy; please disable stretch mode first!"; + ceph_assert(pending_map.strategy == MonMap::CONNECTIVITY); + goto reply_no_propose; + } if (strat == "classic") { + if (pending_map.strategy == MonMap::CLASSIC) { + err = 0; + ss << "You are already in classic election strategy"; + goto reply_no_propose; + } strategy = MonMap::CLASSIC; } else if (strat == "disallow") { + if (pending_map.strategy == MonMap::DISALLOW) { + err = 0; + ss << "You are already in disallow election strategy"; + goto reply_no_propose; + } strategy = MonMap::DISALLOW; } else if (strat == "connectivity") { + if (pending_map.strategy == MonMap::CONNECTIVITY) { + err = 0; + ss << "You are already in connectivity election strategy"; + goto reply_no_propose; + } strategy = MonMap::CONNECTIVITY; } else { err = -EINVAL; -- 2.39.5