Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/mongo/db/catalog/index_catalog_entry_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
#include "mongo/db/session_catalog.h"
#include "mongo/db/storage/storage_options.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
Expand Down Expand Up @@ -397,25 +398,29 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
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](boost::optional<Timestamp>) {
_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());
// Eloq refreshes the cached Collection while committing catalog metadata, before RecoveryUnit
// callbacks run. The refreshed entry already reflects the committed multikey metadata, so the
// callback below must not retain the old IndexCatalogEntry.
if (storageGlobalParams.engine != "eloq") {
opCtx->recoveryUnit()->onCommit(
[this, multikeyPaths, indexMetadataHasChanged](boost::optional<Timestamp>) {
_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();
}
});
if (indexMetadataHasChanged && _infoCache) {
LOG(1) << _ns << ": clearing plan cache - index "
<< _descriptor->keyPattern() << " set to multi key.";
_infoCache->clearQueryCache();
}
});
}

// Keep multikey changes in memory to correctly service later reads using this index.
auto session = OperationContextSession::get(opCtx);
Expand Down
Loading
Loading