summaryrefslogtreecommitdiff
path: root/src/mongo/shell/session.js
diff options
context:
space:
mode:
authorA. Jesse Jiryu Davis <jesse@mongodb.com>2019-01-06 16:00:21 -0500
committerA. Jesse Jiryu Davis <jesse@mongodb.com>2019-01-15 18:06:46 -0500
commit77080261840ce98ea3808f570a7ef72ebeb08b78 (patch)
treeee7fbbdfe2ab7073e76833485af920d6b73e8ae9 /src/mongo/shell/session.js
parentde2a803ca492261cac1d7f43a9f7c847cd0ea24d (diff)
downloadmongo-77080261840ce98ea3808f570a7ef72ebeb08b78.tar.gz
SERVER-38717 Shell prohibits w: 0 in session
Diffstat (limited to 'src/mongo/shell/session.js')
-rw-r--r--src/mongo/shell/session.js32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/mongo/shell/session.js b/src/mongo/shell/session.js
index d1587440545..62d5a070dfa 100644
--- a/src/mongo/shell/session.js
+++ b/src/mongo/shell/session.js
@@ -16,6 +16,18 @@ var {
return typeof obj === "object" && obj !== null;
}
+ function isAcknowledged(cmdObj) {
+ if (isNonNullObject(cmdObj.writeConcern)) {
+ const writeConcern = cmdObj.writeConcern;
+ // Intentional use of "==" comparing NumberInt, NumberLong, or plain Number.
+ if (writeConcern.hasOwnProperty("w") && writeConcern.w == 0) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
function SessionOptions(rawOptions = {}) {
if (!(this instanceof SessionOptions)) {
return new SessionOptions(rawOptions);
@@ -219,6 +231,10 @@ var {
}
function prepareCommandRequest(driverSession, cmdObj) {
+ if (driverSession._isExplicit && !isAcknowledged(cmdObj)) {
+ throw new Error("Unacknowledged writes are prohibited with sessions");
+ }
+
if (serverSupports(kWireVersionSupportingLogicalSession) &&
// Always attach sessionId from explicit sessions.
(driverSession._isExplicit ||
@@ -549,7 +565,9 @@ var {
}
if (!cmdObjUnwrapped.hasOwnProperty("lsid")) {
- cmdObjUnwrapped.lsid = this.handle.getId();
+ if (isAcknowledged(cmdObjUnwrapped)) {
+ cmdObjUnwrapped.lsid = this.handle.getId();
+ }
// We consider the session to still be in use by the client any time the session id
// is injected into the command object as part of making a request.
@@ -594,16 +612,8 @@ var {
return false;
}
- if (isNonNullObject(cmdObj.writeConcern)) {
- const writeConcern = cmdObj.writeConcern;
-
- // We use bsonWoCompare() in order to handle cases where the "w" field is specified
- // as a NumberInt() or NumberLong() instance.
- if (writeConcern.hasOwnProperty("w") &&
- bsonWoCompare({_: writeConcern.w}, {_: 0}) === 0) {
- // Unacknowledged writes cannot be retried.
- return false;
- }
+ if (!isAcknowledged(cmdObj)) {
+ return false;
}
if (cmdName === "insert") {