diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/catalog/index_catalog.h | 8 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_impl.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/storage/kv/kv_engine.h | 4 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h | 4 |
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, |