Skip to content

feat(NODE-7549): send afterClusterTime on writes in causally-consistent sessions - #4963

Merged
tadjik1 merged 6 commits into
mainfrom
node-7549
Jun 25, 2026
Merged

tadjik1 merged 6 commits into
mainfrom
node-7549

Conversation

@PavelSafronov

@PavelSafronov PavelSafronov commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

Summary of Changes

Include afterClusterTime with WRITE commands when in a causally-consistent session.

Notes for Reviewers

Note on testing: The acceptance criteria mention updating the existing causal-consistency prose tests to assert afterClusterTime on writes. Those assertions are now covered comprehensively by the synced unified spec tests (test/spec/causal-consistency/unified/causal-consistency-write-commands.{json,yml} and causal-consistency-clientBulkWrite.{json,yml}), which exercise create, createIndexes, delete, drop, dropDatabase, dropIndexes, findAndModify, insert, update, and bulkWrite. The legacy prose tests (causal_consistency.prose.test.js) were therefore left unchanged to avoid duplicating spec-driven coverage; the TODO(NODE-3882) notes there remain valid for their own scope.

Release Highlight

afterClusterTime now sent on writes in causally-consistent sessions

When a session has causal consistency enabled, write operations now include readConcern.afterClusterTime, matching the existing read behavior. This maintains the "read your own writes" guarantee across primary failovers in shareded clusters. There are no API changes.

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@PavelSafronov
PavelSafronov marked this pull request as ready for review June 12, 2026 14:11
@PavelSafronov
PavelSafronov requested a review from a team as a code owner June 12, 2026 14:11
Copilot AI review requested due to automatic review settings June 12, 2026 14:11

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

This PR updates session command decoration so that, in causally-consistent sessions, readConcern.afterClusterTime is also sent on write commands once an operationTime has been established, aligning write behavior with causal consistency requirements.

Changes:

  • Add commandSupportsAfterClusterTime() and use it from applySession() to attach afterClusterTime beyond just read commands.
  • Extend the unified spec runner with a dropDatabase operation for the new causal consistency test coverage.
  • Add/adjust unified spec tests (including new causal-consistency unified suites) to assert afterClusterTime on writes.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/tools/unified-spec-runner/operations.ts Adds dropDatabase unified operation used by new causal consistency unified specs.
test/spec/transactions/unified/retryable-writes.yml Updates expected command monitoring to require readConcern.afterClusterTime on retryable writes.
test/spec/transactions/unified/retryable-writes.json JSON equivalent updates for retryable writes expectations.
test/spec/transactions/unified/commit.yml Updates expected command monitoring to require readConcern.afterClusterTime on relevant writes.
test/spec/transactions/unified/commit.json JSON equivalent updates for commit suite expectations.
test/spec/transactions-convenient-api/unified/callback-commits.yml Updates expectations to require afterClusterTime in command readConcern.
test/spec/transactions-convenient-api/unified/callback-commits.json JSON equivalent updates for callback commits expectations.
test/spec/transactions-convenient-api/unified/callback-aborts.yml Updates expectations to require afterClusterTime in command readConcern.
test/spec/transactions-convenient-api/unified/callback-aborts.json JSON equivalent updates for callback aborts expectations.
test/spec/causal-consistency/unified/causal-consistency-write-commands.yml Adds new unified causal-consistency coverage for afterClusterTime on a variety of write commands.
test/spec/causal-consistency/unified/causal-consistency-write-commands.json JSON equivalent of the new causal-consistency write command suite.
test/spec/causal-consistency/unified/causal-consistency-clientBulkWrite.yml Adds new unified causal-consistency coverage for afterClusterTime on clientBulkWrite.
test/spec/causal-consistency/unified/causal-consistency-clientBulkWrite.json JSON equivalent of the new causal-consistency clientBulkWrite suite.
test/integration/causal-consistency/causal_consistency.spec.test.ts Wires the new causal-consistency unified specs into the integration test suite.
src/utils.ts Introduces commandSupportsAfterClusterTime() allowlist for commands eligible for afterClusterTime.
src/sessions.ts Switches causal-consistency decoration to use commandSupportsAfterClusterTime() (enabling writes).

Comment thread src/utils.ts Resolved
@tadjik1 tadjik1 self-assigned this Jun 17, 2026
@tadjik1 tadjik1 added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jun 17, 2026
Comment thread src/utils.ts Resolved
@tadjik1

tadjik1 commented Jun 24, 2026

Copy link
Copy Markdown
Member

@PavelSafronov it seems that most of the failures are not relevant, however, I noticed the linter is failing, can you please take a look?

@tadjik1
tadjik1 merged commit 3abfd26 into main Jun 25, 2026
33 checks passed
@tadjik1
tadjik1 deleted the node-7549 branch June 25, 2026 08:23
@PavelSafronov PavelSafronov changed the title fix(NODE-7549): send afterClusterTime on writes in causally-consistent sessions feat(NODE-7549): send afterClusterTime on writes in causally-consistent sessions Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Primary Review In Review with primary reviewer, not yet ready for team's eyes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants