diff options
author | Maria van Keulen <maria@mongodb.com> | 2018-03-15 18:41:20 -0400 |
---|---|---|
committer | Maria van Keulen <maria@mongodb.com> | 2018-03-18 16:59:29 -0400 |
commit | 528c8f24d45ce90274f41ba117c239741de8a890 (patch) | |
tree | bd663f675b8bb369ea94aaace47fd3f10716b97d | |
parent | 0ba0567660231bdd8326e4e5e14fb1feabee76be (diff) | |
download | mongo-528c8f24d45ce90274f41ba117c239741de8a890.tar.gz |
SERVER-33928 Don't assert system.indexes or system.namespaces have UUIDs
6 files changed, 25 insertions, 18 deletions
diff --git a/src/mongo/db/catalog/collection_catalog_entry.h b/src/mongo/db/catalog/collection_catalog_entry.h index ab8774eeb79..bd614debc7b 100644 --- a/src/mongo/db/catalog/collection_catalog_entry.h +++ b/src/mongo/db/catalog/collection_catalog_entry.h @@ -153,9 +153,9 @@ public: /** * Compare the UUID argument to the UUID obtained from the metadata. Return true if they - * are equal, false otherwise. + * are equal, false otherwise. uuid can become a CollectionUUID once MMAPv1 is removed. */ - virtual bool isEqualToMetadataUUID(OperationContext* opCtx, CollectionUUID uuid) = 0; + virtual bool isEqualToMetadataUUID(OperationContext* opCtx, OptionalCollectionUUID uuid) = 0; /** * Updates size of a capped Collection. diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp index 865fa0f09a7..2c86c04da75 100644 --- a/src/mongo/db/op_observer_impl.cpp +++ b/src/mongo/db/op_observer_impl.cpp @@ -641,7 +641,8 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx, ->logOp(opCtx, "c", cmdNss, cmdObj, nullptr); // Make sure the UUID values in the Collection metadata, the Collection object, and the UUID - // catalog are all present and equal. + // catalog are all present and equal, unless the collection is system.indexes or + // system.namespaces (see SERVER-29926, SERVER-30095). invariant(opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_X)); Database* db = dbHolder().get(opCtx, nss.db()); // Some unit tests call the op observer on an unregistered Database. @@ -649,9 +650,11 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx, return; } Collection* coll = db->getCollection(opCtx, nss.ns()); - invariant(coll->uuid() == uuid && coll->uuid()); + + invariant(coll->uuid() || nss.coll() == "system.indexes" || nss.coll() == "system.namespaces"); + invariant(coll->uuid() == uuid); CollectionCatalogEntry* entry = coll->getCatalogEntry(); - invariant(entry->isEqualToMetadataUUID(opCtx, uuid.get())); + invariant(entry->isEqualToMetadataUUID(opCtx, uuid)); } void OpObserverImpl::onDropDatabase(OperationContext* opCtx, const std::string& dbName) { diff --git a/src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp b/src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp index a7f586d396d..1171ba8467a 100644 --- a/src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp +++ b/src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp @@ -248,9 +248,10 @@ void KVCollectionCatalogEntry::addUUID(OperationContext* opCtx, } } -bool KVCollectionCatalogEntry::isEqualToMetadataUUID(OperationContext* opCtx, CollectionUUID uuid) { +bool KVCollectionCatalogEntry::isEqualToMetadataUUID(OperationContext* opCtx, + OptionalCollectionUUID uuid) { MetaData md = _getMetaData(opCtx); - return md.options.uuid && md.options.uuid.get() == uuid; + return md.options.uuid && md.options.uuid == uuid; } void KVCollectionCatalogEntry::updateFlags(OperationContext* opCtx, int newValue) { diff --git a/src/mongo/db/storage/kv/kv_collection_catalog_entry.h b/src/mongo/db/storage/kv/kv_collection_catalog_entry.h index 5fd500be864..51104c787e7 100644 --- a/src/mongo/db/storage/kv/kv_collection_catalog_entry.h +++ b/src/mongo/db/storage/kv/kv_collection_catalog_entry.h @@ -87,7 +87,7 @@ public: void addUUID(OperationContext* opCtx, CollectionUUID uuid, Collection* coll) final; - bool isEqualToMetadataUUID(OperationContext* opCtx, CollectionUUID uuid) final; + bool isEqualToMetadataUUID(OperationContext* opCtx, OptionalCollectionUUID uuid) final; RecordStore* getRecordStore() { return _recordStore.get(); diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp index d010c2d2ed0..33e3e3ca78a 100644 --- a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp +++ b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp @@ -450,17 +450,20 @@ void NamespaceDetailsCollectionCatalogEntry::addUUID(OperationContext* opCtx, } bool NamespaceDetailsCollectionCatalogEntry::isEqualToMetadataUUID(OperationContext* opCtx, - CollectionUUID uuid) { - if (ns().coll() != "system.namespaces") { - RecordData namespaceData; - invariant(_namespacesRecordStore->findRecord(opCtx, _namespacesRecordId, &namespaceData)); - - auto namespacesBson = namespaceData.releaseToBson(); - auto optionsObj = namespacesBson["options"].Obj(); - return !optionsObj["uuid"].eoo() && UUID::parse(optionsObj["uuid"]).getValue() == uuid; - } else { + OptionalCollectionUUID uuid) { + if (ns().coll() == "system.namespaces") { return true; } + RecordData namespaceData; + invariant(_namespacesRecordStore->findRecord(opCtx, _namespacesRecordId, &namespaceData)); + + auto namespacesBson = namespaceData.releaseToBson(); + if (ns().coll() == "system.indexes") { + return !uuid && (!namespacesBson["options"].isABSONObj() || + namespacesBson["options"].Obj()["uuid"].eoo()); + } + auto optionsObj = namespacesBson["options"].Obj(); + return !optionsObj["uuid"].eoo() && UUID::parse(optionsObj["uuid"]).getValue() == uuid; } void NamespaceDetailsCollectionCatalogEntry::updateValidator(OperationContext* opCtx, diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.h b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.h index 3a8f04ee615..517128ae26d 100644 --- a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.h +++ b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.h @@ -104,7 +104,7 @@ public: void addUUID(OperationContext* opCtx, CollectionUUID uuid, Collection* coll) final; - bool isEqualToMetadataUUID(OperationContext* opCtx, CollectionUUID uuid); + bool isEqualToMetadataUUID(OperationContext* opCtx, OptionalCollectionUUID uuid); void updateValidator(OperationContext* opCtx, const BSONObj& validator, |