Skip to content

rados: Add API to disable version querying with reads in librados - #66162

Merged
aainscow merged 1 commit into
ceph:mainfrom
aainscow:no_obj_ver
Feb 4, 2026
Merged

aainscow merged 1 commit into
ceph:mainfrom
aainscow:no_obj_ver

Conversation

@aainscow

@aainscow aainscow commented Nov 7, 2025 •

Copy link
Copy Markdown
Contributor

librados will always request a "user version". Until EC direct reads are implemented this is a cheap operation and so librados always requests the user version, even if the client does not need it.

With EC direct reads, requesting the user version requires an extra op to the primary in some scenarios. The non-primary OSDs do not contain an up to date user version.

NEORADOS already allows for such optimisations, due to a how the API is organised.

librados is not heavily used by ceph-maintained clients, but this API will still be useful for testing of EC direct reads, since the test clients will use librados, due to it simpler nature and performance not being critical in the tests.

I am making this change in its own PR as it changes the externally visible API. Please review carefully!

I have only added to the _cxx API so far, as the _c API is not needed for direct reads testing. I can add if deemed appropriate.

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 requested a review from a team as a code owner November 7, 2025 10:45
@aainscow

aainscow commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

@rzarzynski @bill-scales

I will tidy this up and address the relevant parts of the co-pilot review if you think this is a decide idea in principle.

While only required initially for the EC direct reads testing, I think this sounds like a good addition overall to librados.

@aainscow

aainscow commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

no_version_on_read is a plain bool. IoCtx objects are commonly used concurrently. Setting this flag concurrently with reads is a data race (undefined behavior).

I think this is fine. This is a performance improvement for clients that do not need to know the version from a read. It is not intended to be switched on/off in a multithreaded environment (indeed, even with an atomic, this would not work correctly).

A client which needs such fine-grained multi-threaded control should either put up with the performance impact that leaving versions on has, or switch to using NEORADOS which implements such an API properly.

@athanatos

Copy link
Copy Markdown
Contributor

I'll take a look at this on Monday.

@bill-scales

Copy link
Copy Markdown
Contributor

