summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2021-05-11 14:30:26 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-20 19:18:53 +0000
commit11de948b0c50df7d12de09ae0f01e791fc5d70d7 (patch)
tree5a5a89cce0dc94f21778725184f8da3d5f76a13b /src/mongo/db/commands
parentb2802257c7cd2cf253847d67da5ddcc780a5b85f (diff)
downloadmongo-11de948b0c50df7d12de09ae0f01e791fc5d70d7.tar.gz
SERVER-56002 SERVER-56023 Store Collection metadata in the Collection and reply on the copy-on-write machinery to keep it in sync with the durable catalog.
All updates to the metadata needs to happen through the Collection, moved interfaces from the DurableCatalog to the Collection. Removed back pointer to Collection in IndexCatalogEntryImpl, interfaces now correctly take a const or non-const Collection. This should make its iterface const-correct to avoid making bugs where the copy-on-write system for Collections are bypassed. Multikey handle is special as it needs to happen without exclusive access to the Collection. Implemented isolation for the Collection metadata when multikey is changed. It handles multi-doc transactions and is only commited to the Collection instance after the write to the durable catalog successfully commits. listCollections and listIndexes can now safetly read the metadata cache without needing to read from the durable catalog making them safe to do without Collection level locks.
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r--src/mongo/db/commands/create_indexes.cpp2
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp10
-rw-r--r--src/mongo/db/commands/list_collections.cpp15
-rw-r--r--src/mongo/db/commands/mr_test.cpp2
-rw-r--r--src/mongo/db/commands/resize_oplog.cpp6
-rw-r--r--src/mongo/db/commands/validate.cpp1
-rw-r--r--src/mongo/db/commands/write_commands.cpp1
7 files changed, 13 insertions, 24 deletions
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index 74997b4ad5e..25563a57492 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -220,7 +220,7 @@ std::vector<BSONObj> resolveDefaultsAndRemoveExistingIndexes(OperationContext* o
auto normalSpecs = IndexBuildsCoordinator::normalizeIndexSpecs(opCtx, collection, indexSpecs);
return collection->getIndexCatalog()->removeExistingIndexes(
- opCtx, normalSpecs, false /*removeIndexBuildsToo*/);
+ opCtx, collection, normalSpecs, false /*removeIndexBuildsToo*/);
}
/**
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index 30b2b1612e7..544709fec9d 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -51,7 +51,6 @@
#include "mongo/db/index_builds_coordinator.h"
#include "mongo/db/op_observer.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/timeseries/timeseries_index_schema_conversion_functions.h"
#include "mongo/db/timeseries/timeseries_lookup.h"
#include "mongo/db/vector_clock.h"
@@ -210,8 +209,7 @@ public:
std::vector<std::string> indexNames;
writeConflictRetry(opCtx, "listIndexes", toReIndexNss.ns(), [&] {
indexNames.clear();
- DurableCatalog::get(opCtx)->getAllIndexes(
- opCtx, collection->getCatalogId(), &indexNames);
+ collection->getAllIndexes(&indexNames);
});
all.reserve(indexNames.size());
@@ -219,8 +217,7 @@ public:
for (size_t i = 0; i < indexNames.size(); i++) {
const std::string& name = indexNames[i];
BSONObj spec = writeConflictRetry(opCtx, "getIndexSpec", toReIndexNss.ns(), [&] {
- return DurableCatalog::get(opCtx)->getIndexSpec(
- opCtx, collection->getCatalogId(), name);
+ return collection->getIndexSpec(name);
});
{
@@ -261,7 +258,8 @@ public:
"Uninitialized");
writeConflictRetry(opCtx, "dropAllIndexes", toReIndexNss.ns(), [&] {
WriteUnitOfWork wunit(opCtx);
- collection.getWritableCollection()->getIndexCatalog()->dropAllIndexes(opCtx, true);
+ collection.getWritableCollection()->getIndexCatalog()->dropAllIndexes(
+ opCtx, collection.getWritableCollection(), true);
swIndexesToRebuild =
indexer->init(opCtx, collection, all, MultiIndexBlock::kNoopOnInitFn);
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index c8fa5630521..03c012f06fa 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -61,7 +61,6 @@
#include "mongo/db/query/find_common.h"
#include "mongo/db/query/plan_executor_factory.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/storage_engine.h"
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/views/view_catalog.h"
@@ -192,19 +191,17 @@ BSONObj buildCollectionBson(OperationContext* opCtx,
return b.obj();
}
- CollectionOptions options =
- DurableCatalog::get(opCtx)->getCollectionOptions(opCtx, collection->getCatalogId());
+ const auto& options = collection->getCollectionOptions();
// While the UUID is stored as a collection option, from the user's perspective it is an
- // unsettable read-only property, so put it in the 'info' section.
- auto uuid = options.uuid;
- options.uuid.reset();
- b.append("options", options.toBSON());
+ // unsettable read-only property, so put it in the 'info' section. Pass 'false' to toBSON so it
+ // doesn't include 'uuid' here.
+ b.append("options", options.toBSON(false));
BSONObjBuilder infoBuilder;
infoBuilder.append("readOnly", storageGlobalParams.readOnly);
- if (uuid)
- infoBuilder.appendElements(uuid->toBSON());
+ if (options.uuid)
+ infoBuilder.appendElements(options.uuid->toBSON());
b.append("info", infoBuilder.obj());
auto idIndex = collection->getIndexCatalog()->findIdIndex(opCtx);
diff --git a/src/mongo/db/commands/mr_test.cpp b/src/mongo/db/commands/mr_test.cpp
index eaada81ab68..1dd86a06946 100644
--- a/src/mongo/db/commands/mr_test.cpp
+++ b/src/mongo/db/commands/mr_test.cpp
@@ -537,7 +537,7 @@ TEST_F(MapReduceCommandTest, ReplacingExistingOutputCollectionPreservesIndexes)
WriteUnitOfWork wuow(_opCtx.get());
ASSERT_OK(
coll.getWritableCollection()->getIndexCatalog()->createIndexOnEmptyCollection(
- _opCtx.get(), indexSpec));
+ _opCtx.get(), coll.getWritableCollection(), indexSpec));
wuow.commit();
});
}
diff --git a/src/mongo/db/commands/resize_oplog.cpp b/src/mongo/db/commands/resize_oplog.cpp
index e8a54b818e8..5476c4ea249 100644
--- a/src/mongo/db/commands/resize_oplog.cpp
+++ b/src/mongo/db/commands/resize_oplog.cpp
@@ -98,8 +98,6 @@ public:
if (auto sizeMB = params.getSize()) {
const long long sizeBytes = *sizeMB * 1024 * 1024;
uassertStatusOK(coll.getWritableCollection()->updateCappedSize(opCtx, sizeBytes));
- DurableCatalog::get(opCtx)->updateCappedSize(
- opCtx, coll->getCatalogId(), sizeBytes);
}
if (auto minRetentionHoursOpt = params.getMinRetentionHours()) {
@@ -109,9 +107,7 @@ public:
LOGV2(20497,
"replSetResizeOplog success",
- "size"_attr = DurableCatalog::get(opCtx)
- ->getCollectionOptions(opCtx, coll->getCatalogId())
- .cappedSize,
+ "size"_attr = coll->getCollectionOptions().cappedSize,
"minRetentionHours"_attr = storageGlobalParams.oplogMinRetentionHours.load());
return true;
});
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp
index bdde2c3156a..6e2889eb741 100644
--- a/src/mongo/db/commands/validate.cpp
+++ b/src/mongo/db/commands/validate.cpp
@@ -36,7 +36,6 @@
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/query/internal_plans.h"
-#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/record_store.h"
#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
diff --git a/src/mongo/db/commands/write_commands.cpp b/src/mongo/db/commands/write_commands.cpp
index 04efea03dc5..2e3caeb78dd 100644
--- a/src/mongo/db/commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands.cpp
@@ -63,7 +63,6 @@
#include "mongo/db/retryable_writes_stats.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/storage/duplicate_key_error_info.h"
-#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/timeseries/bucket_catalog.h"
#include "mongo/db/transaction_participant.h"
#include "mongo/db/views/view_catalog.h"