Skip to content

Commit 6e9e203

Browse files
author
Laura Flores
committed
mon, osd: add command to remove invalid pg-upmap-primary entries
The current rm-pg-upmap-primary command checks that the pgid exists in the pgmap before continuing to remove it. Due to https://tracker.ceph.com/issues/66867, some invalid pg-upmap-primary entires may exist for pools that have been removed. Currently, these mappings are impossible to remove since the pgids no longer exist in the pgmap. This new command, rm-pg-upmap-primary-all, allows users the ability to remove any and all pg-upmap-primary mappings in the osdmap at once, which includes valid and invalid entries. This command may also be helpful when upgrading from versions where users are plagued by https://tracker.ceph.com/issues/61948. Users may use an upgraded mon to remove all pg-upmap-primray entries (valid and invalid) so they continue to upgrade to a safe version. See manual testing for this patch here: https://tracker.ceph.com/issues/67179#note-12 Fixes: https://tracker.ceph.com/issues/67179 Fixes: https://tracker.ceph.com/issues/69760 Signed-off-by: Laura Flores <[email protected]>
1 parent f5f9af4 commit 6e9e203

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

src/mon/MonCommands.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,9 @@ COMMAND("osd rm-pg-upmap-primary "
10351035
"name=pgid,type=CephPgid ",
10361036
"clear pg primary setting for <pgid>",
10371037
"osd", "rw")
1038+
COMMAND("osd rm-pg-upmap-primary-all ",
1039+
"clear all pg primary entries (developers only)",
1040+
"osd", "rw")
10381041
COMMAND("osd primary-temp "
10391042
"name=pgid,type=CephPgid "
10401043
"name=id,type=CephOsdName",

src/mon/OSDMonitor.cc

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12417,14 +12417,16 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
1241712417
prefix == "osd pg-upmap-items" ||
1241812418
prefix == "osd rm-pg-upmap-items" ||
1241912419
prefix == "osd pg-upmap-primary" ||
12420-
prefix == "osd rm-pg-upmap-primary") {
12420+
prefix == "osd rm-pg-upmap-primary" ||
12421+
prefix == "osd rm-pg-upmap-primary-all") {
1242112422
enum {
1242212423
OP_PG_UPMAP,
1242312424
OP_RM_PG_UPMAP,
1242412425
OP_PG_UPMAP_ITEMS,
1242512426
OP_RM_PG_UPMAP_ITEMS,
1242612427
OP_PG_UPMAP_PRIMARY,
1242712428
OP_RM_PG_UPMAP_PRIMARY,
12429+
OP_RM_PG_UPMAP_PRIMARY_ALL,
1242812430
} upmap_option;
1242912431

1243012432
if (prefix == "osd pg-upmap") {
@@ -12439,6 +12441,8 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
1243912441
upmap_option = OP_PG_UPMAP_PRIMARY;
1244012442
} else if (prefix == "osd rm-pg-upmap-primary") {
1244112443
upmap_option = OP_RM_PG_UPMAP_PRIMARY;
12444+
} else if (prefix == "osd rm-pg-upmap-primary-all") {
12445+
upmap_option = OP_RM_PG_UPMAP_PRIMARY_ALL;
1244212446
} else {
1244312447
ceph_abort_msg("invalid upmap option");
1244412448
}
@@ -12458,6 +12462,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
1245812462

1245912463
case OP_PG_UPMAP_PRIMARY: // fall through
1246012464
case OP_RM_PG_UPMAP_PRIMARY:
12465+
case OP_RM_PG_UPMAP_PRIMARY_ALL:
1246112466
min_release = ceph_release_t::reef;
1246212467
min_feature = CEPH_FEATUREMASK_SERVER_REEF;
1246312468
feature_name = "pg-upmap-primary";
@@ -12483,17 +12488,33 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
1248312488
goto wait;
1248412489
if (err < 0)
1248512490
goto reply_no_propose;
12491+
1248612492
pg_t pgid;
12487-
err = parse_pgid(cmdmap, ss, pgid);
12488-
if (err < 0)
12489-
goto reply_no_propose;
12490-
if (pending_inc.old_pools.count(pgid.pool())) {
12491-
ss << "pool of " << pgid << " is pending removal";
12492-
err = -ENOENT;
12493-
getline(ss, rs);
12494-
wait_for_commit(op,
12495-
new Monitor::C_Command(mon, op, err, rs, get_last_committed() + 1));
12496-
return true;
12493+
switch (upmap_option) {
12494+
case OP_RM_PG_UPMAP_PRIMARY_ALL: // no pgid to check
12495+
break;
12496+
12497+
case OP_PG_UPMAP:
12498+
case OP_RM_PG_UPMAP:
12499+
case OP_PG_UPMAP_ITEMS:
12500+
case OP_RM_PG_UPMAP_ITEMS:
12501+
case OP_PG_UPMAP_PRIMARY:
12502+
case OP_RM_PG_UPMAP_PRIMARY:
12503+
err = parse_pgid(cmdmap, ss, pgid);
12504+
if (err < 0)
12505+
goto reply_no_propose;
12506+
if (pending_inc.old_pools.count(pgid.pool())) {
12507+
ss << "pool of " << pgid << " is pending removal";
12508+
err = -ENOENT;
12509+
getline(ss, rs);
12510+
wait_for_commit(op,
12511+
new Monitor::C_Command(mon, op, err, rs, get_last_committed() + 1));
12512+
return true;
12513+
}
12514+
break;
12515+
12516+
default:
12517+
ceph_abort_msg("invalid upmap option");
1249712518
}
1249812519

1249912520
// check pending upmap changes
@@ -12528,6 +12549,8 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
1252812549
goto wait;
1252912550
}
1253012551
break;
12552+
case OP_RM_PG_UPMAP_PRIMARY_ALL: // nothing to check
12553+
break;
1253112554

1253212555
default:
1253312556
ceph_abort_msg("invalid upmap option");
@@ -12733,6 +12756,13 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
1273312756
}
1273412757
break;
1273512758

