summaryrefslogtreecommitdiff
path: root/src/mongo/db/write_concern.cpp
diff options
context:
space:
mode:
authorDaniel Alabi <alabidan@gmail.com>2015-03-16 13:11:40 -0400
committerDaniel Alabi <alabidan@gmail.com>2015-03-16 13:27:16 -0400
commitbb9b4e27c8c31542af52d80f4c3751c435909d69 (patch)
treefd06e28b14d194b27cfbe4753572337bc9d91d40 /src/mongo/db/write_concern.cpp
parente89ad4970c81ce122867e6af70d09cd164052022 (diff)
downloadmongo-bb9b4e27c8c31542af52d80f4c3751c435909d69.tar.gz
SERVER-6558 Add writeConcern option to findAndModify command
Diffstat (limited to 'src/mongo/db/write_concern.cpp')
-rw-r--r--src/mongo/db/write_concern.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp
index 97db25a5c5b..db55f59e220 100644
--- a/src/mongo/db/write_concern.cpp
+++ b/src/mongo/db/write_concern.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/write_concern.h"
#include "mongo/base/counter.h"
+#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/commands/server_status_metric.h"
#include "mongo/db/global_environment_experiment.h"
#include "mongo/db/operation_context.h"
@@ -52,6 +53,41 @@ namespace mongo {
static ServerStatusMetricField<Counter64> gleWtimeoutsDisplay("getLastError.wtimeouts",
&gleWtimeouts );
+ void setupSynchronousCommit(const WriteConcernOptions& writeConcern,
+ OperationContext* txn) {
+ if ( writeConcern.syncMode == WriteConcernOptions::JOURNAL ||
+ writeConcern.syncMode == WriteConcernOptions::FSYNC ) {
+ txn->recoveryUnit()->goingToAwaitCommit();
+ }
+ }
+
+ StatusWith<WriteConcernOptions> extractWriteConcern(const BSONObj& cmdObj) {
+ BSONElement writeConcernElement;
+ Status wcStatus = bsonExtractTypedField(cmdObj,
+ "writeConcern",
+ Object,
+ &writeConcernElement);
+
+ if (!wcStatus.isOK()) {
+ if (wcStatus == ErrorCodes::NoSuchKey) {
+ return repl::getGlobalReplicationCoordinator()->getGetLastErrorDefault();
+ }
+ return wcStatus;
+ }
+
+ WriteConcernOptions writeConcern;
+ wcStatus = writeConcern.parse(writeConcernElement.Obj());
+
+ if (wcStatus.isOK()) {
+ wcStatus = validateWriteConcern(writeConcern);
+ }
+ if (!wcStatus.isOK()) {
+ return wcStatus;
+ }
+
+ return writeConcern;
+ }
+
Status validateWriteConcern( const WriteConcernOptions& writeConcern ) {
const bool isJournalEnabled = getGlobalEnvironment()->getGlobalStorageEngine()->isDurable();