summaryrefslogtreecommitdiff
path: root/src/mongo/db/dbcommands.cpp
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2016-04-12 19:11:23 -0400
committerJudah Schvimer <judah@mongodb.com>2016-04-12 19:11:23 -0400
commit7ed530a55304bd9cc2b80c054f379b10d9cea8e2 (patch)
treeff1dac44961da031f3369f0288fb38a347d0d690 /src/mongo/db/dbcommands.cpp
parentb0c0acc6767a74ed2e5aa50361ad4474291951f9 (diff)
downloadmongo-7ed530a55304bd9cc2b80c054f379b10d9cea8e2.tar.gz
SERVER-20224 commands that write support writeConcern
Diffstat (limited to 'src/mongo/db/dbcommands.cpp')
-rw-r--r--src/mongo/db/dbcommands.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index 1516a27989a..94e9c05c80e 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -180,6 +180,10 @@ public:
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return true;
+ }
+
CmdDropDatabase() : Command("dropDatabase") {}
bool run(OperationContext* txn,
@@ -236,6 +240,10 @@ public:
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
+
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
std::vector<Privilege>* out) {
@@ -309,6 +317,10 @@ public:
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
+
virtual Status checkAuthForCommand(ClientBasic* client,
const std::string& dbname,
const BSONObj& cmdObj) {
@@ -398,6 +410,10 @@ public:
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
+
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
std::vector<Privilege>* out) {
@@ -462,6 +478,10 @@ public:
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return true;
+ }
+
virtual bool run(OperationContext* txn,
const string& dbname,
BSONObj& cmdObj,
@@ -499,6 +519,10 @@ public:
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return true;
+ }
+
virtual void help(stringstream& help) const {
help << "create a collection explicitly\n"
"{ create: <ns>[, capped: <bool>, size: <collSizeInBytes>, max: <nDocs>] }";
@@ -554,6 +578,10 @@ public:
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
+
virtual std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const {
std::string collectionName = cmdObj.getStringField("root");
if (collectionName.empty())
@@ -724,6 +752,9 @@ public:
virtual bool slaveOk() const {
return true;
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
virtual void help(stringstream& help) const {
help << "determine data size for a set of data in a certain range"
"\nexample: { dataSize:\"blog.posts\", keyPattern:{x:1}, min:{x:10}, max:{x:55} }"
@@ -869,6 +900,9 @@ public:
virtual bool slaveOk() const {
return true;
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
virtual void help(stringstream& help) const {
help
<< "{ collStats:\"blog.posts\" , scale : 1 } scale divides sizes e.g. for KB use 1024\n"
@@ -976,6 +1010,9 @@ public:
virtual bool slaveOk() const {
return false;
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return true;
+ }
virtual void help(stringstream& help) const {
help << "Sets collection options.\n"
"Example: { collMod: 'foo', usePowerOf2Sizes:true }\n"
@@ -1009,6 +1046,9 @@ public:
virtual bool slaveOk() const {
return true;
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
virtual void help(stringstream& help) const {
help << "Get stats on a database. Not instantaneous. Slower for databases with large "
".ns files.\n"
@@ -1096,6 +1136,9 @@ public:
virtual bool slaveOk() const {
return true;
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
virtual void help(stringstream& help) const {
help << "{whatsmyuri:1}";
}
@@ -1120,6 +1163,9 @@ public:
virtual bool slaveOk() const {
return true;
}
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
virtual Status checkAuthForCommand(ClientBasic* client,
const std::string& dbname,
const BSONObj& cmdObj) {
@@ -1459,8 +1505,41 @@ bool Command::run(OperationContext* txn,
// run expects const db std::string (can't bind to temporary)
const std::string db = request.getDatabase().toString();
+ StatusWith<WriteConcernOptions> wcResult =
+ extractWriteConcern(txn, cmd, db, this->supportsWriteConcern(cmd));
+ if (!wcResult.isOK()) {
+ auto result = appendCommandStatus(inPlaceReplyBob, wcResult.getStatus());
+ inPlaceReplyBob.doneFast();
+ replyBuilder->setMetadata(rpc::makeEmptyMetadata());
+ return result;
+ }
+
+ if (this->supportsWriteConcern(cmd)) {
+ txn->setWriteConcern(wcResult.getValue());
+ }
+
// TODO: remove queryOptions parameter from command's run method.
bool 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;
+ }
+ }
+
+ WriteConcernResult res;
+ auto waitForWCStatus =
+ waitForWriteConcern(txn,
+ repl::ReplClientInfo::forClient(txn->getClient()).getLastOp(),
+ txn->getWriteConcern(),
+ &res);
+ appendCommandWCStatus(inPlaceReplyBob, waitForWCStatus, res);
+ }
+
appendCommandStatus(inPlaceReplyBob, result, errmsg);
inPlaceReplyBob.doneFast();