summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/storage_interface_impl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/storage_interface_impl.cpp')
-rw-r--r--src/mongo/db/repl/storage_interface_impl.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp
index 88f4e2f36c7..ff17b6c7175 100644
--- a/src/mongo/db/repl/storage_interface_impl.cpp
+++ b/src/mongo/db/repl/storage_interface_impl.cpp
@@ -49,6 +49,7 @@
#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/document_validation.h"
+#include "mongo/db/catalog/drop_collection.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/client.h"
#include "mongo/db/concurrency/d_concurrency.h"
@@ -459,18 +460,23 @@ Status StorageInterfaceImpl::createCollection(OperationContext* opCtx,
Status StorageInterfaceImpl::dropCollection(OperationContext* opCtx, const NamespaceString& nss) {
return writeConflictRetry(opCtx, "StorageInterfaceImpl::dropCollection", nss.ns(), [&] {
- AutoGetDb autoDb(opCtx, nss.db(), MODE_IX);
- Lock::CollectionLock collLock(opCtx, nss, MODE_X);
- if (!autoDb.getDb()) {
- // Database does not exist - nothing to do.
- return Status::OK();
- }
- WriteUnitOfWork wunit(opCtx);
- const auto status = autoDb.getDb()->dropCollectionEvenIfSystem(opCtx, nss);
- if (!status.isOK()) {
- return status;
+ {
+ AutoGetDb autoDb(opCtx, nss.db(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, nss, MODE_X);
+ if (!autoDb.getDb()) {
+ // Database does not exist - nothing to do.
+ return Status::OK();
+ }
+ WriteUnitOfWork wunit(opCtx);
+ const auto status = autoDb.getDb()->dropCollectionEvenIfSystem(opCtx, nss);
+ if (!status.isOK()) {
+ return status;
+ }
+ wunit.commit();
}
- wunit.commit();
+
+ // If this dropped the last collection in the database, we should close the database.
+ closeDatabaseIfEmpty(opCtx, nss.db());
return Status::OK();
});
}