Skip to content

Commit

Permalink
fix(NODE-4447): disable causal consistency in implicit sessions (#3479)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariakp committed Dec 2, 2022
1 parent bb6683d commit 6566fb5
Show file tree
Hide file tree
Showing 4 changed files with 499 additions and 1 deletion.
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 = {
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"
}
}
]
}
]
}
]
}

0 comments on commit 6566fb5

Please sign in to comment.