From e98ddbc32714e51e97a824fbe9dd5d52381356e6 Mon Sep 17 00:00:00 2001 From: Xuehan Xu Date: Thu, 9 May 2024 10:24:26 +0800 Subject: [PATCH] crimson/osd/osd_operations/client_request: check "can_serve_replica_reads" before getting obc Fixes: https://tracker.ceph.com/issues/65872 Signed-off-by: Xuehan Xu (cherry picked from commit 5d5ce176b3853284802e81e5743b55919c4c808d) --- .../osd/osd_operations/client_request.cc | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/crimson/osd/osd_operations/client_request.cc b/src/crimson/osd/osd_operations/client_request.cc index d78d05cf7087d..4a721d1277fb6 100644 --- a/src/crimson/osd/osd_operations/client_request.cc +++ b/src/crimson/osd/osd_operations/client_request.cc @@ -170,6 +170,30 @@ ClientRequest::interruptible_future<> ClientRequest::with_pg_process_interruptib pg.wait_for_active_blocker, &decltype(pg.wait_for_active_blocker)::wait)); + if (int res = op_info.set_from_op(&*m, *pg.get_osdmap()); + res != 0) { + co_await reply_op_error(pgref, res); + co_return; + } + + if (!pg.is_primary()) { + // primary can handle both normal ops and balanced reads + if (is_misdirected(pg)) { + DEBUGDPP("{}.{}: dropping misdirected op", + pg, *this, this_instance_id); + co_return; + } else if (const hobject_t& hoid = m->get_hobj(); + !pg.get_peering_state().can_serve_replica_read(hoid)) { + DEBUGDPP("{}.{}: unstable write on replica, bouncing to primary", + pg, *this, this_instance_id); + co_await reply_op_error(pgref, -EAGAIN); + co_return; + } else { + DEBUGDPP("{}.{}: serving replica read on oid {}", + pg, *this, this_instance_id, m->get_hobj()); + } + } + DEBUGDPP("{}.{}: pg active, entering process[_pg]_op", *pgref, *this, this_instance_id); @@ -335,11 +359,6 @@ ClientRequest::process_op( DEBUGDPP("{}.{}: entered get_obc stage, about to wait_scrub", *pg, *this, this_instance_id); - if (int res = op_info.set_from_op(&*m, *pg->get_osdmap()); - res != 0) { - co_await reply_op_error(pg, res); - co_return; - } co_await ihref.enter_blocker( *this, pg->scrubber, &decltype(pg->scrubber)::wait_scrub, m->get_hobj()); @@ -468,24 +487,6 @@ ClientRequest::do_process( co_return; } - if (!pg->is_primary()) { - // primary can handle both normal ops and balanced reads - if (is_misdirected(*pg)) { - DEBUGDPP("{}.{}: dropping misdirected op", - *pg, *this, this_instance_id); - co_return; - } else if (const hobject_t& hoid = m->get_hobj(); - !pg->get_peering_state().can_serve_replica_read(hoid)) { - DEBUGDPP("{}.{}: unstable write on replica, bouncing to primary", - *pg, *this, this_instance_id); - co_await reply_op_error(pg, -EAGAIN); - co_return; - } else { - DEBUGDPP("{}.{}: serving replica read on oid {}", - *pg, *this, this_instance_id, m->get_hobj()); - } - } - auto [submitted, all_completed] = co_await pg->do_osd_ops( m, r_conn, obc, op_info, snapc ); -- 2.39.5