summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2017-05-17 19:40:01 -0400
committerMisha Tyulenev <misha@mongodb.com>2017-05-17 19:40:01 -0400
commit2cafeb2f1f18b7986cbd0d6cf23cbadbdcd54b2b (patch)
tree4be88a60b6568156b348c192ccd6788ec736b93d /src/mongo/shell
parent9687c56dad047fb222076c0eb5fb25db6a796219 (diff)
downloadmongo-2cafeb2f1f18b7986cbd0d6cf23cbadbdcd54b2b.tar.gz
SERVER-29071 gossip clusterTime in mongo shell
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/mongo.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index 834568dc87a..471a0e3285c 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -14,6 +14,9 @@ if (!Mongo.prototype) {
(function(original) {
Mongo.prototype.find = function find(ns, query, fields, limit, skip, batchSize, options) {
const self = this;
+ if (this._isCausal) {
+ query = this._gossipLogicalTime(query);
+ }
const res = original.call(this, ns, query, fields, limit, skip, batchSize, options);
const origNext = res.next;
res.next = function next() {
@@ -145,6 +148,15 @@ Mongo.prototype._injectAfterClusterTime = function(cmdObj) {
return cmdObj;
};
+Mongo.prototype._gossipLogicalTime = function(obj) {
+ obj = Object.assign({}, obj);
+ const clusterTime = this.getClusterTime();
+ if (clusterTime) {
+ obj["$logicalTime"] = clusterTime;
+ }
+ return obj;
+};
+
/**
* Sets logicalTime and operationTime extracted from command reply.
* This is applicable for the protocol starting from version 3.6.
@@ -153,8 +165,8 @@ Mongo.prototype._setLogicalTimeFromReply = function(res) {
if (res.hasOwnProperty("operationTime")) {
this.setOperationTime(res["operationTime"]);
}
- if (res.hasOwnProperty("logicalTime")) {
- this.setClusterTime(res["logicalTime"]);
+ if (res.hasOwnProperty("$logicalTime")) {
+ this.setClusterTime(res["$logicalTime"]);
}
};
@@ -167,6 +179,9 @@ Mongo.prototype._setLogicalTimeFromReply = function(res) {
if (this.isCausalConsistencyEnabled(cmdName, cmdObj) && cmdObj) {
cmdObj = this._injectAfterClusterTime(cmdObj);
}
+ if (this._isCausal) {
+ metadata = this._gossipLogicalTime(metadata);
+ }
const res = original.call(this, dbName, cmdName, metadata, cmdObj);
this._setLogicalTimeFromReply(res);
return res;
@@ -183,6 +198,9 @@ Mongo.prototype._setLogicalTimeFromReply = function(res) {
if (this.isCausalConsistencyEnabled(cmdName, cmdObj) && cmdObj) {
cmdObj = this._injectAfterClusterTime(cmdObj);
}
+ if (this._isCausal) {
+ cmdObj = this._gossipLogicalTime(cmdObj);
+ }
const res = original.call(this, dbName, cmdObj, options);
this._setLogicalTimeFromReply(res);
return res;