Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-4447): disable causal consistency in implicit sessions #3479

Merged
merged 5 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/sessions.ts
Expand Up @@ -169,8 +169,10 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
this[kServerSession] = this.explicit ? this.sessionPool.acquire() : null;
this[kTxnNumberIncrement] = 0;

const defaultCausalConsistencyValue = this.explicit && options.snapshot !== true;
this.supports = {
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
causalConsistency: options.snapshot !== true && options.causalConsistency !== false
// if we can enable causal consistency, do so by default
causalConsistency: options.causalConsistency ?? defaultCausalConsistencyValue
};

this.clusterTime = options.initialClusterTime;
Expand Down
318 changes: 318 additions & 0 deletions test/spec/sessions/implicit-sessions-default-causal-consistency.json
@@ -0,0 +1,318 @@
{
"description": "implicit sessions default causal consistency",
"schemaVersion": "1.3",
"runOnRequirements": [
{
"minServerVersion": "4.2",
"topologies": [
"replicaset",
"sharded",
"load-balanced"
]
}
],
"createEntities": [
{
"client": {
"id": "client0",
"useMultipleMongoses": false,
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "implicit-cc-tests"
}
},
{
"collection": {
"id": "collectionDefault",
"database": "database0",
"collectionName": "coll-default"
}
},
{
"collection": {
"id": "collectionSnapshot",
"database": "database0",
"collectionName": "coll-snapshot",
"collectionOptions": {
"readConcern": {
"level": "snapshot"
}
}
}
},
{
"collection": {
"id": "collectionlinearizable",
"database": "database0",
"collectionName": "coll-linearizable",
"collectionOptions": {
"readConcern": {
"level": "linearizable"
}
}
}
}
],
"initialData": [
{
"collectionName": "coll-default",
"databaseName": "implicit-cc-tests",
"documents": [
{
"_id": 1,
"x": "default"
}
]
},
{
"collectionName": "coll-snapshot",
"databaseName": "implicit-cc-tests",
"documents": [
{
"_id": 1,
"x": "snapshot"
}
]
},
{
"collectionName": "coll-linearizable",
"databaseName": "implicit-cc-tests",
"documents": [
{
"_id": 1,
"x": "linearizable"
}
]
}
],
"tests": [
{
"description": "readConcern is not sent on retried read in implicit session when readConcern level is not specified",
"operations": [
{
"name": "failPoint",
"object": "testRunner",
"arguments": {
"client": "client0",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
"times": 1
},
"data": {
"failCommands": [
"find"
],
"errorCode": 11600
}
}
}
},
{
"name": "find",
"object": "collectionDefault",
"arguments": {
"filter": {}
},
"expectResult": [
{
"_id": 1,
"x": "default"
}
]
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"find": "coll-default",
"filter": {},
"readConcern": {
"$$exists": false
}
},
"databaseName": "implicit-cc-tests"
}
},
{
"commandStartedEvent": {
"command": {
"find": "coll-default",
"filter": {},
"readConcern": {
"$$exists": false
}
},
"databaseName": "implicit-cc-tests"
}
}
]
}
]
},
{
"description": "afterClusterTime is not sent on retried read in implicit session when readConcern level is snapshot",
"runOnRequirements": [
{
"minServerVersion": "5.0"
}
],
"operations": [
{
"name": "failPoint",
"object": "testRunner",
"arguments": {
"client": "client0",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
"times": 1
},
"data": {
"failCommands": [
"find"
],
"errorCode": 11600
}
}
}
},
{
"name": "find",
"object": "collectionSnapshot",
"arguments": {
"filter": {}
},
"expectResult": [
{
"_id": 1,
"x": "snapshot"
}
]
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"find": "coll-snapshot",
"filter": {},
"readConcern": {
"level": "snapshot",
"afterClusterTime": {
"$$exists": false
}
}
},
"databaseName": "implicit-cc-tests"
}
},
{
"commandStartedEvent": {
"command": {
"find": "coll-snapshot",
"filter": {},
"readConcern": {
"level": "snapshot",
"afterClusterTime": {
"$$exists": false
}
}
},
"databaseName": "implicit-cc-tests"
}
}
]
}
]
},
{
"description": "afterClusterTime is not sent on retried read in implicit session when readConcern level is linearizable",
"operations": [
{
"name": "failPoint",
"object": "testRunner",
"arguments": {
"client": "client0",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
"times": 1
},
"data": {
"failCommands": [
"find"
],
"errorCode": 11600
}
}
}
},
{
"name": "find",
"object": "collectionlinearizable",
"arguments": {
"filter": {}
},
"expectResult": [
{
"_id": 1,
"x": "linearizable"
}
]
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"find": "coll-linearizable",
"filter": {},
"readConcern": {
"level": "linearizable",
"afterClusterTime": {
"$$exists": false
}
}
},
"databaseName": "implicit-cc-tests"
}
},
{
"commandStartedEvent": {
"command": {
"find": "coll-linearizable",
"filter": {},
"readConcern": {
"level": "linearizable",
"afterClusterTime": {
"$$exists": false
}
}
},
"databaseName": "implicit-cc-tests"
}
}
]
}
]
}
]
}