diff options
Diffstat (limited to 'src/mongo/db/catalog/drop_collection.cpp')
-rw-r--r-- | src/mongo/db/catalog/drop_collection.cpp | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index cb932432dab..67bfb70ae45 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -48,54 +48,55 @@ #include "mongo/util/log.h" namespace mongo { - Status dropCollection(OperationContext* txn, - const NamespaceString& collectionName, - BSONObjBuilder& result) { - if (!serverGlobalParams.quiet) { - log() << "CMD: drop " << collectionName; - } +Status dropCollection(OperationContext* txn, + const NamespaceString& collectionName, + BSONObjBuilder& result) { + if (!serverGlobalParams.quiet) { + log() << "CMD: drop " << collectionName; + } - std::string dbname = collectionName.db().toString(); + std::string dbname = collectionName.db().toString(); - MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { - ScopedTransaction transaction(txn, MODE_IX); + MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { + ScopedTransaction transaction(txn, MODE_IX); - AutoGetDb autoDb(txn, dbname, MODE_X); - Database* const db = autoDb.getDb(); - Collection* coll = db ? db->getCollection(collectionName) : nullptr; + AutoGetDb autoDb(txn, dbname, MODE_X); + Database* const db = autoDb.getDb(); + Collection* coll = db ? db->getCollection(collectionName) : nullptr; - // If db/collection does not exist, short circuit and return. - if ( !db || !coll ) { - return Status(ErrorCodes::NamespaceNotFound, "ns not found"); - } - OldClientContext context(txn, collectionName); + // If db/collection does not exist, short circuit and return. + if (!db || !coll) { + return Status(ErrorCodes::NamespaceNotFound, "ns not found"); + } + OldClientContext context(txn, collectionName); - bool userInitiatedWritesAndNotPrimary = txn->writesAreReplicated() && - !repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(collectionName); + bool userInitiatedWritesAndNotPrimary = txn->writesAreReplicated() && + !repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(collectionName); - if (userInitiatedWritesAndNotPrimary) { - return Status(ErrorCodes::NotMaster, - str::stream() << "Not primary while dropping collection " - << collectionName.ns()); - } + if (userInitiatedWritesAndNotPrimary) { + return Status(ErrorCodes::NotMaster, + str::stream() << "Not primary while dropping collection " + << collectionName.ns()); + } - int numIndexes = coll->getIndexCatalog()->numIndexesTotal(txn); + int numIndexes = coll->getIndexCatalog()->numIndexesTotal(txn); - BackgroundOperation::assertNoBgOpInProgForNs(collectionName.ns()); + BackgroundOperation::assertNoBgOpInProgForNs(collectionName.ns()); - WriteUnitOfWork wunit(txn); - Status s = db->dropCollection(txn, collectionName.ns()); + WriteUnitOfWork wunit(txn); + Status s = db->dropCollection(txn, collectionName.ns()); - result.append("ns", collectionName); + result.append("ns", collectionName); - if ( !s.isOK() ) { - return s; - } + if (!s.isOK()) { + return s; + } - result.append("nIndexesWas", numIndexes); + result.append("nIndexesWas", numIndexes); - wunit.commit(); - } MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "drop", collectionName.ns()); - return Status::OK(); + wunit.commit(); } -} // namespace mongo + MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "drop", collectionName.ns()); + return Status::OK(); +} +} // namespace mongo |