diff options
5 files changed, 17 insertions, 24 deletions
diff --git a/jstests/noPassthrough/validate_multikey_compound.js b/jstests/noPassthrough/validate_multikey_compound.js index cc0f3890c52..11e2a0a551a 100644 --- a/jstests/noPassthrough/validate_multikey_compound.js +++ b/jstests/noPassthrough/validate_multikey_compound.js @@ -70,9 +70,9 @@ assert(result.indexDetails.c_hashed.valid, tojson(result)); // Check multikey index. assert.eq(6, result.keysPerIndex.a_1_b_1, tojson(result)); -assert(result.indexDetails.a_1_b_1.valid, tojson(result)); +assert(!result.indexDetails.a_1_b_1.valid, tojson(result)); -assert(result.valid, tojson(result)); +assert(!result.valid, tojson(result)); -rst.stopSet(); +rst.stopSet(/*signal=*/undefined, /*forRestart=*/undefined, {skipValidation: true}); })(); diff --git a/jstests/noPassthrough/validate_multikey_restart.js b/jstests/noPassthrough/validate_multikey_restart.js index 9d717fe19fc..fb78e999bdd 100644 --- a/jstests/noPassthrough/validate_multikey_restart.js +++ b/jstests/noPassthrough/validate_multikey_restart.js @@ -63,9 +63,9 @@ assert(result.indexDetails.b_hashed.valid, tojson(result)); // Check multikey index. assert.eq(3, result.keysPerIndex.a_1, tojson(result)); -assert(result.indexDetails.a_1.valid, tojson(result)); +assert(!result.indexDetails.a_1.valid, tojson(result)); -assert(result.valid, tojson(result)); +assert(!result.valid, tojson(result)); -rst.stopSet(); +rst.stopSet(/*signal=*/undefined, /*forRestart=*/undefined, {skipValidation: true}); })(); diff --git a/jstests/noPassthrough/validate_multikey_stepdown.js b/jstests/noPassthrough/validate_multikey_stepdown.js index 3c2a04632bd..e1ed4802dd2 100644 --- a/jstests/noPassthrough/validate_multikey_stepdown.js +++ b/jstests/noPassthrough/validate_multikey_stepdown.js @@ -120,9 +120,9 @@ assert(result.indexDetails._id_.valid, tojson(result)); // Check geo index. assert.lt(1, result.keysPerIndex.geo_2dsphere, tojson(result)); -assert(result.indexDetails.geo_2dsphere.valid, tojson(result)); +assert(!result.indexDetails.geo_2dsphere.valid, tojson(result)); -assert(result.valid, tojson(result)); +assert(!result.valid, tojson(result)); -rst.stopSet(); +rst.stopSet(/*signal=*/undefined, /*forRestart=*/undefined, {skipValidation: true}); })(); diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.cpp b/src/mongo/db/catalog/index_catalog_entry_impl.cpp index c20bc831c88..7ba3a22f1e4 100644 --- a/src/mongo/db/catalog/index_catalog_entry_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_entry_impl.cpp @@ -78,11 +78,10 @@ IndexCatalogEntryImpl::IndexCatalogEntryImpl(OperationContext* const opCtx, { stdx::lock_guard<Latch> lk(_indexMultikeyPathsMutex); - const bool isMultikey = _catalogIsMultikey(opCtx, collection, &_indexMultikeyPathsForWrite); + const bool isMultikey = _catalogIsMultikey(opCtx, collection, &_indexMultikeyPathsForRead); _isMultikeyForRead.store(isMultikey); _isMultikeyForWrite.store(isMultikey); - _indexMultikeyPathsForRead = _indexMultikeyPathsForWrite; - _indexTracksMultikeyPathsInCatalog = !_indexMultikeyPathsForWrite.empty(); + _indexTracksMultikeyPathsInCatalog = !_indexMultikeyPathsForRead.empty(); } auto nss = DurableCatalog::get(opCtx)->getEntry(_catalogId).nss; @@ -185,12 +184,12 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx, if (_indexTracksMultikeyPathsInCatalog) { stdx::lock_guard<Latch> lk(_indexMultikeyPathsMutex); - invariant(multikeyPaths.size() == _indexMultikeyPathsForWrite.size()); + invariant(multikeyPaths.size() == _indexMultikeyPathsForRead.size()); bool newPathIsMultikey = false; for (size_t i = 0; i < multikeyPaths.size(); ++i) { - if (!std::includes(_indexMultikeyPathsForWrite[i].begin(), - _indexMultikeyPathsForWrite[i].end(), + if (!std::includes(_indexMultikeyPathsForRead[i].begin(), + _indexMultikeyPathsForRead[i].end(), multikeyPaths[i].begin(), multikeyPaths[i].end())) { // If 'multikeyPaths' contains a new path component that causes this index to be @@ -275,11 +274,10 @@ void IndexCatalogEntryImpl::forceSetMultikey(OperationContext* const opCtx, { stdx::lock_guard<Latch> lk(_indexMultikeyPathsMutex); const bool isMultikeyInCatalog = - _catalogIsMultikey(opCtx, coll, &_indexMultikeyPathsForWrite); + _catalogIsMultikey(opCtx, coll, &_indexMultikeyPathsForRead); _isMultikeyForRead.store(isMultikeyInCatalog); _isMultikeyForWrite.store(isMultikeyInCatalog); - _indexMultikeyPathsForRead = _indexMultikeyPathsForWrite; - _indexTracksMultikeyPathsInCatalog = !_indexMultikeyPathsForWrite.empty(); + _indexTracksMultikeyPathsInCatalog = !_indexMultikeyPathsForRead.empty(); } // Since multikey metadata has changed, invalidate the query cache. @@ -396,7 +394,6 @@ void IndexCatalogEntryImpl::_catalogSetMultikey(OperationContext* opCtx, _isMultikeyForRead.store(true); if (_indexTracksMultikeyPathsInCatalog) { stdx::lock_guard<Latch> lk(_indexMultikeyPathsMutex); - _indexMultikeyPathsForRead = _indexMultikeyPathsForWrite; for (size_t i = 0; i < multikeyPaths.size(); ++i) { _indexMultikeyPathsForRead[i].insert(multikeyPaths[i].begin(), multikeyPaths[i].end()); } @@ -415,8 +412,6 @@ void IndexCatalogEntryImpl::_catalogSetMultikey(OperationContext* opCtx, // transaction successfully commits. Only after this point may a writer optimize out // flipping multikey. _isMultikeyForWrite.store(true); - stdx::lock_guard<Latch> lk(_indexMultikeyPathsMutex); - _indexMultikeyPathsForWrite = _indexMultikeyPathsForRead; }); } diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.h b/src/mongo/db/catalog/index_catalog_entry_impl.h index 13bd86209fe..6a6f84ff3aa 100644 --- a/src/mongo/db/catalog/index_catalog_entry_impl.h +++ b/src/mongo/db/catalog/index_catalog_entry_impl.h @@ -248,7 +248,7 @@ private: // this point, future writers do not need to update the catalog. mutable AtomicWord<bool> _isMultikeyForWrite; - // Controls concurrent access to '_indexMultikeyPathsForRead' and '_indexMultikeyPathsForWrite'. + // Controls concurrent access to '_indexMultikeyPathsForRead'. // We acquire this mutex rather than the RESOURCE_METADATA lock as a performance optimization // so that it is cheaper to detect whether there is actually any path-level multikey // information to update or not. @@ -263,8 +263,6 @@ private: // causes the index to be multikey. mutable MultikeyPaths _indexMultikeyPathsForRead; // May include paths not committed to catalog. - mutable MultikeyPaths - _indexMultikeyPathsForWrite; // Paths in catalog updated by a transaction commit. // The earliest snapshot that is allowed to read this index. boost::optional<Timestamp> _minVisibleSnapshot; |