12759+
case OP_RM_PG_UPMAP_PRIMARY_ALL:
12760+
{
12761+
osdmap.rm_all_upmap_prims(cct, &pending_inc);
12762+
ss << "cleared all pg_upmap_primary mappings";
12763+
}
12764+
break;
12765+
1273612766
default:
1273712767
ceph_abort_msg("invalid upmap option");
1273812768
}

src/osd/OSDMap.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5216,6 +5216,20 @@ void OSDMap::rm_all_upmap_prims(CephContext *cct, OSDMap::Incremental *pending_i
52165216
}
52175217
}
52185218

5219+
void OSDMap::rm_all_upmap_prims(
5220+
CephContext *cct,
5221+
OSDMap::Incremental *pending_inc)
5222+
{
5223+
for (const auto& [pg, _] : pg_upmap_primaries) {
5224+
if (pending_inc->new_pg_upmap_primary.contains(pg)) {
5225+
ldout(cct, 30) << __func__ << "Removing pending pg_upmap_prim for pg " << pg << dendl;
5226+
pending_inc->new_pg_upmap_primary.erase(pg);
5227+
}
5228+
ldout(cct, 30) << __func__ << "Removing pg_upmap_prim for pg " << pg << dendl;
5229+
pending_inc->old_pg_upmap_primary.insert(pg);
5230+
}
5231+
}
5232+
52195233
int OSDMap::calc_desired_primary_distribution(
52205234
CephContext *cct,
52215235
int64_t pid,

src/osd/OSDMap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,10 @@ class OSDMap {
14921492
OSDMap& tmp_osd_map,
14931493
const std::optional<rb_policy>& rbp = std::nullopt) const;
14941494

1495-
void rm_all_upmap_prims(CephContext *cct, Incremental *pending_inc, uint64_t pid);
1495+
void rm_all_upmap_prims(CephContext *cct, Incremental *pending_inc, uint64_t pid); // per pool
1496+
void rm_all_upmap_prims(
1497+
CephContext *cct,
1498+
OSDMap::Incremental *pending_inc); // total
14961499

14971500
int calc_desired_primary_distribution(
14981501
CephContext *cct,

0 commit comments

Comments
 (0)