Skip to content

Ignore BALANCED/LOCALIZE READS flags for watch/notify/notify_ack and pg ops - #70629

Merged
SrinivasaBharath merged 3 commits into
ceph:mainfrom
bill-scales:issue76955
Sep 30, 2026
Merged

SrinivasaBharath merged 3 commits into
ceph:mainfrom
bill-scales:issue76955

Conversation

@bill-scales

@bill-scales bill-scales commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

The conf setting setting rados_replica_read_policy can be used to enable balance or localize reads, these flags get added to all client requests by librados/objecter.

However there are some ops which can only be processed by the primary OSD and do not work correctly if issued to a non-primary.

One subclass of ops which must be sent to the primary are the watch, notify and notify_ack ops. This is because a watch op sets up volatile state in the OSD which is then used by the subsequent notify and notify_ack ops.

A second subclass of ops which must be sent to the primary are the pg ops such as pgnls and scrubls. These pg level ops rely on state that is only maintained on the primary.

The whole rationale for balanced and localized reads is to improve performance, in particular for I/O requests transferring a lot of data. Neither watch/notify/notify_ack or pg ops are issued frequently or have large enough data payloads to be worthwhile optimizing.

The fixes are implemented in two halves:

  1. The client code is changed to ignore these flags
  2. The OSD code is changed to police that these requests are sent to the primary and to fail requests sent to the non-primary with EAGAIN which will cause the client to reissue the request to the primary OSD.

Either half of the fixes is sufficient, so just upgrading the OSDs will be sufficient to fix the issue

Fixes: https://tracker.ceph.com/issues/76954
Fixes: https://tracker.ceph.com/issues/76955

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.

@bill-scales
bill-scales requested a review from a team as a code owner July 28, 2026 14:44
Copilot AI review requested due to automatic review settings July 28, 2026 14:44
@github-actions github-actions Bot added the core label Jul 28, 2026
@bill-scales
bill-scales removed the request for review from Copilot July 28, 2026 14:45

@JonBailey1993 JonBailey1993 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.

Just one comment after reviewing

Comment thread src/librados/IoCtxImpl.cc Outdated
// that Objecter does not route this to a non-primary replica.
int flags = extra_op_flags &
~(CEPH_OSD_FLAG_BALANCE_READS | CEPH_OSD_FLAG_LOCALIZE_READS);
objecter->read(oid, oloc, rd, snap_seq, (bufferlist*)NULL, flags, 0, 0);

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 method calls objecter->read(...), which calls prepare_read_op(...), which calls get_read_flags(flags) passing in these flags.

int get_read_flags(int flags) {
    int ret = flags | global_op_flags |
              extra_read_flags.load(std::memory_order_relaxed) |
              CEPH_OSD_FLAG_READ;

    // If the op is rwordered or a PG op, strip out the balanced and localized
    // flags since those ops must be handled by the primary OSD.
    if (flags & (CEPH_OSD_FLAG_RWORDERED | CEPH_OSD_FLAG_PGOP)) {
      ret &= ~(CEPH_OSD_FLAG_BALANCE_READS | CEPH_OSD_FLAG_LOCALIZE_READS);
    }
    return ret;
  }

extra_read_flags is used to store CEPH_OSD_FLAG_BALANCE_READS and CEPH_OSD_FLAG_LOCALIZE_READS when they get set.

I believe currently we can still see balanced notify_ack's and need to find a way to ensure they are not added back by get_read_flags(...).

@bill-scales

Copy link
Copy Markdown
Contributor Author

Pushed fixes - add read_primary methods to objecter that always route the read request to the primary OSD by clearing the balanced/localized read flags. Modified notify_ack to use these new methods.

Tested with ceph_test_rados from the pool migration branch which has fixes for watch/notify/notify_ack testing and confirmed all these requests were always sent to the primary.

Copilot AI 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.

Pull request overview

Prevents primary-only RADOS operations from being routed to replica OSDs.

Changes:

  • Strips replica-read flags from PG and watch/notify requests.
  • Adds primary-only operation classification and OSD-side EAGAIN handling.
  • Routes notify acknowledgements through new primary-read helpers.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/osdc/Objecter.h Adds primary-read helpers and PG flag filtering.
src/osdc/Objecter.cc Strips replica-read flags from linger operations.
src/osd/PrimaryLogPG.cc Rejects primary-only replica requests.
src/osd/osd_types.h Defines the primary-only internal flag.
src/osd/osd_op_util.h Declares primary-only metadata helpers.
src/osd/osd_op_util.cc Classifies PG and watch/notify operations.
src/osd/OpRequest.h Exposes primary-only classification.
src/neorados/RADOS.cc Routes notify acknowledgements to primaries.
src/librados/IoCtxImpl.cc Routes legacy notify acknowledgements to primaries.

Comment thread src/osdc/Objecter.h Resolved
Comment thread src/osd/PrimaryLogPG.cc Resolved

@JonBailey1993 JonBailey1993 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, one question on if we can simplify/deduplicate the new read_primary functions

Comment thread src/osdc/Objecter.h Resolved

@JonBailey1993 JonBailey1993 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.

Couple tiny nits that can be ignored if you like, but LGTM

Comment thread src/osdc/Objecter.h Resolved
Comment thread src/osdc/Objecter.h Resolved
The conf setting rados_replica_read_policy can be used to
enable balance or localize reads, these flags get added to all
client requests.

However not all ops work if sent to a non-primary OSD. This
commit fixes watch, notify and notify_ack ops so that the
client ignores the balance and localize read flag and always
sends these to the primary OSD.

Updating clients is hard, so update the OSD to police this
as well and fail requests with EAGAIN (which will force
downlevel client to resubmit to the primary).

Fixes: https://tracker.ceph.com/issues/76955

Signed-off-by: Bill Scales <[email protected]>
Assisted-by: IBM Bob 2.0.1
The conf setting rados_replica_read_policy can be used to
enable balance or localize reads, these flags get added to all
client requests.

However not all ops work if sent to a non-primary OSD. This
commit fixes pg ops such as scrubls and pgnls so that they are
always sent to the primary OSD.

Updating clients is hard, so update the OSD to police this
as well and fail requests with EAGAIN (which will force
downlevel client to resubmit to the primary).

Fixes: https://tracker.ceph.com/issues/76954

Signed-off-by: Bill Scales <[email protected]>
Assisted-by: IBM Bob 2.0.1
The CEPH_OSD_FLAG_PGOP was getting set in various different places
as PG ops were constructed. Tidy this up so that the flag is set
when pg_read or prepare_pg_read_op are called. This makes it safe
to change pg_read to call get_read_flags and ensures PG ops cannot
have the balanced or localize read flags set.

Signed-off-by: Bill Scales <[email protected]>
@bill-scales

Copy link
Copy Markdown
Contributor Author

Force push to just fix whitespace issue, not going to delete pg_ls even if it is unused.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath29-testing-20260924.231744-main.

@NitzanMordhai

Copy link
Copy Markdown
Contributor

@SrinivasaBharath
SrinivasaBharath merged commit 1b14e27 into ceph:main Sep 30, 2026
16 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/36787528059

@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/36787528059

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.

5 participants