summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordi Olivares Provencio <jordi.olivares-provencio@mongodb.com>2022-02-07 12:40:58 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-07 13:08:13 +0000
commit5aa1d8f38943f36b93faf0485ea37f2de830621f (patch)
tree56be34e592e4a2cece22197d860a41ab82185b01
parented2e8137e7911fde3815c45f733776211fb7cc94 (diff)
downloadmongo-5aa1d8f38943f36b93faf0485ea37f2de830621f.tar.gz
SERVER-63252 Modify CollectionImpl::setIndexIsMultikey to not modify state unless necessary
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index e58330d61c4..66bbbd756b2 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -2195,13 +2195,19 @@ bool CollectionImpl::setIndexIsMultikey(OperationContext* opCtx,
uncommittedMultikeys = std::make_shared<UncommittedMultikey::MultikeyMap>();
}
BSONCollectionCatalogEntry::MetaData* metadata = nullptr;
+ bool hasSetMultikey = false;
if (auto it = uncommittedMultikeys->find(this); it != uncommittedMultikeys->end()) {
metadata = &it->second;
+ hasSetMultikey = setMultikey(*metadata);
} else {
- metadata = &uncommittedMultikeys->emplace(this, *_metadata).first->second;
+ BSONCollectionCatalogEntry::MetaData metadataLocal(*_metadata);
+ hasSetMultikey = setMultikey(metadataLocal);
+ if (hasSetMultikey) {
+ metadata = &uncommittedMultikeys->emplace(this, std::move(metadataLocal)).first->second;
+ }
}
- if (!setMultikey(*metadata))
+ if (!hasSetMultikey)
return false;
opCtx->recoveryUnit()->onRollback(