From f35ca81c8964899012526e00b04ffc4948d758d1 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Tue, 20 Sep 2022 07:02:51 +0000 Subject: [PATCH] osd/scrub: make on_replica_init() idempotent again on_replica_init() might be called twice during replica scrub initiation. Thus, it was designed to cause no issue if called an extra time. That was broken when the scrubber-backend code was introduced. Fixes: https://tracker.ceph.com/issues/57616 Signed-off-by: Ronen Friedman --- src/osd/scrubber/pg_scrubber.cc | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/osd/scrubber/pg_scrubber.cc b/src/osd/scrubber/pg_scrubber.cc index 2a610b30a07..7597f4a7d27 100644 --- a/src/osd/scrubber/pg_scrubber.cc +++ b/src/osd/scrubber/pg_scrubber.cc @@ -1022,19 +1022,26 @@ void PgScrubber::on_init() m_pg->publish_stats_to_osd(); } +/* + * Note: as on_replica_init() is likely to be called twice (entering + * both ReplicaWaitUpdates & ActiveReplica), its operations should be + * idempotent. + * Now that it includes some state-changing operations, we need to check + * m_active against double-activation. + */ void PgScrubber::on_replica_init() { - m_be = std::make_unique( - *this, - *m_pg, - m_pg_whoami, - m_is_repair, - m_is_deep ? scrub_level_t::deep : scrub_level_t::shallow); - m_active = true; - ++m_sessions_counter; + dout(10) << __func__ << " called with 'active' " + << (m_active ? "set" : "cleared") << dendl; + if (!m_active) { + m_be = std::make_unique( + *this, *m_pg, m_pg_whoami, m_is_repair, + m_is_deep ? scrub_level_t::deep : scrub_level_t::shallow); + m_active = true; + ++m_sessions_counter; + } } - int PgScrubber::build_primary_map_chunk() { epoch_t map_building_since = m_pg->get_osdmap_epoch(); -- 2.39.5