Repository navigation
mon: Roll back pending_inc on prepare_new_pool failure - #71130
Conversation
|
jenkins test make check arm64 |
gregsfortytwo
left a comment
There was a problem hiding this comment.
This is pretty spread out and may get missed if future failure cases arise.
Could we reformat it as an RAII object and then mark it clean when the pool create is actually done, similar to how we use Plugger in MonmapMonitor?
|
This PR has been added to wip-bharath7-testing-20260824.015917-main. |
I think this would be a better solution. Will update. |
828639c to
802bd4b
Compare
|
jenkins test api |
gregsfortytwo
left a comment
There was a problem hiding this comment.
Reviewed-by: Greg Farnum [email protected]
|
This PR has been added to wip-bharath10-testing-20260903.050751-main. |
| OSDMap::Incremental &inc; | ||
| int64_t pool_id; | ||
| bool committed = false; | ||
| } abort_guard(pending_inc, pool); |
There was a problem hiding this comment.
Rather than re-inventing this all the time, let's create a src/common/ScopeGuard.h with:
#include <concepts>
#include <utility>
template<std::invocable Fn>
class ScopeGuard {
Fn rollback_fn;
bool active{true};
public:
constexpr explicit ScopeGuard(Fn&& fn)
: rollback_fn(std::forward<Fn>(fn)) {}
// Prevent copying
ScopeGuard(const ScopeGuard&) = delete;
ScopeGuard& operator=(const ScopeGuard&) = delete;
// Allow moving
constexpr ScopeGuard(ScopeGuard&& other) noexcept
: rollback_fn(std::move(other.rollback_fn)),
active(std::exchange(other.active, false)) {}
constexpr void commit() noexcept { active = false; }
constexpr ~ScopeGuard() {
if (active) {
rollback_fn();
}
}
};
and then use here:
auto abort_guard = ScopeGuard([&pending_inc, pool] {
pending_inc.new_pools.erase(pool);
--pending_inc.new_pool_max;
});
There was a problem hiding this comment.
after reading this implementation, i realized that our scope_guard is buggy. hence created #73241
|
@jamiepryde Once the reviewers have approved the PR, please feel free to merge it. If a rerun is required, please add the needs-qa label and remove the TESTED label. |
batrick
left a comment
There was a problem hiding this comment.
@batrick What about this updated commit? I noticed we also have include/scope_guard.h, and it's already used in OSDMonitor elsewhere. It doesn't have a commit function, so I need to use a bool to skip the rollback on success. We could add a commit() to scope_guard.h if you think we need it.
Please add a commit and cleanup the existing code after this merges.
|
Also, scope_guard.h probably belongs in src/common. |
|
New round of QA needed. |
|
This PR has been added to wip-bharath5-testing-20261012.095720-main. |
|
@jamiepryde, here is a standalone test for this fix, in case you would like to add it to this PR: aainscow@20c9acd (branch
|
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
A guard is often used for rollback: it should undo a change if the function bails out early, and do nothing once the function gets to the end. Without a way to turn the guard off, the caller has to keep a bool next to the guard and test it in the lambda. ceph#71130 does exactly that to roll back a half-created pool in OSDMonitor::prepare_new_pool(). Add an "active" flag, and dismiss() to clear it. Put the callable under [[no_unique_address]], so a guard holding a captureless lambda is no bigger than the flag. Signed-off-by: Kefu Chai <[email protected]>
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Carried from ceph#71130; drop when this is rebased onto a main that has it. Any error return in prepare_new_pool() after the new pool has been inserted into pending_inc.new_pools and pending_inc.new_pool_max has been incremented, but before pending_inc.new_pool_names is set, leaves pending_inc in an inconsistent state: the pool ID is present in new_pools but absent from new_pool_names. On the next encode_pending() call, apply_incremental() adds the unnamed pool to tmp.pools but not to tmp.pool_name. check_health() then iterates pools and calls get_pool_name() on the unnamed ID, hitting ceph_assert(i != pool_name.end()) and crashing the monitor. Fix with a make_scope_guard() that erases the pool from pending_inc.new_pools and decrements pending_inc.new_pool_max on scope exit. The guard is dismissed once new_pool_names is set, so any error return between pool allocation and name assignment automatically triggers rollback without requiring explicit cleanup at each site. Fixes: https://tracker.ceph.com/issues/79574 Signed-off-by: Jamie Pryde <[email protected]> Assisted-by: IBM Bob 2.0.2
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.