diff options
-rw-r--r-- | jstests/core/collmod_convert_to_unique.js | 8 | ||||
-rw-r--r-- | src/mongo/db/catalog/coll_mod_index.cpp | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/jstests/core/collmod_convert_to_unique.js b/jstests/core/collmod_convert_to_unique.js index 280f571c005..27bd11b0344 100644 --- a/jstests/core/collmod_convert_to_unique.js +++ b/jstests/core/collmod_convert_to_unique.js @@ -7,6 +7,10 @@ * assumes_no_implicit_collection_creation_after_drop, # common tag in collMod tests. * requires_fcv_52, * requires_non_retryable_commands, # common tag in collMod tests. + * # TODO(SERVER-61181): Fix validation errors under ephemeralForTest. + * incompatible_with_eft, + * # TODO(SERVER-61182): Fix WiredTigerKVEngine::alterIdentMetadata() under inMemory. + * requires_persistence, * ] */ @@ -72,8 +76,8 @@ if (db.getMongo().isMongos()) { } // Look up index details in listIndexes output. -assert.eq(countUnique({a: 1}), 0, 'index should not be unique yet: ' + tojson(coll.getIndexes())); +assert.eq(countUnique({a: 1}), 1, 'index should be unique now: ' + tojson(coll.getIndexes())); // Test uniqueness constraint. -assert.commandWorked(coll.insert({_id: 100, a: 100})); +assert.commandFailedWithCode(coll.insert({_id: 100, a: 100}), ErrorCodes.DuplicateKey); })(); diff --git a/src/mongo/db/catalog/coll_mod_index.cpp b/src/mongo/db/catalog/coll_mod_index.cpp index 9fbf29bab63..31207f38d3e 100644 --- a/src/mongo/db/catalog/coll_mod_index.cpp +++ b/src/mongo/db/catalog/coll_mod_index.cpp @@ -150,6 +150,7 @@ void _processCollModIndexRequestUnique(OperationContext* opCtx, return; } *newUnique = indexUnique; + autoColl->getWritableCollection()->updateUniqueSetting(opCtx, idx->indexName()); } } // namespace @@ -206,6 +207,11 @@ void processCollModIndexRequest(OperationContext* opCtx, // This matches the default for IndexCatalog::refreshEntry(). auto flags = CreateIndexEntryFlags::kIsReady; + // Update data format version in storage engine metadata for index. + if (indexUnique) { + flags = CreateIndexEntryFlags::kIsReady | CreateIndexEntryFlags::kUpdateMetadata; + } + // Notify the index catalog that the definition of this index changed. This will invalidate the // local idx pointer. On rollback of this WUOW, the local var idx pointer will be valid again. autoColl->getWritableCollection()->getIndexCatalog()->refreshEntry( |