Skip to content

RUBY-3898 Remove dead cursor-pinning block, fix cursor id for OP_MSG#3073

Draft
comandeo-mongo wants to merge 1 commit into
mongodb:masterfrom
comandeo-mongo:3898-cursor-id-opmsg
Draft

RUBY-3898 Remove dead cursor-pinning block, fix cursor id for OP_MSG#3073
comandeo-mongo wants to merge 1 commit into
mongodb:masterfrom
comandeo-mongo:3898-cursor-id-opmsg

Conversation

@comandeo-mongo

Copy link
Copy Markdown
Contributor

Operation::Result#has_cursor_id? checked replies.last.respond_to?(:cursor_id), which is only true for the legacy Protocol::Reply. Every modern reply is a Protocol::Msg, so the predicate was always false. Two call sites depended on it:

  • The load-balanced cursor pin/unpin block in executable.rb never executed. LB cursors already retain their connection via explicit ownership (Cursor holds @connection since RUBY-3616, released by Cursor#check_in_connection), so the block was a redundant guard.
  • The OpenTelemetry db.mongodb.cursor_id attribute on find/aggregate spans was gated on the dead predicate and therefore never recorded (the request-message path only covers getMore/killCursors).

Changes

  • lib/mongo/operation/shared/executable.rb — removed the dead LB cursor pin/unpin block. Transaction pinning, snapshot handling, and process_result are unchanged.
  • lib/mongo/operation/result.rb — removed has_cursor_id?; made base cursor_id read the id from the OP_MSG cursor subdocument (returning 0 when absent), so it is safe to call on any command result.
  • lib/mongo/tracing/open_telemetry/command_tracer.rb — gate process_cursor_context on cursor_id.positive?. Find/aggregate spans now record db.mongodb.cursor_id.
  • Specs — replaced the #has_cursor_id? coverage in result_spec.rb with OP_MSG #cursor_id cases; updated tracer spec doubles to stub cursor_id instead of the removed predicate.

Test plan

  • bundle exec rubocop on all changed files — no offenses
  • bundle exec rspec spec/mongo/operation/result_spec.rb spec/mongo/tracing/open_telemetry/command_tracer_spec.rb — 142 examples, 0 failures
  • bundle exec rspec spec/mongo/cursor_spec.rb spec/integration/cursor_pinning_spec.rb — 46 examples, 0 failures, 5 pending (LB-only cases, skipped on local replica set)
  • LB cursor_pinning_spec cases run in the Evergreen load-balanced variant (connection-retention regression guard)

RUBY-3898

Operation::Result#has_cursor_id? checked replies.last.respond_to?(:cursor_id),
which is only true for the legacy Protocol::Reply. Every modern reply is a
Protocol::Msg, so the predicate was always false. Two call sites depended on it:

- The load-balanced cursor pin/unpin block in executable.rb never ran. LB
  cursors already retain their connection via explicit ownership (Cursor holds
  @connection since RUBY-3616), so the block was a redundant guard. Removed.
- The OpenTelemetry db.mongodb.cursor_id attribute on find/aggregate spans was
  gated on the dead predicate and never recorded.

Remove has_cursor_id?, make base Result#cursor_id read the cursor id from the
OP_MSG `cursor` subdocument (returning 0 when absent, so it is safe to call on
any command result), and gate the tracer on cursor_id.positive?. Find and
aggregate spans now record the cursor id.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant