diff options
author | Misha Tyulenev <misha@mongodb.com> | 2017-12-15 13:48:58 -0500 |
---|---|---|
committer | Misha Tyulenev <misha@mongodb.com> | 2017-12-15 15:54:03 -0500 |
commit | 36874a480ea4e2be33af298777a8d6824b7b974e (patch) | |
tree | dd7f7fdb415c76710c52c804a9168ed43abbb29f /src | |
parent | b1ae796faf5f262cd658f59a59d18f8c3eb0d4ee (diff) | |
download | mongo-36874a480ea4e2be33af298777a8d6824b7b974e.tar.gz |
SERVER-31916 wait for clusterTime on mongo connection
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/commands/oplog_note.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/read_concern.cpp | 2 | ||||
-rw-r--r-- | src/mongo/shell/mongo.js | 21 |
3 files changed, 23 insertions, 2 deletions
diff --git a/src/mongo/db/commands/oplog_note.cpp b/src/mongo/db/commands/oplog_note.cpp index d3efa60ac50..914da7721ff 100644 --- a/src/mongo/db/commands/oplog_note.cpp +++ b/src/mongo/db/commands/oplog_note.cpp @@ -148,7 +148,7 @@ public: result, _performNoopWrite(opCtx, dataElement.Obj(), "appendOpLogNote")); } else { std::stringstream ss; - ss << "Requested maxClusterTime" << LogicalTime(maxClusterTime).toString() + ss << "Requested maxClusterTime " << LogicalTime(maxClusterTime).toString() << " is less or equal to the last primary OpTime: " << LogicalTime(lastAppliedOpTime).toString(); return appendCommandStatus(result, {ErrorCodes::StaleClusterTime, ss.str()}); diff --git a/src/mongo/db/read_concern.cpp b/src/mongo/db/read_concern.cpp index afae793f6e8..0d3dd1baf82 100644 --- a/src/mongo/db/read_concern.cpp +++ b/src/mongo/db/read_concern.cpp @@ -148,7 +148,7 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) { if (!remainingAttempts--) { std::stringstream ss; - ss << "Requested clusterTime" << clusterTime.toString() + ss << "Requested clusterTime " << clusterTime.toString() << " is greater than the last primary OpTime: " << lastAppliedOpTime.toString() << " no retries left"; return Status(ErrorCodes::InternalError, ss.str()); diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js index a5077fe9471..2a477659eb8 100644 --- a/src/mongo/shell/mongo.js +++ b/src/mongo/shell/mongo.js @@ -441,3 +441,24 @@ Mongo.prototype.isCausalConsistency = function isCausalConsistency() { Mongo.prototype.setCausalConsistency = function setCausalConsistency(causalConsistency = true) { this._causalConsistency = causalConsistency; }; + +Mongo.prototype.waitForClusterTime = function waitForClusterTime(maxRetries = 10) { + let isFirstTime = true; + let count = 0; + while (count < maxRetries) { + if (typeof this._clusterTime === "object" && this._clusterTime !== null) { + if (this._clusterTime.hasOwnProperty("signature") && + this._clusterTime.signature.keyId > 0) { + return; + } + } + if (isFirstTime) { + isFirstTime = false; + } else { + sleep(500); + } + count++; + this.adminCommand({"ping": 1}); + } + throw new Error("failed waiting for non default clusterTime"); +}; |