summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2014-04-28 06:38:03 -0400
committerDan Pasette <dan@mongodb.com>2014-05-15 19:25:28 -0400
commit0661a4fa335f200b07c2a6afa6e5d0922bae60d6 (patch)
tree2431d3ed19de86a2b361b27245660812f596256d
parent5f50fe901bdd34c5c539c612e22b30f339e57e81 (diff)
downloadmongo-0661a4fa335f200b07c2a6afa6e5d0922bae60d6.tar.gz
SERVER-13750 prevent invariant failure when ConvertToCappeding a nonexistent collection
(cherry picked from commit ff276366a823fdbd73be5594244b4bdb4e63e1a0)
-rw-r--r--jstests/core/convert_to_capped_nonexistant.js9
-rw-r--r--src/mongo/db/commands/collection_to_capped.cpp10
2 files changed, 16 insertions, 3 deletions
diff --git a/jstests/core/convert_to_capped_nonexistant.js b/jstests/core/convert_to_capped_nonexistant.js
new file mode 100644
index 00000000000..6a9a8b8ce3d
--- /dev/null
+++ b/jstests/core/convert_to_capped_nonexistant.js
@@ -0,0 +1,9 @@
+// This test ensures that ConvertToCapped()ing a nonexistent collection will not cause the server to
+// abort (SERVER-13750)
+
+var testDb = db.getSiblingDB("convert_to_capped_nonexistent");
+testDb.dropDatabase();
+var result = testDb.runCommand({convertToCapped: 'foo', size: 1024});
+assert.eq(result.ok, 0, "converting a nonexistent to capped worked and should not have");
+assert.eq(result.errmsg, "source collection convert_to_capped_nonexistent.foo does not exist",
+ "converting a nonexistent to capped failed but for the wrong reason");
diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp
index c4e1f32a6a3..8a21db08ada 100644
--- a/src/mongo/db/commands/collection_to_capped.cpp
+++ b/src/mongo/db/commands/collection_to_capped.cpp
@@ -201,12 +201,16 @@ namespace mongo {
virtual std::vector<BSONObj> stopIndexBuilds(Database* db,
const BSONObj& cmdObj) {
- std::string coll = cmdObj.firstElement().valuestr();
- std::string ns = db->name() + "." + coll;
+ std::string collName = cmdObj.firstElement().valuestr();
+ std::string ns = db->name() + "." + collName;
IndexCatalog::IndexKillCriteria criteria;
criteria.ns = ns;
- return IndexBuilder::killMatchingIndexBuilds(db->getCollection(ns), criteria);
+ Collection* coll = db->getCollection(ns);
+ if (coll) {
+ return IndexBuilder::killMatchingIndexBuilds(coll, criteria);
+ }
+ return std::vector<BSONObj>();
}
bool run(const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {