summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2023-02-02 14:08:44 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-03 05:10:08 +0000
commitff06d8d8c15e6b4f79231a385539741bb169dac1 (patch)
tree0e0910fb3f668152b9adf595d46f0349662dbc80 /src
parentb2985ae30e7f4ff6a80690ef9d70d8215b353892 (diff)
downloadmongo-ff06d8d8c15e6b4f79231a385539741bb169dac1.tar.gz
SERVER-72111 Avoid additional read from DurableCatalog in CollectionImpl::initFromExisting
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/collection.h2
-rw-r--r--src/mongo/db/catalog/collection_catalog.cpp10
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp30
-rw-r--r--src/mongo/db/catalog/collection_impl.h1
-rw-r--r--src/mongo/db/catalog/collection_mock.h1
-rw-r--r--src/mongo/db/catalog/virtual_collection_impl.h1
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp1
7 files changed, 32 insertions, 14 deletions
diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h
index 48e2294ca76..dad5c86ce3f 100644
--- a/src/mongo/db/catalog/collection.h
+++ b/src/mongo/db/catalog/collection.h
@@ -48,6 +48,7 @@
#include "mongo/db/repl/oplog.h"
#include "mongo/db/session/logical_session_id.h"
#include "mongo/db/storage/bson_collection_catalog_entry.h"
+#include "mongo/db/storage/durable_catalog_entry.h"
#include "mongo/db/storage/record_store.h"
#include "mongo/db/storage/snapshot.h"
#include "mongo/db/yieldable.h"
@@ -230,6 +231,7 @@ public:
*/
virtual Status initFromExisting(OperationContext* opCtx,
const std::shared_ptr<Collection>& collection,
+ const DurableCatalogEntry& catalogEntry,
boost::optional<Timestamp> readTimestamp) = 0;
virtual bool isCommitted() const {
diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp
index 330df528902..714717f16db 100644
--- a/src/mongo/db/catalog/collection_catalog.cpp
+++ b/src/mongo/db/catalog/collection_catalog.cpp
@@ -1089,8 +1089,11 @@ std::shared_ptr<Collection> CollectionCatalog::_createCompatibleCollection(
catalogEntry.catalogId,
catalogEntry.metadata,
/*rs=*/nullptr);
- Status status = collToReturn->initFromExisting(
- opCtx, latestCollection ? latestCollection : dropPendingColl, readTimestamp);
+ Status status =
+ collToReturn->initFromExisting(opCtx,
+ latestCollection ? latestCollection : dropPendingColl,
+ catalogEntry,
+ readTimestamp);
if (!status.isOK()) {
LOGV2_DEBUG(
6857100, 1, "Failed to instantiate collection", "reason"_attr = status.reason());
@@ -1142,7 +1145,8 @@ std::shared_ptr<Collection> CollectionCatalog::_createNewPITCollection(
catalogEntry.catalogId,
catalogEntry.metadata,
std::move(rs));
- Status status = collToReturn->initFromExisting(opCtx, /*collection=*/nullptr, readTimestamp);
+ Status status =
+ collToReturn->initFromExisting(opCtx, /*collection=*/nullptr, catalogEntry, readTimestamp);
if (!status.isOK()) {
LOGV2_DEBUG(
6857102, 1, "Failed to instantiate collection", "reason"_attr = status.reason());
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index 7b290ed5ba7..c60e5b17671 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -214,12 +214,7 @@ bool doesMinMaxHaveMixedSchemaData(const BSONObj& min, const BSONObj& max) {
StatusWith<std::shared_ptr<Ident>> findSharedIdentForIndex(OperationContext* opCtx,
StorageEngine* storageEngine,
Collection* collection,
- RecordId catalogId,
- StringData indexName) {
- // TODO(SERVER-72111): Remove the need for this durable catalog lookup.
- const std::string ident =
- DurableCatalog::get(opCtx)->getIndexIdent(opCtx, catalogId, indexName);
-
+ StringData ident) {
// First check the index catalog of the existing collection for the index entry.
auto latestEntry = [&]() -> std::shared_ptr<IndexCatalogEntry> {
if (!collection)
@@ -236,7 +231,7 @@ StatusWith<std::shared_ptr<Ident>> findSharedIdentForIndex(OperationContext* opC
}
// Next check the CollectionCatalog for a compatible drop pending index.
- auto dropPendingEntry = CollectionCatalog::get(opCtx)->findDropPendingIndex(ident);
+ auto dropPendingEntry = CollectionCatalog::get(opCtx)->findDropPendingIndex(ident.toString());
// The index entries are incompatible with the read timestamp, but we need to use the same
// shared ident to prevent the reaper from dropping idents prematurely.
@@ -246,7 +241,7 @@ StatusWith<std::shared_ptr<Ident>> findSharedIdentForIndex(OperationContext* opC
// The index ident is expired, but it could still be drop pending. Mark it as in use if
// possible.
- auto newIdent = storageEngine->markIdentInUse(ident);
+ auto newIdent = storageEngine->markIdentInUse(ident.toString());
if (newIdent) {
return newIdent;
}
@@ -396,6 +391,7 @@ void CollectionImpl::init(OperationContext* opCtx) {
Status CollectionImpl::initFromExisting(OperationContext* opCtx,
const std::shared_ptr<Collection>& collection,
+ const DurableCatalogEntry& catalogEntry,
boost::optional<Timestamp> readTimestamp) {
// We are per definition committed if we initialize from an existing collection.
_cachedCommitted = true;
@@ -420,13 +416,25 @@ Status CollectionImpl::initFromExisting(OperationContext* opCtx,
// Determine which indexes from the existing collection can be shared with this newly
// initialized collection. The remaining indexes will be initialized by the IndexCatalog.
- for (const auto& index : _metadata->indexes) {
+ auto it = catalogEntry.indexIdents.begin();
+ for (size_t offset = 0; offset < _metadata->indexes.size(); ++offset, ++it) {
+ invariant(it != catalogEntry.indexIdents.end());
+
+ const auto& index = _metadata->indexes[offset];
const auto indexName = index.nameStringData();
if (!isIndexReady(indexName)) {
continue;
}
- auto swIndexIdent =
- findSharedIdentForIndex(opCtx, storageEngine, collection.get(), _catalogId, indexName);
+
+ BSONElement identElem = *it;
+ if (indexName != identElem.fieldName()) {
+ // If the indexes don't have the same ordering in 'idxIdent' and 'md', we perform a
+ // search instead. There's no guarantee these are in order, but they typically are.
+ identElem = catalogEntry.indexIdents.getField(indexName);
+ }
+
+ auto swIndexIdent = findSharedIdentForIndex(
+ opCtx, storageEngine, collection.get(), identElem.checkAndGetStringData());
if (!swIndexIdent.isOK()) {
return swIndexIdent.getStatus();
}
diff --git a/src/mongo/db/catalog/collection_impl.h b/src/mongo/db/catalog/collection_impl.h
index ca85b483b5b..b4410758f20 100644
--- a/src/mongo/db/catalog/collection_impl.h
+++ b/src/mongo/db/catalog/collection_impl.h
@@ -82,6 +82,7 @@ public:
void init(OperationContext* opCtx) final;
Status initFromExisting(OperationContext* opCtx,
const std::shared_ptr<Collection>& collection,
+ const DurableCatalogEntry& catalogEntry,
boost::optional<Timestamp> readTimestamp) final;
bool isInitialized() const final;
bool isCommitted() const final;
diff --git a/src/mongo/db/catalog/collection_mock.h b/src/mongo/db/catalog/collection_mock.h
index a7d1a7b4545..76c9a07f89b 100644
--- a/src/mongo/db/catalog/collection_mock.h
+++ b/src/mongo/db/catalog/collection_mock.h
@@ -68,6 +68,7 @@ public:
Status initFromExisting(OperationContext* opCtx,
const std::shared_ptr<Collection>& collection,
+ const DurableCatalogEntry& catalogEntry,
boost::optional<Timestamp> readTimestamp) {
MONGO_UNREACHABLE;
}
diff --git a/src/mongo/db/catalog/virtual_collection_impl.h b/src/mongo/db/catalog/virtual_collection_impl.h
index 0daf26e5ab3..055c61283a2 100644
--- a/src/mongo/db/catalog/virtual_collection_impl.h
+++ b/src/mongo/db/catalog/virtual_collection_impl.h
@@ -68,6 +68,7 @@ public:
Status initFromExisting(OperationContext* opCtx,
const std::shared_ptr<Collection>& collection,
+ const DurableCatalogEntry& catalogEntry,
boost::optional<Timestamp> readTimestamp) final {
unimplementedTasserted();
return Status(ErrorCodes::UnknownError, "unknown");
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp
index 3bc455a2ba1..5b25316603e 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp
@@ -85,6 +85,7 @@ public:
Status initFromExisting(OperationContext* opCtx,
const std::shared_ptr<Collection>& collection,
+ const DurableCatalogEntry& catalogEntry,
boost::optional<Timestamp> readTimestamp) override {
MONGO_UNREACHABLE;
}