Skip to content

RUBY-3820 Send afterClusterTime on writes in causally-consistent sessions#3075

Merged
jamis merged 2 commits into
mongodb:masterfrom
jamis:3820-afterClusterTime
Jul 7, 2026
Merged

RUBY-3820 Send afterClusterTime on writes in causally-consistent sessions#3075
jamis merged 2 commits into
mongodb:masterfrom
jamis:3820-afterClusterTime

Conversation

@jamis

@jamis jamis commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Writes performed in a causally consistent session now attach afterClusterTime, matching the updated causal consistency spec (split from DRIVERS-3274). Previously only reads carried it.

The write operation op_msg classes (insert, update, delete, create, create_index, drop, drop_database, drop_index, and write_command) now include CausalConsistencySupported. That override always applies the causal consistency document (rather than only for startTransaction), so writes emit afterClusterTime when the session is causally consistent and has an operation time. For writes this attaches only afterClusterTime with no read concern level, since write specs never populate a read concern.

Testing and runner changes

  • Added the causal consistency unified spec suite (spec/spec_tests/causal_consistency_unified_spec.rb plus fixtures).
  • Threaded an explicit :session through Index::View#drop_by_name so a session passed to drop/drop_all is honored.
  • Added session argument support to the affected unified runner operations, including a new drop_database handler.
  • The clientBulkWrite fixture is skipped at runtime pending RUBY-2964, since the driver does not yet implement the bulkWrite command.

Fixture updates

Existing transaction fixtures (transactions/commit.yml, transactions/retryable-writes.yml, transactions_api/callback-aborts.yml, transactions_api/callback-commits.yml) were updated: post-transaction writes in the same causally consistent session now expect afterClusterTime.

Verification

  • causal_consistency_unified_spec.rb: 18 examples, 0 failures, 1 pending (clientBulkWrite).
  • Combined with transactions_spec.rb and transactions_api_spec.rb: 2197 examples, 0 failures.
  • RuboCop clean.

…ions

Include CausalConsistencySupported in the write operation op_msg classes
(insert, update, delete, create, create_index, drop, drop_database,
drop_index, and write_command) so that writes attach afterClusterTime
when running in a causally consistent session, preserving causal
ordering across writes.

Thread an explicit :session through Index::View#drop_by_name, add
session support to the affected unified runner operations (including a
new drop_database handler), and add the causal consistency unified spec
suite. The clientBulkWrite fixture is skipped pending RUBY-2964, since
the driver does not implement the bulkWrite command yet.

Update existing transaction fixtures whose post-transaction writes now
carry afterClusterTime.
@jamis jamis requested a review from a team as a code owner July 6, 2026 21:05
@jamis jamis requested review from comandeo-mongo and Copilot July 6, 2026 21:05

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

Updates the Ruby driver’s causal consistency behavior to attach readConcern.afterClusterTime to write commands executed in a causally consistent session (when an operationTime is available), aligning with the updated causal consistency specification.

Changes:

  • Include CausalConsistencySupported in write op_msg operations so writes can attach afterClusterTime outside of startTransaction.
  • Add a new unified causal consistency spec suite (fixtures + spec file) and update existing transaction-related fixtures to expect afterClusterTime on post-transaction writes.
  • Update unified test runner operations to thread session through additional CRUD/DDL operations and add a dropDatabase handler; ensure index drops honor explicitly provided sessions.

Reviewed changes

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

Show a summary per file
File Description
spec/spec_tests/data/transactions/retryable-writes.yml Updates event expectations to include afterClusterTime on retryable writes after a transaction.
spec/spec_tests/data/transactions/commit.yml Updates event expectations to include afterClusterTime on relevant post-transaction writes.
spec/spec_tests/data/transactions_api/callback-commits.yml Updates callback transaction fixtures to expect afterClusterTime on subsequent writes.
spec/spec_tests/data/transactions_api/callback-aborts.yml Updates callback transaction fixtures to expect afterClusterTime on subsequent writes.
spec/spec_tests/data/causal_consistency_unified/causal-consistency-write-commands.yml Adds a unified test suite asserting afterClusterTime is sent on many write commands in causally consistent sessions.
spec/spec_tests/data/causal_consistency_unified/causal-consistency-clientBulkWrite.yml Adds a unified fixture for clientBulkWrite causal consistency behavior (runtime-skipped by runner).
spec/spec_tests/causal_consistency_unified_spec.rb Adds an RSpec entrypoint to run the new unified causal consistency suite.
spec/runners/unified/ddl_operations.rb Threads session through DDL runner operations and adds a drop_database operation handler.
spec/runners/unified/crud_operations.rb Threads session through additional CRUD runner operations (update/replace/delete/bulkWrite).
lib/mongo/operation/write_command/op_msg.rb Enables causal consistency override on write_command op_msg.
lib/mongo/operation/update/op_msg.rb Enables causal consistency override on update op_msg.
lib/mongo/operation/shared/causal_consistency_supported.rb Updates module documentation to reflect write support and semantics.
lib/mongo/operation/insert/op_msg.rb Enables causal consistency override on insert op_msg.
lib/mongo/operation/drop/op_msg.rb Enables causal consistency override on drop op_msg.
lib/mongo/operation/drop_index/op_msg.rb Enables causal consistency override on drop_index op_msg.
lib/mongo/operation/drop_database/op_msg.rb Enables causal consistency override on drop_database op_msg.
lib/mongo/operation/delete/op_msg.rb Enables causal consistency override on delete op_msg.
lib/mongo/operation/create/op_msg.rb Enables causal consistency override on create op_msg.
lib/mongo/operation/create_index/op_msg.rb Enables causal consistency override on create_index op_msg.
lib/mongo/index/view.rb Ensures an explicitly provided session is honored when dropping indexes by name.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

# Conflicts:
#	spec/runners/unified/crud_operations.rb
@jamis jamis merged commit e319046 into mongodb:master Jul 7, 2026
213 checks passed
@jamis jamis deleted the 3820-afterClusterTime branch July 7, 2026 16:04
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.

3 participants