diff options
author | Randolph Tan <randolph@mongodb.com> | 2019-10-24 18:27:47 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-24 18:27:47 +0000 |
commit | 75e89cb9cb05c3717ef9929694ec2cbe0873db90 (patch) | |
tree | d025e3a1c2e4a66592e8060e498a5f6876c21292 /src/mongo | |
parent | bc3412923e5747c67261cf31d28e54028127447d (diff) | |
download | mongo-75e89cb9cb05c3717ef9929694ec2cbe0873db90.tar.gz |
SERVER-42737 Make secondary reads in ShardServerCatalogCacheLoader block behind the PBW lock
(cherry picked from commit e0f6fdab23da872d9cf8a93b88c2332ba45041c0)
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/db_raii.cpp | 21 | ||||
-rw-r--r-- | src/mongo/db/db_raii.h | 15 | ||||
-rw-r--r-- | src/mongo/db/s/shard_server_catalog_cache_loader.cpp | 7 |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp index fd04dac348d..2335603d380 100644 --- a/src/mongo/db/db_raii.cpp +++ b/src/mongo/db/db_raii.cpp @@ -46,6 +46,12 @@ namespace { const boost::optional<int> kDoNotChangeProfilingLevel = boost::none; +// TODO: SERVER-44105 remove +// If set to false, secondary reads should wait behind the PBW lock. +// Does nothing if gAllowSecondaryReadsDuringBatchApplication setting is false. +const auto allowSecondaryReadsDuringBatchApplication_DONT_USE = + OperationContext::declareDecoration<boost::optional<bool>>(); + } // namespace AutoStatsTracker::AutoStatsTracker(OperationContext* opCtx, @@ -92,6 +98,7 @@ AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx, // Don't take the ParallelBatchWriterMode lock when the server parameter is set and our // storage engine supports snapshot reads. if (gAllowSecondaryReadsDuringBatchApplication.load() && + allowSecondaryReadsDuringBatchApplication_DONT_USE(opCtx).value_or(true) && opCtx->getServiceContext()->getStorageEngine()->supportsReadConcernSnapshot()) { _shouldNotConflictWithSecondaryBatchApplicationBlock.emplace(opCtx->lockState()); } @@ -386,4 +393,18 @@ LockMode getLockModeForQuery(OperationContext* opCtx, const boost::optional<Name return MODE_IS; } +BlockSecondaryReadsDuringBatchApplication_DONT_USE:: + BlockSecondaryReadsDuringBatchApplication_DONT_USE(OperationContext* opCtx) + : _opCtx(opCtx) { + auto allowSecondaryReads = &allowSecondaryReadsDuringBatchApplication_DONT_USE(opCtx); + allowSecondaryReads->swap(_originalSettings); + *allowSecondaryReads = false; +} + +BlockSecondaryReadsDuringBatchApplication_DONT_USE:: + ~BlockSecondaryReadsDuringBatchApplication_DONT_USE() { + auto allowSecondaryReads = &allowSecondaryReadsDuringBatchApplication_DONT_USE(_opCtx); + allowSecondaryReads->swap(_originalSettings); +} + } // namespace mongo diff --git a/src/mongo/db/db_raii.h b/src/mongo/db/db_raii.h index f5497c6f3a1..940e13c1f6f 100644 --- a/src/mongo/db/db_raii.h +++ b/src/mongo/db/db_raii.h @@ -259,4 +259,19 @@ private: PrepareConflictBehavior _originalValue; }; +/** + * TODO: SERVER-44105 remove + * RAII type for letting secondary reads to block behind the PBW lock. + * Note: Do not add additional usage. This is only temporary for ease of backport. + */ +struct BlockSecondaryReadsDuringBatchApplication_DONT_USE { +public: + BlockSecondaryReadsDuringBatchApplication_DONT_USE(OperationContext* opCtx); + ~BlockSecondaryReadsDuringBatchApplication_DONT_USE(); + +private: + OperationContext* _opCtx{nullptr}; + boost::optional<bool> _originalSettings; +}; + } // namespace mongo diff --git a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp index 142b7d3e69f..dec279a747f 100644 --- a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp +++ b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp @@ -34,6 +34,7 @@ #include "mongo/db/s/shard_server_catalog_cache_loader.h" #include "mongo/db/client.h" +#include "mongo/db/db_raii.h" #include "mongo/db/operation_context.h" #include "mongo/db/operation_context_group.h" #include "mongo/db/read_concern.h" @@ -575,6 +576,12 @@ void ShardServerCatalogCacheLoader::_runSecondaryGetChunksSince( forcePrimaryCollectionRefreshAndWaitForReplication(opCtx, nss); // Read the local metadata. + + // Disallow reading on an older snapshot because this relies on being able to read the + // side effects of writes during secondary replication after being signalled from the + // CollectionVersionLogOpHandler. + BlockSecondaryReadsDuringBatchApplication_DONT_USE secondaryReadsBlockBehindReplication(opCtx); + auto swCollAndChunks = _getCompletePersistedMetadataForSecondarySinceVersion(opCtx, nss, catalogCacheSinceVersion); callbackFn(opCtx, std::move(swCollAndChunks)); |