My understanding of the rados_get_last_version API is that it is primarily intended to be used in conjunction with the rados_write_op_assert_version API to implement an atomic read-modify-write. There is also rados_read_op_assert_version and possibly rados_watch (although the docs suggest version doesn't work on watch).

I'd expect there to be two classes of rados application - ones that don't do any atomic updates which don't need the version number and one that do occasional atomic updates which therefore occasionally need the version number.

Your API change caters for the first type of application (although they need to know to opt in to get the benefit), it only helps the 2nd type of application if it wants to repeatedly adjusts the setting. TBH I don't see any application using this API and modern code is hopefully more likely to use neorados which provides more control over when to get the version and deals with all the multi-threading/concurrency issues that the rados_get_last_version API has.

So perhaps the question becomes is it an appropriate change to the API to facilitate testing and should the change just be made to C/C++ version of librados or does it need to be implemented in the wrappers (e.g. python) as well?

@athanatos

Copy link
Copy Markdown
Contributor

This seems like a reasonable change to the api. At present, it doesn't actually impact the MOSDOpReply you get back from the OSD. Presumably, the plan is to include a primary user_version query if the user wants a user_version, so the user needs to be able to signal whether they want it. Seems reasonable to me.

Looks like in neorados, you pass nullptr to execute. If we wanted a non-ioctx switch, I suppose a param to operate/aio_operate would be the analogue. Setting it on the ioctx is convenient to implement and use in tests, I think it's fine for now. We can add it elsewhere if someone wants it.

@aainscow

Copy link
Copy Markdown
Contributor Author

ceph test api

@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test api

@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test windows

Comment thread src/librados/IoCtxImpl.cc Outdated
@@ -683,6 +683,21 @@ int librados::IoCtxImpl::operate(const object_t& oid, ::ObjectOperation *o,
return r;
}

version_t *librados::IoCtxImpl::get_objver_for_read(version_t *objver_p) {

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 am not sure I understand the nature of the returned value: sometimes it's a pointer, and sometimes that pointer is assigned to. Can you add a comment to the .h explaining both the parameter and the returned value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do. Although note that this is supposed to be private. Which I will update soon.

The intent is:

  1. If the version is wanted, then we return the pointer that is passed to the function.
  2. If the version is not wanted, we intentionally invalidate it and pass back a null pointer to indicate that the op should not request a version.

@cbodley

cbodley commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

ok for rgw as long as read versions are enabled by default. last year in #59998 i summarized where rgw depends on version_t, and that does include some read operations

@aainscow

Copy link
Copy Markdown
Contributor Author

ok for rgw as long as read versions are enabled by default. last year in #59998 i summarized where rgw depends on version_t, and that does include some read operations

Thankyou. That is a really useful summary. I don't think we want to turn off the user version in RGW as partial reads which hit the non-primary shard are going to be fairly rare.

The optimisation in split ops is mainly aimed at RBD, where a very high proportion of ops will be submitted to the the non-primary OSDs

@aainscow
aainscow force-pushed the no_obj_ver branch 3 times, most recently from a8d477d to e2f3c4d Compare November 17, 2025 16:04
@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test windows

librados will always request a "user version". Until EC direct reads are implemented
this is a cheap operation and so librados always requests the user version, even if
the client does not need it.

With EC direct reads, requesting the user version requires an extra op to the primary
in some scenarios. The non-primary OSDs do not contain an up to date user
version.

NEORADOS already allows for such optimisations, due to a how the API is organised.

librados is not heavily used by ceph-maintained clients, but this API will still be
useful for testing of EC direct reads, since the test clients will use librados, due
to it simpler nature and performance not being critical in the tests.

Signed-off-by: Alex Ainscow <[email protected]>
@sseshasa

Copy link
Copy Markdown
Contributor

@aainscow I see a related failure in teuthology here:

Teuthology Run and QA Tracker:

Test Logs:
/a/skanta-2025-12-03_02:50:04-rados-wip-bharath5-testing-2025-12-02-1511-distro-default-smithi/8638387

Relevant Log Snippet:

2025-12-03T06:43:44.637 INFO:tasks.workunit.client.0.smithi189.stdout:           MiscPP.NoVer
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp: /ceph/rpmbuild/BUILD/ceph-20.3.0-4385-g15967587/src/test/librados/misc_cxx.cc:936: Failure
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp: Expected equality of these values:
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp:   1
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp:   ioctx.get_last_version()
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp:     Which is: 4
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp:
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp: [  FAILED  ] LibRadosMiscPP.NoVer (675 ms)
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp: [----------] 23 tests from LibRadosMiscPP (212815 ms total)

@aainscow

Copy link
Copy Markdown
Contributor Author

@aainscow I see a related failure in teuthology here:

Teuthology Run and QA Tracker:

Test Logs: /a/skanta-2025-12-03_02:50:04-rados-wip-bharath5-testing-2025-12-02-1511-distro-default-smithi/8638387

Relevant Log Snippet:

2025-12-03T06:43:44.637 INFO:tasks.workunit.client.0.smithi189.stdout:           MiscPP.NoVer
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp: /ceph/rpmbuild/BUILD/ceph-20.3.0-4385-g15967587/src/test/librados/misc_cxx.cc:936: Failure
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp: Expected equality of these values:
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp:   1
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp:   ioctx.get_last_version()
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp:     Which is: 4
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp:
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp: [  FAILED  ] LibRadosMiscPP.NoVer (675 ms)
2025-12-03T06:43:44.638 INFO:tasks.workunit.client.0.smithi189.stdout:              api_misc_pp: [----------] 23 tests from LibRadosMiscPP (212815 ms total)

Thankyou for running this. This is a failed unit test only and I have already fixed it, as it is also tested as part of windows tests (surprisingly).

Can we run this one test again as the fix is test harness only?

@sseshasa

Copy link
Copy Markdown
Contributor

Thankyou for running this. This is a failed unit test only and I have already fixed it, as it is also tested as part of windows tests (surprisingly).

Can we run this one test again as the fix is test harness only?

@SrinivasaBharath Can you please include this PR in another batch and test again?

@ljflores

Copy link
Copy Markdown
Member

@yuriw

yuriw commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Comment thread src/librados/IoCtxImpl.h
uint64_t assert_ver = 0;
version_t last_objver = 0;
uint32_t notify_timeout = 30;
bool no_version_on_read = false;

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.

Comment thread src/librados/IoCtxImpl.h

void set_no_version_on_read(bool _val);
private:
version_t *get_objver_for_read(version_t *objver_p) const;

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.

Yes, it's private.

Comment thread src/librados/IoCtxImpl.cc

version_t *librados::IoCtxImpl::get_objver_for_read(version_t *objver_p) const {
if (!no_version_on_read) {
return objver_p;

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. Pass-through by defualt.

ASSERT_EQ(0, memcmp(bl.c_str(), "ceph", 4));

// last version should now have been corrected.
ASSERT_EQ(version, ioctx.get_last_version());

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.

Comment thread src/librados/IoCtxImpl.cc
}

if (objver_p) {
*objver_p = std::numeric_limits<version_t>::max();

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.

Modifying the AioCompletionImpl::objver here is a bit surprising but overall saves tons of repetition. Fine.

@aainscow
aainscow merged commit 4cb9b6f into ceph:main Feb 4, 2026
@connorfawcett

Copy link
Copy Markdown
Contributor

@aainscow aainscow added the no-backport-required Label that can be optionally added to show that we do not need to backport. label May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core needs-qa no-backport-required Label that can be optionally added to show that we do not need to backport. ready-to-merge TESTED tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.