Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
} from './transactions';
import {
calculateDurationInMs,
commandSupportsReadConcern,
commandSupportsAfterClusterTime,
isPromiseLike,
List,
MongoDBNamespace,
Expand Down Expand Up @@ -1215,7 +1215,7 @@ export function applySession(
if (
session.supports.causalConsistency &&
session.operationTime &&
commandSupportsReadConcern(command)
commandSupportsAfterClusterTime(command)
) {
command.readConcern = command.readConcern || {};
Object.assign(command.readConcern, { afterClusterTime: session.operationTime });
Expand Down
41 changes: 41 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,47 @@ export function commandSupportsReadConcern(command: Document): boolean {
if (command.aggregate || command.count || command.distinct || command.find || command.geoNear) {
return true;
}
return false;
}

/**
* @internal
*/
export function commandSupportsAfterClusterTime(command: Document): boolean {
// READ operations
if (
command.aggregate ||
command.count ||
command.dbStats ||
command.distinct ||
command.find ||
command.geoNear ||
// command.getMore ||
command.listIndexes ||
command.listCollections ||
command.listDatabases
Comment thread
tadjik1 marked this conversation as resolved.
Resolved
) {
return true;
}
Comment thread
tadjik1 marked this conversation as resolved.
Resolved

// WRITE operations
if (
command.bulkWrite ||
command.create ||
command.createIndexes ||
command.delete ||
command.drop ||
command.dropDatabase ||
command.dropIndexes ||
// command.dropUser ||
// command.endSessions ||
command.findAndModify ||
command.insert ||
// command.renameCollection ||
command.update
) {
return true;
}

return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as path from 'path';

import { loadSpecTests } from '../../spec';
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';

describe('Causal Consistency Spec - Unified', function () {
runUnifiedSuite(loadSpecTests(path.join('causal-consistency', 'unified')));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"description": "causal consistency bulkWrite include afterClusterTime",
"schemaVersion": "1.3",
"runOnRequirements": [
{
"minServerVersion": "8.0",
"topologies": [
"replicaset",
"sharded",
"load-balanced"
]
}
],
"createEntities": [
{
"client": {
"id": "client0",
"useMultipleMongoses": false,
"uriOptions": {
"retryWrites": false
},
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "causal-consistency-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
},
{
"session": {
"id": "session0",
"client": "client0",
"sessionOptions": {
"causalConsistency": true
}
}
}
],
"initialData": [
{
"collectionName": "test",
"databaseName": "causal-consistency-tests",
"documents": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
],
"tests": [
{
"description": "clientBulkWrite includes afterClusterTime in causally consistent session",
"operations": [
{
"name": "find",
"object": "collection0",
"arguments": {
"session": "session0",
"filter": {
"_id": 1
}
},
"expectResult": [
{
"_id": 1,
"x": 11
}
]
},
{
"name": "clientBulkWrite",
"object": "client0",
"arguments": {
"session": "session0",
"models": [
{
"insertOne": {
"namespace": "causal-consistency-tests.test",
"document": {
"_id": 4
}
}
}
]
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"commandName": "find",
"command": {
"find": "test",
"readConcern": {
"$$exists": false
},
"lsid": {
"$$sessionLsid": "session0"
}
}
}
},
{
"commandStartedEvent": {
"commandName": "bulkWrite",
"command": {
"bulkWrite": 1,
"lsid": {
"$$sessionLsid": "session0"
},
"readConcern": {
"afterClusterTime": {
"$$exists": true
},
"level": {
"$$exists": false
}
}
}
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
description: "causal consistency bulkWrite include afterClusterTime"

schemaVersion: "1.3"

runOnRequirements:
- minServerVersion: "8.0"
topologies: [replicaset, sharded, load-balanced]

createEntities:
- client:
id: &client0 client0
useMultipleMongoses: false
uriOptions:
retryWrites: false
observeEvents: [commandStartedEvent]
- database:
id: &database0 database0
client: *client0
databaseName: &databaseName causal-consistency-tests
- collection:
id: &collection0 collection0
database: *database0
collectionName: &collectionName test
- session:
id: &session0 session0
client: *client0
sessionOptions:
causalConsistency: true

initialData:
- collectionName: *collectionName
databaseName: *databaseName
documents:
- { _id: 1, x: 11 }
- { _id: 2, x: 22 }
- { _id: 3, x: 33 }

# In a causally consistent session, once an operationTime has been established by a prior
# operation, subsequent write commands MUST include readConcern.afterClusterTime so the
# server can apply the write causally after the previously-observed data.

tests:
- description: "clientBulkWrite includes afterClusterTime in causally consistent session"
operations:
- name: find
object: *collection0
arguments:
session: *session0
filter: { _id: 1 }
expectResult: [{ _id: 1, x: 11 }]
- name: clientBulkWrite
object: *client0
arguments:
session: *session0
models:
- insertOne:
namespace: causal-consistency-tests.test
document: { _id: 4 }
expectEvents:
- client: *client0
events:
- commandStartedEvent:
commandName: find
command:
find: *collectionName
readConcern: { $$exists: false }
lsid: { $$sessionLsid: *session0 }
- commandStartedEvent:
commandName: bulkWrite
command:
bulkWrite: 1
lsid: { $$sessionLsid: *session0 }
readConcern:
afterClusterTime: { $$exists: true }
level: { $$exists: false }
Loading
Loading