summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2016-05-06 18:10:19 -0400
committerMathias Stearn <mathias@10gen.com>2016-05-09 17:52:12 -0400
commit3555c1363e02c64511d8826a57289275c13491c0 (patch)
treed789b1aeca9c546936b77928e1763ec84d252b31
parent26586d84484c16f3d5aa7ab4cad87552e4b8bc5f (diff)
downloadmongo-3555c1363e02c64511d8826a57289275c13491c0.tar.gz
SERVER-20224 Now only the command processor calls txn->setWriteConcern()
It also restores the original writeConcern when it is done.
-rw-r--r--src/mongo/db/commands/get_last_error.cpp3
-rw-r--r--src/mongo/db/commands/mr.cpp16
-rw-r--r--src/mongo/db/commands/pipeline_command.cpp6
-rw-r--r--src/mongo/db/commands/user_management_commands.cpp16
-rw-r--r--src/mongo/db/dbcommands.cpp26
-rw-r--r--src/mongo/db/ops/write_ops_exec.cpp5
-rw-r--r--src/mongo/s/s_only.cpp15
7 files changed, 27 insertions, 60 deletions
diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp
index 19d262e4df5..7af1a83aafa 100644
--- a/src/mongo/db/commands/get_last_error.cpp
+++ b/src/mongo/db/commands/get_last_error.cpp
@@ -262,14 +262,13 @@ public:
}
}
- txn->setWriteConcern(writeConcern);
{
stdx::lock_guard<Client> lk(*txn->getClient());
txn->setMessage_inlock("waiting for write concern");
}
WriteConcernResult wcResult;
- status = waitForWriteConcern(txn, lastOpTime, txn->getWriteConcern(), &wcResult);
+ status = waitForWriteConcern(txn, lastOpTime, writeConcern, &wcResult);
wcResult.appendTo(writeConcern, &result);
// For backward compatibility with 2.4, wtimeout returns ok : 1.0
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 3f0b2643af8..56bd3f7fcf2 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -616,7 +616,7 @@ long long State::postProcessCollectionNonAtomic(OperationContext* txn,
ScopedTransaction transaction(txn, MODE_X);
Lock::GlobalWrite lock(txn->lockState()); // TODO(erh): why global???
// replace: just rename from temp to final collection name, dropping previous collection
- _db.dropCollection(_config.outputOptions.finalNamespace, txn->getWriteConcern());
+ _db.dropCollection(_config.outputOptions.finalNamespace);
BSONObj info;
if (!_db.runCommand("admin",
@@ -627,7 +627,7 @@ long long State::postProcessCollectionNonAtomic(OperationContext* txn,
uasserted(10076, str::stream() << "rename failed: " << info);
}
- _db.dropCollection(_config.tempNamespace, txn->getWriteConcern());
+ _db.dropCollection(_config.tempNamespace);
} else if (_config.outputOptions.outType == Config::MERGE) {
// merge: upsert new docs into old collection
{
@@ -646,7 +646,7 @@ long long State::postProcessCollectionNonAtomic(OperationContext* txn,
Helpers::upsert(_txn, _config.outputOptions.finalNamespace, o);
pm.hit();
}
- _db.dropCollection(_config.tempNamespace, txn->getWriteConcern());
+ _db.dropCollection(_config.tempNamespace);
pm.finished();
} else if (_config.outputOptions.outType == Config::REDUCE) {
// reduce: apply reduce op on new result and existing one
@@ -1325,11 +1325,6 @@ public:
BSONObjBuilder& result) {
Timer t;
- // Save and reset the write concern so that it doesn't get changed accidentally by
- // DBDirectClient.
- auto oldWC = txn->getWriteConcern();
- ON_BLOCK_EXIT([txn, oldWC] { txn->setWriteConcern(oldWC); });
-
boost::optional<DisableDocumentValidation> maybeDisableValidation;
if (shouldBypassDocumentValidationForCommand(cmd))
maybeDisableValidation.emplace(txn);
@@ -1655,11 +1650,6 @@ public:
<< dbname));
}
- // Save and reset the write concern so that it doesn't get changed accidentally by
- // DBDirectClient.
- auto oldWC = txn->getWriteConcern();
- ON_BLOCK_EXIT([txn, oldWC] { txn->setWriteConcern(oldWC); });
-
boost::optional<DisableDocumentValidation> maybeDisableValidation;
if (shouldBypassDocumentValidationForCommand(cmdObj))
maybeDisableValidation.emplace(txn);
diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp
index 6f63dd9fbd4..4eb8444951f 100644
--- a/src/mongo/db/commands/pipeline_command.cpp
+++ b/src/mongo/db/commands/pipeline_command.cpp
@@ -54,7 +54,6 @@
#include "mongo/db/query/plan_summary_stats.h"
#include "mongo/db/storage/storage_options.h"
#include "mongo/stdx/memory.h"
-#include "mongo/util/scopeguard.h"
namespace mongo {
@@ -204,11 +203,6 @@ public:
if (!pPipeline.get())
return false;
- // Save and reset the write concern so that it doesn't get changed accidentally by
- // DBDirectClient.
- auto oldWC = txn->getWriteConcern();
- ON_BLOCK_EXIT([txn, oldWC] { txn->setWriteConcern(oldWC); });
-
// This is outside of the if block to keep the object alive until the pipeline is finished.
BSONObj parsed;
if (kDebugBuild && !pPipeline->isExplain() && !pCtx->inShard) {
diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp
index 68c5d862081..696339496eb 100644
--- a/src/mongo/db/commands/user_management_commands.cpp
+++ b/src/mongo/db/commands/user_management_commands.cpp
@@ -73,7 +73,6 @@
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/net/ssl_manager.h"
-#include "mongo/util/scopeguard.h"
#include "mongo/util/sequence_util.h"
#include "mongo/util/time_support.h"
@@ -265,11 +264,6 @@ Status queryAuthzDocument(OperationContext* txn,
Status insertAuthzDocument(OperationContext* txn,
const NamespaceString& collectionName,
const BSONObj& document) {
- // Save and reset the write concern so that it doesn't get changed accidentally by
- // DBDirectClient.
- auto oldWC = txn->getWriteConcern();
- ON_BLOCK_EXIT([txn, oldWC] { txn->setWriteConcern(oldWC); });
-
try {
DBDirectClient client(txn);
@@ -304,11 +298,6 @@ Status updateAuthzDocuments(OperationContext* txn,
bool upsert,
bool multi,
long long* nMatched) {
- // Save and reset the write concern so that it doesn't get changed accidentally by
- // DBDirectClient.
- auto oldWC = txn->getWriteConcern();
- ON_BLOCK_EXIT([txn, oldWC] { txn->setWriteConcern(oldWC); });
-
try {
DBDirectClient client(txn);
@@ -379,11 +368,6 @@ Status removeAuthzDocuments(OperationContext* txn,
const NamespaceString& collectionName,
const BSONObj& query,
long long* numRemoved) {
- // Save and reset the write concern so that it doesn't get changed accidentally by
- // DBDirectClient.
- auto oldWC = txn->getWriteConcern();
- ON_BLOCK_EXIT([txn, oldWC] { txn->setWriteConcern(oldWC); });
-
try {
DBDirectClient client(txn);
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index b1fbd59940c..cefb565eac0 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -1540,28 +1540,26 @@ bool Command::run(OperationContext* txn,
return result;
}
- if (this->supportsWriteConcern(cmd)) {
+ bool result;
+ if (!this->supportsWriteConcern(cmd)) {
+ // TODO: remove queryOptions parameter from command's run method.
+ result = this->run(txn, db, cmd, 0, errmsg, inPlaceReplyBob);
+ } else {
+ // Change the write concern while running the command.
+ const auto oldWC = txn->getWriteConcern();
+ ON_BLOCK_EXIT([&] { txn->setWriteConcern(oldWC); });
txn->setWriteConcern(wcResult.getValue());
- }
- // TODO: remove queryOptions parameter from command's run method.
- bool result = this->run(txn, db, cmd, 0, errmsg, inPlaceReplyBob);
+ result = this->run(txn, db, cmd, 0, errmsg, inPlaceReplyBob);
- if (this->supportsWriteConcern(cmd)) {
- if (shouldLog(logger::LogSeverity::Debug(1))) {
- BSONObj oldWC = wcResult.getValue().toBSON();
- BSONObj newWC = txn->getWriteConcern().toBSON();
- if (oldWC != newWC) {
- LOG(1) << "Provided writeConcern was overridden from " << oldWC << " to " << newWC
- << " for command " << cmd;
- }
- }
+ // Nothing in run() should change the writeConcern.
+ dassert(txn->getWriteConcern().toBSON() == wcResult.getValue().toBSON());
WriteConcernResult res;
auto waitForWCStatus =
waitForWriteConcern(txn,
repl::ReplClientInfo::forClient(txn->getClient()).getLastOp(),
- txn->getWriteConcern(),
+ wcResult.getValue(),
&res);
appendCommandWCStatus(inPlaceReplyBob, waitForWCStatus, res);
diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp
index 9f29bd1f65d..72366ef131e 100644
--- a/src/mongo/db/ops/write_ops_exec.cpp
+++ b/src/mongo/db/ops/write_ops_exec.cpp
@@ -276,11 +276,6 @@ static WriteResult performCreateIndexes(OperationContext* txn, const InsertOp& w
// seem worth it since users that want faster index builds should just use the createIndexes
// command rather than a legacy emulation.
LastOpFixer lastOpFixer(txn, wholeOp.ns);
-
- // Creating an index can change the writeConcern. Make sure we set it back to what it was.
- const auto oldWC = txn->getWriteConcern();
- ON_BLOCK_EXIT([&] { txn->setWriteConcern(oldWC); });
-
WriteResult out;
for (auto&& spec : wholeOp.documents) {
try {
diff --git a/src/mongo/s/s_only.cpp b/src/mongo/s/s_only.cpp
index 1cecb1aba3d..8d63a0cb05b 100644
--- a/src/mongo/s/s_only.cpp
+++ b/src/mongo/s/s_only.cpp
@@ -48,6 +48,7 @@
#include "mongo/util/assert_util.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/log.h"
+#include "mongo/util/scopeguard.h"
namespace mongo {
@@ -139,14 +140,20 @@ void Command::execCommandClientBasic(OperationContext* txn,
return;
}
- if (supportsWriteConcern) {
- txn->setWriteConcern(wcResult.getValue());
- }
std::string errmsg;
bool ok = false;
try {
- ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
+ if (!supportsWriteConcern) {
+ ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
+ } else {
+ // Change the write concern while running the command.
+ const auto oldWC = txn->getWriteConcern();
+ ON_BLOCK_EXIT([&] { txn->setWriteConcern(oldWC); });
+ txn->setWriteConcern(wcResult.getValue());
+
+ ok = c->run(txn, dbname, cmdObj, queryOptions, errmsg, result);
+ }
} catch (const DBException& e) {
result.resetToEmpty();
const int code = e.getCode();