summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2018-02-08 11:42:18 -0500
committerKyle Suarez <kyle.suarez@mongodb.com>2018-02-08 11:42:18 -0500
commit8d46e50bdf3e52c39fe60ed3323fe732a84412f8 (patch)
treeb17d8fb2658fab4babae93ee0779abfb4be780f7 /src/mongo/db
parent0630b56803ef000012725490526242e97bc879cc (diff)
downloadmongo-8d46e50bdf3e52c39fe60ed3323fe732a84412f8.tar.gz
SERVER-33106 set multiKeyPaths and clear plan cache in onCommit hook
Without this change, if the WriteUnitOfWork aborts, we will set the multiKeyPaths for the index without actually marking it as multiKey.
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/catalog/index_catalog_entry_impl.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.cpp b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
index cbea2f00a00..46abd0e3170 100644
--- a/src/mongo/db/catalog/index_catalog_entry_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
@@ -272,22 +272,27 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
// CollectionCatalogEntry::setIndexIsMultikey() requires that we discard the path-level
// multikey information in order to avoid unintentionally setting path-level multikey
// information on an index created before 3.4.
- if (_collection->setIndexIsMultikey(opCtx, _descriptor->indexName(), paths)) {
- if (_infoCache) {
+ const bool indexMetadataHasChanged =
+ _collection->setIndexIsMultikey(opCtx, _descriptor->indexName(), paths);
+
+ // When the recovery unit commits, update the multikey paths if needed and clear the plan cache
+ // if the index metadata has changed.
+ opCtx->recoveryUnit()->onCommit([this, multikeyPaths, indexMetadataHasChanged] {
+ _isMultikey.store(true);
+
+ if (_indexTracksPathLevelMultikeyInfo) {
+ stdx::lock_guard<stdx::mutex> lk(_indexMultikeyPathsMutex);
+ for (size_t i = 0; i < multikeyPaths.size(); ++i) {
+ _indexMultikeyPaths[i].insert(multikeyPaths[i].begin(), multikeyPaths[i].end());
+ }
+ }
+
+ if (indexMetadataHasChanged && _infoCache) {
LOG(1) << _ns << ": clearing plan cache - index " << _descriptor->keyPattern()
<< " set to multi key.";
_infoCache->clearQueryCache();
}
- }
-
- opCtx->recoveryUnit()->onCommit([this] { _isMultikey.store(true); });
-
- if (_indexTracksPathLevelMultikeyInfo) {
- stdx::lock_guard<stdx::mutex> lk(_indexMultikeyPathsMutex);
- for (size_t i = 0; i < multikeyPaths.size(); ++i) {
- _indexMultikeyPaths[i].insert(multikeyPaths[i].begin(), multikeyPaths[i].end());
- }
- }
+ });
}
// ----