diff options
author | Scott Hernandez <scotthernandez@gmail.com> | 2015-01-03 21:34:48 -0500 |
---|---|---|
committer | Scott Hernandez <scotthernandez@gmail.com> | 2015-01-05 11:31:40 -0500 |
commit | 3753b0810391b237b543fdc16705d7ba90add3ce (patch) | |
tree | 2ff7ac75bbda879d90bb7c6a9bb189eb40f232c0 /src/mongo/db/commands/compact.cpp | |
parent | 89d03890991e173d0b773dfe98d7bfb944bc5205 (diff) | |
download | mongo-3753b0810391b237b543fdc16705d7ba90add3ce.tar.gz |
SERVER-16711: do not create db for compact if missing db/collection
Diffstat (limited to 'src/mongo/db/commands/compact.cpp')
-rw-r--r-- | src/mongo/db/commands/compact.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index 023370dd172..78af3ed4150 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -145,16 +145,19 @@ namespace mongo { ScopedTransaction transaction(txn, MODE_IX); - Lock::DBLock lk(txn->lockState(), db, MODE_X); - BackgroundOperation::assertNoBgOpInProgForNs(ns.ns()); - Client::Context ctx(txn, ns); + AutoGetDb autoDb(txn, db, MODE_X); + Database* const collDB = autoDb.getDb(); + Collection* collection = collDB ? collDB->getCollection(ns) : NULL; - Collection* collection = ctx.db()->getCollection(ns.ns()); - if( ! collection ) { + // If db/collection does not exist, short circuit and return. + if ( !collDB || !collection ) { errmsg = "namespace does not exist"; return false; } + Client::Context ctx(txn, ns); + BackgroundOperation::assertNoBgOpInProgForNs(ns.ns()); + if ( collection->isCapped() ) { errmsg = "cannot compact a capped collection"; return false; @@ -162,7 +165,7 @@ namespace mongo { log() << "compact " << ns << " begin, options: " << compactOptions.toString(); - std::vector<BSONObj> indexesInProg = stopIndexBuilds(txn, ctx.db(), cmdObj); + std::vector<BSONObj> indexesInProg = stopIndexBuilds(txn, collDB, cmdObj); StatusWith<CompactStats> status = collection->compact( txn, &compactOptions ); if ( !status.isOK() ) |