Skip to content

osd: Support for Synchronous Reads in EC - #67079

Merged
rzarzynski merged 2 commits into
ceph:mainfrom
MattyWilliams22:ec-sync-reads
May 26, 2026
Merged

rzarzynski merged 2 commits into
ceph:mainfrom
MattyWilliams22:ec-sync-reads

Conversation

@MattyWilliams22

Copy link
Copy Markdown
Contributor

Use boost pull-type coroutines to perform synchronous reads in EC without blocking any threads. This functionality enables the use of class (cls) methods in EC pools.

  • Coroutines.h file added containing type and struct definitions.
  • Coroutine spawned in PrimaryLogPG::do_op if the message contains a CEPH_OSD_OP_CALL op.
  • ECBackend::objects_read_sync yields while running ECBackend::objects_read_async. Coroutine is resumed once the read is complete.
  • When a coroutine op is being processed, all other ops to the same PG are blocked.

https://tracker.ceph.com/issues/74531

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 x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@aainscow aainscow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

I think the state_guard code is probably unnecessary. Have you found code paths which cause any of:

  • read_async to complete synchronously.
  • on_change calls the finisher callback.

?

The code looks like it has been written to cope with these scenarios, which suggests you hit them in testing?

Comment thread src/osd/ECBackend.cc Resolved
Comment thread src/osd/ECSwitch.h Resolved
Comment thread src/osd/ECSwitch.h Resolved
Comment thread src/osd/osd_types.h Resolved
Comment thread src/osd/PrimaryLogPG.cc Resolved
Comment thread src/osd/PrimaryLogPG.h Resolved
Comment thread src/osd/Coroutines.h Resolved
Comment thread src/osd/ECBackend.cc Resolved
Comment thread src/osd/PrimaryLogPG.cc Resolved
Comment thread src/osd/PrimaryLogPG.cc Resolved
Comment thread src/osd/PrimaryLogPG.h Resolved
Comment thread src/osd/PrimaryLogPG.cc Resolved
Comment thread src/osd/PrimaryLogPG.cc
if (active_coro_op) {
requeue_op(active_coro_op);
active_coro_op = nullptr;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering of the requeues looks a bit suspect, but I think its ok:

  1. Its only possible for there to be a ops on waiting_for_coro_op if there is an active_coro_op which is suspended (inside EC waiting for an async read to complete). In particular this means the op being processed by the coroutine has not managed to get added to waiting_for_readable, or any of the other lists considered by the code below. These ops need to be requeued before the active_coro_op so they are retried later.
  2. For the I/O to have got this far it means there can't be anything on the waiting_for_readable list, so ordering versus this list doesn't matter
  3. Waiting for peered, flush, active all happen before do_op so this ordering is correct.

@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test api

3 similar comments
@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test api

@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test api

@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test api

@MattyWilliams22
MattyWilliams22 marked this pull request as ready for review January 30, 2026 14:55
@MattyWilliams22
MattyWilliams22 requested a review from a team as a code owner January 30, 2026 14:55
@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test make check

4 similar comments
@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@CJamesIBM
CJamesIBM force-pushed the ec-sync-reads branch 2 times, most recently from e5b3e43 to d8230dd Compare April 22, 2026 15:11

@bill-scales bill-scales left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with the changes, but I think the change in PrimaryLogPG::get_rw_locks deserves its own commit with more explanation about the scenario it is fixing and justification as to why it will still be very unusual to take a RWEXCL lock.

Comment thread src/osd/ECBackend.cc
return result;
}

