summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/capped_utils.cpp
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-08-14 10:23:04 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-02 23:53:39 +0000
commitbf5914a20b596ba3bde772b42e579e028f733bac (patch)
tree2b26469571786d9adb5e95c47990c2416bfab9c4 /src/mongo/db/catalog/capped_utils.cpp
parent6b3e341703b781bb1ff7b1263406a0f1d28dd77c (diff)
downloadmongo-bf5914a20b596ba3bde772b42e579e028f733bac.tar.gz
SERVER-50317 Const correct uses of Collection
Most of the code should only need a const Collection now. AutoGetCollection returns a const Collection by default. There is a placeholder getWritableCollection() interface that will handle the necessary steps we need for lock free reads in the future. Added some operators to AutoGetCollection so it behaves more like a smart pointer.
Diffstat (limited to 'src/mongo/db/catalog/capped_utils.cpp')
-rw-r--r--src/mongo/db/catalog/capped_utils.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp
index bc5b78af2f1..5dd3533fc91 100644
--- a/src/mongo/db/catalog/capped_utils.cpp
+++ b/src/mongo/db/catalog/capped_utils.cpp
@@ -72,7 +72,8 @@ Status emptyCapped(OperationContext* opCtx, const NamespaceString& collectionNam
uassert(ErrorCodes::NamespaceNotFound, "no such database", db);
Collection* collection =
- CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, collectionName);
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespaceForMetadataWrite(opCtx,
+ collectionName);
uassert(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "emptycapped not supported on view: " << collectionName.ns(),
collection || !ViewCatalog::get(db)->lookup(opCtx, collectionName.ns()));
@@ -114,7 +115,7 @@ void cloneCollectionAsCapped(OperationContext* opCtx,
const NamespaceString& toNss,
long long size,
bool temp) {
- Collection* fromCollection =
+ const Collection* fromCollection =
CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, fromNss);
if (!fromCollection) {
uassert(ErrorCodes::CommandNotSupportedOnView,
@@ -153,7 +154,7 @@ void cloneCollectionAsCapped(OperationContext* opCtx,
uassertStatusOK(createCollection(opCtx, toNss.db().toString(), cmd.done()));
}
- Collection* toCollection =
+ const Collection* toCollection =
CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, toNss);
invariant(toCollection); // we created above
@@ -243,7 +244,7 @@ void convertToCapped(OperationContext* opCtx, const NamespaceString& ns, long lo
StringData dbname = ns.db();
StringData shortSource = ns.coll();
- AutoGetCollection autoColl(opCtx, ns, MODE_X);
+ AutoGetCollection coll(opCtx, ns, MODE_X);
bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() &&
!repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, ns);
@@ -252,11 +253,11 @@ void convertToCapped(OperationContext* opCtx, const NamespaceString& ns, long lo
str::stream() << "Not primary while converting " << ns << " to a capped collection",
!userInitiatedWritesAndNotPrimary);
- Database* const db = autoColl.getDb();
+ Database* const db = coll.getDb();
uassert(
ErrorCodes::NamespaceNotFound, str::stream() << "database " << dbname << " not found", db);
- if (Collection* coll = autoColl.getCollection()) {
+ if (coll) {
IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(coll->uuid());
}