diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-11-08 19:29:28 -0500 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-11-08 19:29:28 -0500 |
commit | 6d8e6b9cce052cdd442e207a27df10e698b2bb00 (patch) | |
tree | 5a7bb7b5cf93902bf00a681dccb0f54adb2f1ab0 /src/mongo/scripting | |
parent | f7756c41c5ed54e8e546461395bc8898d885af0c (diff) | |
download | mongo-6d8e6b9cce052cdd442e207a27df10e698b2bb00.tar.gz |
SERVER-31296 Update sessions, causal, and retryable in the mongo shell.
* Removes the initialClusterTime and initialOperationTime session
options.
* Enables causal consistency by default when using an explicit
session.
* Adds a --retryWrites command line option to the mongo shell for
enabling retryable writes in the mongo shell. The retryWrites
options to SessionOptions is left for convenience with testing.
* Renames setClusterTime() to advanceClusterTime(), and adds a
corresponding advanceOperationTime() method to DriverSession.
* Enables assigning transaction numbers for write commands where
ordered=false.
* Prevents the mongo shell from sending afterClusterTime or assigning
transaction numbers when talking to a stand-alone mongod.
* Prevents the mongo shell from assigning transaction numbers when
using an unacknowledged (w=0) writeConcern.
* Changes DBClientRS to re-discover the current primary of the replica
set when it receives an error code representing "not master" in
addition to an error message representing "not master".
* Adds a shellPrint() pretty-printer for SessionOptions and
DriverSession instances so they no longer print out their entire
object definition.
Diffstat (limited to 'src/mongo/scripting')
-rw-r--r-- | src/mongo/scripting/mozjs/mongo.cpp | 31 | ||||
-rw-r--r-- | src/mongo/scripting/mozjs/mongo.h | 8 |
2 files changed, 29 insertions, 10 deletions
diff --git a/src/mongo/scripting/mozjs/mongo.cpp b/src/mongo/scripting/mozjs/mongo.cpp index debede5bee7..c740e3acadc 100644 --- a/src/mongo/scripting/mozjs/mongo.cpp +++ b/src/mongo/scripting/mozjs/mongo.cpp @@ -88,7 +88,10 @@ const JSFunctionSpec MongoBase::methods[] = { isReplicaSetMember, MongoLocalInfo, MongoExternalInfo), MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(isMongos, MongoLocalInfo, MongoExternalInfo), MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(getClusterTime, MongoLocalInfo, MongoExternalInfo), - MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(setClusterTime, MongoLocalInfo, MongoExternalInfo), + MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO( + advanceClusterTime, MongoLocalInfo, MongoExternalInfo), + MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO( + resetClusterTime_forTesting, MongoLocalInfo, MongoExternalInfo), MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(_startSession, MongoLocalInfo, MongoExternalInfo), JS_FS_END, }; @@ -194,9 +197,14 @@ BSONObj MongoBase::getClusterTime() { return latestlogicalTime; } -void MongoBase::setClusterTime(const BSONObj& newTime) { +void MongoBase::resetClusterTime_forTesting() { + stdx::lock_guard<stdx::mutex> lk(logicalTimeMutex); + latestlogicalTime = BSONObj(); +} + +void MongoBase::advanceClusterTime(const BSONObj& newTime) { if (newTime["clusterTime"].eoo()) - uasserted(ErrorCodes::BadValue, "missing clusterTime field in setClusterTime argument"); + uasserted(ErrorCodes::BadValue, "missing clusterTime field in advanceClusterTime argument"); stdx::lock_guard<stdx::mutex> lk(logicalTimeMutex); if (latestlogicalTime.isEmpty() || @@ -791,17 +799,26 @@ void MongoBase::Functions::getClusterTime::call(JSContext* cx, JS::CallArgs args args.rval().setUndefined(); } -void MongoBase::Functions::setClusterTime::call(JSContext* cx, JS::CallArgs args) { +void MongoBase::Functions::advanceClusterTime::call(JSContext* cx, JS::CallArgs args) { if (args.length() != 1) - uasserted(ErrorCodes::BadValue, "setClusterTime takes 1 argument"); + uasserted(ErrorCodes::BadValue, "advanceClusterTime takes 1 argument"); if (!args.get(0).isObject()) - uasserted(ErrorCodes::BadValue, "the parameter to setClusterTime must be an object"); + uasserted(ErrorCodes::BadValue, "the parameter to advanceClusterTime must be an object"); auto newTime = ObjectWrapper(cx, args.get(0)).toBSON(); - MongoBase::setClusterTime(newTime); + MongoBase::advanceClusterTime(newTime); + + args.rval().setUndefined(); +} + +void MongoBase::Functions::resetClusterTime_forTesting::call(JSContext* cx, JS::CallArgs args) { + if (args.length() != 0) { + uasserted(ErrorCodes::BadValue, "resetClusterTime_forTesting takes no arguments"); + } + MongoBase::resetClusterTime_forTesting(); args.rval().setUndefined(); } diff --git a/src/mongo/scripting/mozjs/mongo.h b/src/mongo/scripting/mozjs/mongo.h index f6c6a535c1c..4d7a0200bd7 100644 --- a/src/mongo/scripting/mozjs/mongo.h +++ b/src/mongo/scripting/mozjs/mongo.h @@ -65,17 +65,19 @@ struct MongoBase : public BaseInfo { MONGO_DECLARE_JS_FUNCTION(isReplicaSetMember); MONGO_DECLARE_JS_FUNCTION(isMongos); MONGO_DECLARE_JS_FUNCTION(getClusterTime); - MONGO_DECLARE_JS_FUNCTION(setClusterTime); + MONGO_DECLARE_JS_FUNCTION(advanceClusterTime); + MONGO_DECLARE_JS_FUNCTION(resetClusterTime_forTesting); MONGO_DECLARE_JS_FUNCTION(_startSession); }; - static const JSFunctionSpec methods[24]; + static const JSFunctionSpec methods[25]; static const char* const className; static const unsigned classFlags = JSCLASS_HAS_PRIVATE; static BSONObj getClusterTime(); - static void setClusterTime(const BSONObj& newTime); + static void advanceClusterTime(const BSONObj& newTime); + static void resetClusterTime_forTesting(); }; /** |