int ECBackend::objects_read_local(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK: You are introducing a new objects_read_sync method that can be used by a stackfull coroutine and will issue an async read and block until it completes.

The old objects_read_async method has been renamed to objects_read_local (it takes different arguments so you would get compile errors if you failed to update one of the references)

Comment thread src/osd/PrimaryLogPG.cc Resolved
Comment thread src/osd/PrimaryLogPG.cc
dout(20) << __func__ << ": op " << *m << dendl;
for (const auto& osd_op : m->ops) {
if (osd_op.op.op == CEPH_OSD_OP_CALL) {
return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK: Only FastEC pools that receive Ops with a OP_CALL Class call will use a coroutine

Comment thread src/osd/PrimaryLogPG.cc
if (coro_op_in_flight) {
dout(20) << __func__ << ": coroutine op in flight, queuing " << op << dendl;
waiting_for_coro_op.push_back(op);
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK - This only happens when an co-routine handling a CALL OP issues an asynchronous read and blocks waiting for the read to complete. The PG lock is released so it is possible for new Ops to be scheduled, these will get queued here. The SubOpReadReply/SubOpWriteReply messages are processed (these don't get as far as do_op so aren't blocked) which allows the async read to complete and the co-routine will be resumed. When the co-routine finishes this queue is kicked.

All writes in EC are asynchronous (even if they are only updating metadata), so Cls reads in EC must use the RWEXCL lock to eliminate the possibility of race conditions.
This resolves failures with Cls queue tests on EC pools where read operations were observed overtaking in-flight writes.

Fixes: https://tracker.ceph.com/issues/74531
Signed-off-by: Matty Williams <[email protected]>
…ng any threads

Coroutines.h file added containing type and struct definitions.
Coroutine spawned in PrimaryLogPG::do_op if the message contains a CEPH_OSD_OP_CALL op.
ECBackend::objects_read_sync yields while running ECBackend::objects_read_async. Coroutine is resumed once the read is complete.
When a coroutine op is being processed, all other ops to the same PG are blocked.

Fixes: https://tracker.ceph.com/issues/74531
Signed-off-by: Matty Williams <[email protected]>

@aainscow aainscow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any comments beyond those which Bill had.

@bill-scales bill-scales left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NitzanMordhai

Copy link
Copy Markdown
Contributor

Comment thread src/osd/PrimaryLogPG.cc
if (m->finish_decode()) {
op->reset_desc(); // for TrackedOp
m->clear_payload();
if (!pool.info.allows_ecoptimizations()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supported only for the new, FastEC code paths. OK!

Comment thread src/osd/PrimaryLogPG.cc
dout(20) << __func__ << ": op " << *m << dendl;
for (const auto& osd_op : m->ops) {
if (osd_op.op.op == CEPH_OSD_OP_CALL) {
return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and only executing for a ceph class' method – as it should. OK.

Comment thread src/osd/osd_types.h
@@ -376,6 +376,8 @@ enum {
CEPH_OSD_RMW_FLAG_RETURNVEC = (1 << 11),
CEPH_OSD_RMW_FLAG_READ_DATA = (1 << 12),
CEPH_OSD_RMW_FLAG_EC_DIRECT_READ = (1 << 13),
CEPH_OSD_RMW_FLAG_EC_SYNC_READ = (1 << 14),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: first use of this flag is in the next commit.

Comment thread src/osd/ECBackend.cc
Comment on lines +1017 to +1033
// Callback for the async read
Context *on_finish = new LambdaContext([&, coro](int r) {
result = r;
done = true;

if (waiting) {
coro.resume();
}
});

objects_read_async(hoid, object_size, to_read, on_finish, true);

// If the async read is not yet complete, yield and wait for it to complete
if (!done) {
waiting = true;
coro.yield();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually we're either executing a request immediately (if none is being executed at the time) or chaining.

Comment thread src/osd/PrimaryLogPG.cc
it != in_progress_async_reads.end(); ++it) {
if (it->second == active_coro_ctx) {
in_progress_async_reads.erase(it);
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This break means you we aren't referencing it (for it++) after it has been erase()d. OK.

@rzarzynski
rzarzynski merged commit 9034a59 into ceph:main May 26, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I have resolved the following tracker ticket due to the merge of this PR:

No backports are pending for the ticket. If this is incorrect, please update the tracker
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/26461360013

@MattyWilliams22
MattyWilliams22 deleted the ec-sync-reads branch June 2, 2026 15:05
@JonBailey1993 JonBailey1993 mentioned this pull request Jun 4, 2026
4 of 14 tasks
JonBailey1993 added a commit to JonBailey1993/ceph that referenced this pull request Jun 8, 2026
This test was talking about testing invalid ops, however with the inclusion of sync reads in EC (ceph#67079), it is valid to perform class reads in EC. In addition, work was done around illegal ops here: ceph#66258 and the existance of TEST(ClsHello, BadMethods) in test_cls_hello.cc covers illegal ops in that PR leading me to think this is unneccisairy. Because of these reasons, I think its better this test is removed as it is incorrect and also not working.

Signed-off-by: Jon Bailey <[email protected]>
@ljflores

Copy link
Copy Markdown
Member

@MattyWilliams22 FYI somehow the API check didn't catch this compile-time error: https://tracker.ceph.com/issues/77618

Can you see if it's related to this PR?

@MattyWilliams22
MattyWilliams22 restored the ec-sync-reads branch July 20, 2026 14:32
batrick pushed a commit that referenced this pull request Jul 29, 2026
This test was talking about testing invalid ops, however with the inclusion of sync reads in EC (#67079), it is valid to perform class reads in EC. In addition, work was done around illegal ops here: #66258 and the existance of TEST(ClsHello, BadMethods) in test_cls_hello.cc covers illegal ops in that PR leading me to think this is unneccisairy. Because of these reasons, I think its better this test is removed as it is incorrect and also not working.

Signed-off-by: Jon Bailey <[email protected]>
(cherry picked from commit b05cfd1)
AnuragRaut08 pushed a commit to AnuragRaut08/ceph that referenced this pull request Sep 30, 2026
This test was talking about testing invalid ops, however with the inclusion of sync reads in EC (ceph#67079), it is valid to perform class reads in EC. In addition, work was done around illegal ops here: ceph#66258 and the existance of TEST(ClsHello, BadMethods) in test_cls_hello.cc covers illegal ops in that PR leading me to think this is unneccisairy. Because of these reasons, I think its better this test is removed as it is incorrect and also not working.

Signed-off-by: Jon Bailey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants