From 9ba3877df2a0734fbf2148c7c16ca18bdf7d4bfb Mon Sep 17 00:00:00 2001 From: Kaloian Manassiev Date: Fri, 2 Oct 2015 17:53:00 -0400 Subject: SERVER-19934 waitForWriteConcern should take write concern parameter That way sub-operations, which need to wait on a specific write concern, which might be different than the one of the entire operation don't need to change the OperationContext. --- src/mongo/db/commands/find_and_modify.cpp | 7 +++++-- src/mongo/db/commands/get_last_error.cpp | 2 +- src/mongo/db/commands/write_commands/batch_executor.cpp | 7 +++++-- src/mongo/db/write_concern.cpp | 3 +-- src/mongo/db/write_concern.h | 1 + src/mongo/db/write_concern_options.cpp | 10 +++++++++- src/mongo/db/write_concern_options.h | 2 ++ 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index ff11de903ba..78b367a39ea 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -491,8 +491,11 @@ public: } WriteConcernResult res; - auto waitForWCStatus = waitForWriteConcern( - txn, repl::ReplClientInfo::forClient(txn->getClient()).getLastOp(), &res); + auto waitForWCStatus = + waitForWriteConcern(txn, + repl::ReplClientInfo::forClient(txn->getClient()).getLastOp(), + txn->getWriteConcern(), + &res); appendCommandWCStatus(result, waitForWCStatus); return true; diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index c7480b57c6b..e6955f1700b 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -271,7 +271,7 @@ public: } WriteConcernResult wcResult; - status = waitForWriteConcern(txn, lastOpTime, &wcResult); + status = waitForWriteConcern(txn, lastOpTime, txn->getWriteConcern(), &wcResult); wcResult.appendTo(writeConcern, &result); // For backward compatibility with 2.4, wtimeout returns ok : 1.0 diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index bedc9c8f4bf..4f877885969 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -332,8 +332,11 @@ void WriteBatchExecutor::executeBatch(const BatchedCommandRequest& request, } WriteConcernResult res; - Status status = waitForWriteConcern( - _txn, repl::ReplClientInfo::forClient(_txn->getClient()).getLastOp(), &res); + Status status = + waitForWriteConcern(_txn, + repl::ReplClientInfo::forClient(_txn->getClient()).getLastOp(), + _txn->getWriteConcern(), + &res); if (!status.isOK()) { wcError.reset(toWriteConcernError(status, res)); diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index 7ce188de192..f035b3f5bfd 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -203,9 +203,8 @@ void WriteConcernResult::appendTo(const WriteConcernOptions& writeConcern, Status waitForWriteConcern(OperationContext* txn, const OpTime& replOpTime, + const WriteConcernOptions& writeConcern, WriteConcernResult* result) { - const WriteConcernOptions& writeConcern = txn->getWriteConcern(); - // We assume all options have been validated earlier, if not, programming error dassert(validateWriteConcern(writeConcern).isOK()); diff --git a/src/mongo/db/write_concern.h b/src/mongo/db/write_concern.h index 31e2bc6c588..72bdfb4d986 100644 --- a/src/mongo/db/write_concern.h +++ b/src/mongo/db/write_concern.h @@ -100,6 +100,7 @@ struct WriteConcernResult { */ Status waitForWriteConcern(OperationContext* txn, const repl::OpTime& replOpTime, + const WriteConcernOptions& writeConcern, WriteConcernResult* result); diff --git a/src/mongo/db/write_concern_options.cpp b/src/mongo/db/write_concern_options.cpp index 5fba6321b5e..e24f652517d 100644 --- a/src/mongo/db/write_concern_options.cpp +++ b/src/mongo/db/write_concern_options.cpp @@ -25,6 +25,8 @@ * it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/db/write_concern_options.h" #include "mongo/base/status.h" @@ -64,6 +66,11 @@ WriteConcernOptions::WriteConcernOptions(int numNodes, SyncMode sync, int timeou WriteConcernOptions::WriteConcernOptions(const std::string& mode, SyncMode sync, int timeout) : syncMode(sync), wNumNodes(0), wMode(mode), wTimeout(timeout) {} +WriteConcernOptions::WriteConcernOptions(const std::string& mode, + SyncMode sync, + Milliseconds timeout) + : syncMode(sync), wNumNodes(0), wMode(mode), wTimeout(durationCount(timeout)) {} + Status WriteConcernOptions::parse(const BSONObj& obj) { if (obj.isEmpty()) { return Status(ErrorCodes::FailedToParse, "write concern object cannot be empty"); @@ -179,4 +186,5 @@ BSONObj WriteConcernOptions::toBSON() const { bool WriteConcernOptions::shouldWaitForOtherNodes() const { return !wMode.empty() || wNumNodes > 1; } -} + +} // namespace mongo diff --git a/src/mongo/db/write_concern_options.h b/src/mongo/db/write_concern_options.h index 217e864a2cf..a0cb45f8da9 100644 --- a/src/mongo/db/write_concern_options.h +++ b/src/mongo/db/write_concern_options.h @@ -57,6 +57,8 @@ public: WriteConcernOptions(const std::string& mode, SyncMode sync, int timeout); + WriteConcernOptions(const std::string& mode, SyncMode sync, Milliseconds timeout); + Status parse(const BSONObj& obj); /** -- cgit v1.2.1