summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2021-11-03 20:25:19 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-11-04 01:04:03 +0000
commit4b04962780d870c4e6afbe2f0ba61bf4865fc2a8 (patch)
tree859fe140c1ff1c20fd57a8b6e1e5f2c9d58eafe5
parent058019e29ff1c96f09fa9c183f94bcd840126372 (diff)
downloadmongo-4b04962780d870c4e6afbe2f0ba61bf4865fc2a8.tar.gz
SERVER-61158 add CreateIndexEntryFlags::kUpdateMetadata
This also restores KVEngine::alterIdentMetadata() which was removed during 4.4 FCV-related work in commit 8e4f280e492fe2bfb7842733ff640030d559cd0a.
-rw-r--r--src/mongo/db/catalog/index_catalog.h8
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp9
-rw-r--r--src/mongo/db/storage/kv/kv_engine.h4
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp14
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h4
5 files changed, 38 insertions, 1 deletions
diff --git a/src/mongo/db/catalog/index_catalog.h b/src/mongo/db/catalog/index_catalog.h
index 624f0fe427c..1dfcc641869 100644
--- a/src/mongo/db/catalog/index_catalog.h
+++ b/src/mongo/db/catalog/index_catalog.h
@@ -92,7 +92,13 @@ enum class CreateIndexEntryFlags : int {
* built. This is used when starting a node in standalone mode and a two-phase index build
* is incomplete. kIsReady must not also be set.
*/
- kFrozen = 0x4
+ kFrozen = 0x4,
+ /**
+ * kUpdateMetadata indicates that the index metadata in the storage engine should be updated
+ * based on changes to the IndexDescriptor.
+ * This is used when making an index unique through the collMod command.
+ */
+ kUpdateMetadata = 0x8
};
inline bool operator&(CreateIndexEntryFlags lhs, CreateIndexEntryFlags rhs) {
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index 5e0c8b0f593..261f0f8fb71 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -431,6 +431,15 @@ IndexCatalogEntry* IndexCatalogImpl::createIndexEntry(OperationContext* opCtx,
opCtx, collection, ident, std::move(descriptor), frozen);
IndexDescriptor* desc = entry->descriptor();
+
+ // In some cases, it may be necessary to update the index metadata in the storage engine in
+ // order to obtain the correct SortedDataInterface. One such scenario is found in converting an
+ // index to be unique.
+ bool isUpdateMetadata = CreateIndexEntryFlags::kUpdateMetadata & flags;
+ if (isUpdateMetadata) {
+ engine->getEngine()->alterIdentMetadata(opCtx, ident, desc);
+ }
+
const auto& collOptions = collection->getCollectionOptions();
std::unique_ptr<SortedDataInterface> sdi =
engine->getEngine()->getSortedDataInterface(opCtx, collOptions, ident, desc);
diff --git a/src/mongo/db/storage/kv/kv_engine.h b/src/mongo/db/storage/kv/kv_engine.h
index 2503db506b8..b4f14fffcdf 100644
--- a/src/mongo/db/storage/kv/kv_engine.h
+++ b/src/mongo/db/storage/kv/kv_engine.h
@@ -175,6 +175,10 @@ public:
return status;
}
+ virtual void alterIdentMetadata(OperationContext* opCtx,
+ StringData ident,
+ const IndexDescriptor* desc) {}
+
/**
* See StorageEngine::flushAllFiles for details
*/
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index 45fd173275e..991b8c3afbc 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -1646,6 +1646,20 @@ std::unique_ptr<RecordStore> WiredTigerKVEngine::makeTemporaryRecordStore(Operat
return std::move(rs);
}
+void WiredTigerKVEngine::alterIdentMetadata(OperationContext* opCtx,
+ StringData ident,
+ const IndexDescriptor* desc) {
+ WiredTigerSession session(_conn);
+ std::string uri = _uri(ident);
+
+ // Make the alter call to update metadata without taking exclusive lock to avoid conflicts with
+ // concurrent operations.
+ std::string alterString =
+ WiredTigerIndex::generateAppMetadataString(*desc) + "exclusive_refreshed=false,";
+ invariantWTOK(
+ session.getSession()->alter(session.getSession(), uri.c_str(), alterString.c_str()));
+}
+
Status WiredTigerKVEngine::dropIdent(RecoveryUnit* ru,
StringData ident,
StorageEngine::DropIdentCallback&& onDrop) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
index 1301a0c07b8..b45c0269b6c 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
@@ -170,6 +170,10 @@ public:
void dropIdentForImport(OperationContext* opCtx, StringData ident) override;
+ void alterIdentMetadata(OperationContext* opCtx,
+ StringData ident,
+ const IndexDescriptor* desc) override;
+
Status okToRename(OperationContext* opCtx,
StringData fromNS,
StringData toNS,