diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2020-09-17 17:09:19 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-26 02:12:49 +0000 |
commit | 2b82ab88982566114d1bb7667477b71c883b0799 (patch) | |
tree | c152b35ff047fdc42f69aa6cd6b04fee1d811fe4 /src/mongo/db/catalog/drop_collection.cpp | |
parent | 08e92a678a1ed288f6a95e7950597e082556ae59 (diff) | |
download | mongo-2b82ab88982566114d1bb7667477b71c883b0799.tar.gz |
SERVER-50984 Add CollectionPtr to replace usage of const Collection*
It implements a yieldable interface that is used to re-load the
Collection pointer from the catalog after a yield that released locks.
With lock-free reads and copy-on-write on Collection instances releasing
locks without notifying an AutoGetCollection at a higher level may cause
its pointers to dangle if a MODE_X writer installs a new Collection
instance in the catalog.
CollectionPtr should be passed by const reference so a yield can notify
all the way up.
Diffstat (limited to 'src/mongo/db/catalog/drop_collection.cpp')
-rw-r--r-- | src/mongo/db/catalog/drop_collection.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 3ed987e475f..99826f3082a 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -53,7 +53,7 @@ namespace mongo { MONGO_FAIL_POINT_DEFINE(hangDropCollectionBeforeLockAcquisition); MONGO_FAIL_POINT_DEFINE(hangDuringDropCollection); -Status _checkNssAndReplState(OperationContext* opCtx, const Collection* coll) { +Status _checkNssAndReplState(OperationContext* opCtx, const CollectionPtr& coll) { if (!coll) { return Status(ErrorCodes::NamespaceNotFound, "ns not found"); } @@ -134,7 +134,7 @@ Status _abortIndexBuildsAndDropCollection(OperationContext* opCtx, // which may have changed when we released the collection lock temporarily. opCtx->recoveryUnit()->abandonSnapshot(); - const Collection* coll = + const CollectionPtr& coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, startingNss); Status status = _checkNssAndReplState(opCtx, coll); if (!status.isOK()) { @@ -185,7 +185,7 @@ Status _abortIndexBuildsAndDropCollection(OperationContext* opCtx, // disk state, which may have changed when we released the collection lock temporarily. opCtx->recoveryUnit()->abandonSnapshot(); - const Collection* coll = + const CollectionPtr& coll = CollectionCatalog::get(opCtx).lookupCollectionByUUID(opCtx, collectionUUID); status = _checkNssAndReplState(opCtx, coll); if (!status.isOK()) { @@ -237,7 +237,7 @@ Status _dropCollection(OperationContext* opCtx, DropCollectionSystemCollectionMode systemCollectionMode, BSONObjBuilder& result) { Lock::CollectionLock collLock(opCtx, collectionName, MODE_X); - const Collection* coll = + const CollectionPtr& coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, collectionName); Status status = _checkNssAndReplState(opCtx, coll); if (!status.isOK()) { @@ -300,8 +300,9 @@ Status dropCollection(OperationContext* opCtx, return Status(ErrorCodes::NamespaceNotFound, "ns not found"); } - const Collection* coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace( - opCtx, collectionName); + const CollectionPtr& coll = + CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, + collectionName); if (!coll) { return _dropView(opCtx, db, collectionName, result); @@ -337,7 +338,7 @@ Status dropCollectionForApplyOps(OperationContext* opCtx, return Status(ErrorCodes::NamespaceNotFound, "ns not found"); } - const Collection* coll = + const CollectionPtr& coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, collectionName); BSONObjBuilder unusedBuilder; |