Skip to content

Commit ce0b1ed

Browse files
committed
osd: Generalise can_serve_replica_read for consumption by EC.
The can_serve_replica_read() function is called by replica to determine whether there are any uncommitted writes. If such writes exist, then the system will reject the IO to avoid the risk of reading data from a write which may yet be rolled back. The same code is going to be useful for EC direct reads. The string_view code is not expensive. Signed-off-by: Alex Ainscow <[email protected]>
1 parent d9f4ee4 commit ce0b1ed

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

src/crimson/osd/osd_operations/client_request.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ ClientRequest::interruptible_future<> ClientRequest::with_pg_process_interruptib
209209
pg.get_perf_logger().inc(l_osd_replica_read_redirect_missing);
210210
co_await reply_op_error(pgref, -EAGAIN);
211211
co_return;
212-
} else if (!pg.get_peering_state().can_serve_replica_read(m->get_hobj())) {
213-
// Note: can_serve_replica_read checks for writes on the head object
212+
} else if (!pg.get_peering_state().can_serve_read(m->get_hobj())) {
213+
// Note: can_serve_read checks for writes on the head object
214214
// as writes can only occur to head.
215215
DEBUGDPP("{}.{}: unstable write on replica, bouncing to primary",
216216
pg, *this, this_instance_id);

src/messages/MOSDRepOp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class MOSDRepOp final : public MOSDFastDispatchOp {
6565
* Because updates <= pg_committed_to cannot become divergent, replicas
6666
* may safely serve reads on objects which do not have more recent updates.
6767
*
68-
* See PeeringState::pg_committed_to, PeeringState::can_serve_replica_read
68+
* See PeeringState::pg_committed_to, PeeringState::can_serve_read
6969
*
7070
* Historical note: Prior to early 2024, this field was named
7171
* min_last_complete_ondisk. The replica, however, only actually relied on

src/osd/PeeringState.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,17 +1546,21 @@ bool PeeringState::needs_backfill() const
15461546
}
15471547

15481548
/**
1549-
* Returns whether a particular object can be safely read on this replica
1549+
* Returns whether a particular object can be safely read
15501550
*/
1551-
bool PeeringState::can_serve_replica_read(const hobject_t &hoid)
1551+
bool PeeringState::can_serve_read(const hobject_t &hoid)
15521552
{
15531553
ceph_assert(!is_primary());
1554+
std::string_view storage_object = "replica";
1555+
if (pool.info.is_erasure()) {
1556+
storage_object = "shard";
1557+
}
15541558
if (!pg_log.get_log().has_write_since(
15551559
hoid, pg_committed_to)) {
1556-
psdout(20) << "can be safely read on this replica" << dendl;
1560+
psdout(20) << "can be safely read on this " << storage_object << dendl;
15571561
return true;
15581562
} else {
1559-
psdout(20) << "can't read object on this replica" << dendl;
1563+
psdout(20) << "can't read object on this " << storage_object << dendl;
15601564
return false;
15611565
}
15621566
}

src/osd/PeeringState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ class PeeringState : public MissingLoc::MappingInfo {
24392439
bool needs_recovery() const;
24402440
bool needs_backfill() const;
24412441

2442-
bool can_serve_replica_read(const hobject_t &hoid);
2442+
bool can_serve_read(const hobject_t &hoid);
24432443

24442444
/**
24452445
* Returns whether the current acting set is able to go active

src/osd/PrimaryLogPG.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,15 +2352,20 @@ void PrimaryLogPG::do_op(OpRequestRef& op)
23522352
}
23532353

23542354
if (!is_primary()) {
2355-
if (!recovery_state.can_serve_replica_read(oid)) {
2355+
if (!recovery_state.can_serve_read(oid)) {
2356+
std::string_view storage_object = "replica";
2357+
if (pool.info.is_erasure()) {
2358+
storage_object = "shard";
2359+
}
23562360
dout(20) << __func__
2357-
<< ": unstable write on replica, bouncing to primary "
2361+
<< ": unstable write on " << storage_object
2362+
<< ", bouncing to primary "
23582363
<< *m << dendl;
23592364
osd->logger->inc(l_osd_replica_read_redirect_conflict);
23602365
osd->reply_op_error(op, -EAGAIN);
23612366
return;
23622367
}
2363-
dout(20) << __func__ << ": serving replica read on oid " << oid
2368+
dout(20) << __func__ << ": serving read on oid " << oid
23642369
<< dendl;
23652370
osd->logger->inc(l_osd_replica_read_served);
23662371
}

0 commit comments

Comments
 (0)