RUBY-3820 Send afterClusterTime on writes in causally-consistent sessions#3075
Merged
Conversation
…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.
Contributor
There was a problem hiding this comment.
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
CausalConsistencySupportedin write op_msg operations so writes can attachafterClusterTimeoutside ofstartTransaction. - Add a new unified causal consistency spec suite (fixtures + spec file) and update existing transaction-related fixtures to expect
afterClusterTimeon post-transaction writes. - Update unified test runner operations to thread
sessionthrough additional CRUD/DDL operations and add adropDatabasehandler; 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
comandeo-mongo
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andwrite_command) nowinclude CausalConsistencySupported. That override always applies the causal consistency document (rather than only forstartTransaction), so writes emitafterClusterTimewhen the session is causally consistent and has an operation time. For writes this attaches onlyafterClusterTimewith no read concern level, since write specs never populate a read concern.Testing and runner changes
spec/spec_tests/causal_consistency_unified_spec.rbplus fixtures).:sessionthroughIndex::View#drop_by_nameso a session passed todrop/drop_allis honored.sessionargument support to the affected unified runner operations, including a newdrop_databasehandler.clientBulkWritefixture is skipped at runtime pending RUBY-2964, since the driver does not yet implement thebulkWritecommand.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 expectafterClusterTime.Verification
causal_consistency_unified_spec.rb: 18 examples, 0 failures, 1 pending (clientBulkWrite).transactions_spec.rbandtransactions_api_spec.rb: 2197 examples, 0 failures.