summaryrefslogtreecommitdiff
path: root/src/mongo/shell/mongo.js
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2017-12-15 13:48:58 -0500
committerMisha Tyulenev <misha@mongodb.com>2017-12-15 15:54:03 -0500
commit36874a480ea4e2be33af298777a8d6824b7b974e (patch)
treedd7f7fdb415c76710c52c804a9168ed43abbb29f /src/mongo/shell/mongo.js
parentb1ae796faf5f262cd658f59a59d18f8c3eb0d4ee (diff)
downloadmongo-36874a480ea4e2be33af298777a8d6824b7b974e.tar.gz
SERVER-31916 wait for clusterTime on mongo connection
Diffstat (limited to 'src/mongo/shell/mongo.js')
-rw-r--r--src/mongo/shell/mongo.js21
1 files changed, 21 insertions, 0 deletions
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");
+};