diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2020-07-31 15:26:11 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-07 13:32:12 +0000 |
commit | 9de175fb3776415e7237e6c0af4b76f518adc451 (patch) | |
tree | 56a22e0f57be9937d53deed8f76fdbc2502639c3 /src/mongo/db/dbhelpers.cpp | |
parent | 21d5a8e5bd822e71e5fb8feb2f9e71a7e8cf25f9 (diff) | |
download | mongo-9de175fb3776415e7237e6c0af4b76f518adc451.tar.gz |
SERVER-47885 Added lookupCollectionByXXXForRead interface to the Collection catalog that returns collection as shared_ptr<const Collection>
AutoGetCollectionForRead and AutoGetCollectionForReadCommand now uses this and holds the shared_ptr. They return the collection as const.
Const correct various places to make this possible.
Moved some logic from Collection destructors to deregister from the catalog as they may now be destroyed at a later point.
Diffstat (limited to 'src/mongo/db/dbhelpers.cpp')
-rw-r--r-- | src/mongo/db/dbhelpers.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index f6c1c27b4d6..bf19f4bd8bf 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -61,7 +61,7 @@ using std::unique_ptr; set your db SavedContext first */ bool Helpers::findOne(OperationContext* opCtx, - Collection* collection, + const Collection* collection, const BSONObj& query, BSONObj& result, bool requireIndex) { @@ -76,7 +76,7 @@ bool Helpers::findOne(OperationContext* opCtx, set your db SavedContext first */ RecordId Helpers::findOne(OperationContext* opCtx, - Collection* collection, + const Collection* collection, const BSONObj& query, bool requireIndex) { if (!collection) @@ -88,7 +88,7 @@ RecordId Helpers::findOne(OperationContext* opCtx, } RecordId Helpers::findOne(OperationContext* opCtx, - Collection* collection, + const Collection* collection, std::unique_ptr<QueryRequest> qr, bool requireIndex) { if (!collection) @@ -129,6 +129,7 @@ bool Helpers::findById(OperationContext* opCtx, bool* indexFound) { invariant(database); + // TODO ForRead? Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, NamespaceString(ns)); if (!collection) { @@ -155,10 +156,10 @@ bool Helpers::findById(OperationContext* opCtx, } RecordId Helpers::findById(OperationContext* opCtx, - Collection* collection, + const Collection* collection, const BSONObj& idquery) { verify(collection); - IndexCatalog* catalog = collection->getIndexCatalog(); + const IndexCatalog* catalog = collection->getIndexCatalog(); const IndexDescriptor* desc = catalog->findIdIndex(opCtx); uassert(13430, "no _id index", desc); return catalog->getEntry(desc)->accessMethod()->findSingle(opCtx, idquery["_id"].wrap()); @@ -166,10 +167,10 @@ RecordId Helpers::findById(OperationContext* opCtx, // Acquires necessary locks to read the collection with the given namespace. If this is an oplog // read, use AutoGetOplog for simplified locking. -Collection* getCollectionForRead(OperationContext* opCtx, - const NamespaceString& ns, - boost::optional<AutoGetCollectionForReadCommand>& autoColl, - boost::optional<AutoGetOplog>& autoOplog) { +const Collection* getCollectionForRead(OperationContext* opCtx, + const NamespaceString& ns, + boost::optional<AutoGetCollectionForReadCommand>& autoColl, + boost::optional<AutoGetOplog>& autoOplog) { if (ns.isOplog()) { // Simplify locking rules for oplog collection. autoOplog.emplace(opCtx, OplogAccessMode::kRead); |