summaryrefslogtreecommitdiff
path: root/src/mongo/shell/session.js
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2018-04-11 19:18:16 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2018-04-13 14:38:26 -0400
commitc483f7751482b15ddf900b565bce68b8f898e6ab (patch)
tree00bb502127ec2bdc4085db7dc8c18a1b169215c1 /src/mongo/shell/session.js
parent64f24ed205a4d83aece37c5f2c64af26624113c1 (diff)
downloadmongo-c483f7751482b15ddf900b565bce68b8f898e6ab.tar.gz
SERVER-34321 Require stmtId for multi-statement transactions in the shell.
Diffstat (limited to 'src/mongo/shell/session.js')
-rw-r--r--src/mongo/shell/session.js29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/mongo/shell/session.js b/src/mongo/shell/session.js
index e32dc4e9708..022c158e7ea 100644
--- a/src/mongo/shell/session.js
+++ b/src/mongo/shell/session.js
@@ -476,10 +476,8 @@ var {
let _txnOptions;
- // Keep track of the first statement of a transaction, which is the only statement
- // in which a user can specify a readConcern and writeConcern.
- // This will eventually turn into a stmtId field.
- let _firstStatement = false;
+ // Keep track of the next available statement id of a transaction.
+ let _nextStatementId = 0;
// _txnNumber starts at -1 because when we increment it, the first transaction
// and retryable write will both have a txnNumber of 0.
@@ -657,14 +655,31 @@ var {
// All operations of a multi-statement transaction must specify autocommit=false.
cmdObjUnwrapped.autocommit = false;
+ // Statement Id is required on all transaction operations.
+ cmdObjUnwrapped.stmtId = new NumberInt(_nextStatementId);
+
// 'readConcern' and 'startTransaction' can only be specified on the first statement in
// a transaction.
- if (_firstStatement) {
+ if (_nextStatementId == 0) {
cmdObjUnwrapped.startTransaction = true;
if (_txnOptions.getTxnReadConcern() !== undefined) {
cmdObjUnwrapped.readConcern = _txnOptions.getTxnReadConcern();
}
- _firstStatement = false;
+ }
+
+ // Reserve the statement ids for batch writes.
+ switch (cmdName) {
+ case "insert":
+ _nextStatementId += cmdObjUnwrapped.documents.length;
+ break;
+ case "update":
+ _nextStatementId += cmdObjUnwrapped.updates.length;
+ break;
+ case "delete":
+ _nextStatementId += cmdObjUnwrapped.deletes.length;
+ break;
+ default:
+ _nextStatementId += 1;
}
return cmdObj;
@@ -673,7 +688,7 @@ var {
this.startTransaction = function startTransaction(txnOptsObj) {
_txnOptions = new TransactionOptions(txnOptsObj);
_txnState = ServerSession.TransactionStates.kActive;
- _firstStatement = true;
+ _nextStatementId = 0;
_txnNumber++;
};