Skip to content

Commit f6aed0b

Browse files
committed
mon: add command osd pool clear-availability-status
This commit adds a new command to allow users to clear the calculated availability score for a specified pool. This can be done by issuing the command: ceph osd pool clear-availability-status <pool_name> Fixes: https://tracker.ceph.com/issues/71495 Signed-off-by: Shraddha Agrawal <[email protected]>
1 parent 3b1647d commit f6aed0b

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

src/mon/MgrStatMonitor.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ void MgrStatMonitor::create_initial()
101101
encode(service_map, pending_service_map_bl, CEPH_FEATURES_ALL);
102102
}
103103

104+
void MgrStatMonitor::clear_pool_availability(int64_t poolid)
105+
{
106+
dout(20) << __func__ << dendl;
107+
std::scoped_lock l(lock);
108+
auto pool_itr = pending_pool_availability.find(poolid);
109+
if (pool_itr != pending_pool_availability.end()) {
110+
pool_itr->second = PoolAvailability();
111+
} else {
112+
dout(1) << "failed to clear a non-existing pool: " << poolid << dendl;
113+
return;
114+
};
115+
dout(20) << __func__ << " cleared availability score for pool: " << poolid << dendl;
116+
}
117+
104118
void MgrStatMonitor::calc_pool_availability()
105119
{
106120
dout(20) << __func__ << dendl;
@@ -400,6 +414,7 @@ bool MgrStatMonitor::prepare_report(MonOpRequestRef op)
400414
dout(20) << "pool_availability:\n";
401415
JSONFormatter jf(true);
402416
jf.open_object_section("pool_availability");
417+
std::scoped_lock l(lock);
403418
for (auto& i : pending_pool_availability) {
404419
jf.dump_object(std::to_string(i.first), i.second);
405420
}

src/mon/MgrStatMonitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
bool enable_availability_tracking = g_conf().get_val<bool>("enable_availability_tracking"); ///< tracking availability score feature
5959
std::optional<utime_t> reset_availability_last_uptime_downtime_val;
6060

61+
void clear_pool_availability(int64_t poolid);
62+
6163
void check_sub(Subscription *sub);
6264
void check_subs();
6365
void send_digests();

src/mon/MonCommands.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,10 @@ COMMAND("osd pool stretch unset "
12461246
COMMAND("osd pool availability-status", \
12471247
"obtain availability stats from all pools", \
12481248
"osd", "r")
1249+
COMMAND("osd pool clear-availability-status "
1250+
"name=pool,type=CephPoolname ",
1251+
"clear a pool's existing availability stats",
1252+
"osd", "r")
12491253
COMMAND("osd utilization",
12501254
"get basic pg distribution stats",
12511255
"osd", "r")

src/mon/OSDMonitor.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14406,6 +14406,33 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
1440614406
wait_for_commit(op, new Monitor::C_Command(mon, op, 0, rs,
1440714407
get_last_committed() + 1));
1440814408
return true;
14409+
} else if (prefix == "osd pool clear-availability-status") {
14410+
if (!g_conf().get_val<bool>("enable_availability_tracking")) {
14411+
ss << "Availability tracking is disabled. Availability status can not be cleared "
14412+
<< "while the feature is disabled. Enable it by setting the config "
14413+
<< "option enable_availability_tracking to ``true`` then try again.";
14414+
err = -EOPNOTSUPP;
14415+
goto reply_no_propose;
14416+
}
14417+
14418+
string pool_name;
14419+
cmd_getval(cmdmap, "pool", pool_name);
14420+
int64_t pool_id = osdmap.lookup_pg_pool_name(pool_name);
14421+
// check if pool exists
14422+
if (pool_id < 0) {
14423+
ss << "unrecognized pool '" << pool_name << "'";
14424+
err = -ENOENT;
14425+
goto reply_no_propose;
14426+
}
14427+
std::map<uint64_t, PoolAvailability> pool_availability = mon.mgrstatmon()->get_pool_availability();
14428+
// check if pool exists in pool_availability
14429+
if (pool_availability.find(pool_id) == pool_availability.end()){
14430+
ss << "unrecognized pool '" << pool_name << "'";
14431+
err = -ENOENT;
14432+
goto reply_no_propose;
14433+
}
14434+
// clear existing calculations
14435+
mon.mgrstatmon()->clear_pool_availability(pool_id);
1440914436
} else if (prefix == "osd pool availability-status") {
1441014437
if (!g_conf().get_val<bool>("enable_availability_tracking")) {
1441114438
ss << "availability tracking is disabled; you can enable it by setting the config option enable_availability_tracking";

0 commit comments

Comments
 (0)