diff options
-rw-r--r-- | src/mongo/db/s/shard_server_op_observer.cpp | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp index 661be4e079d..9179504e4f2 100644 --- a/src/mongo/db/s/shard_server_op_observer.cpp +++ b/src/mongo/db/s/shard_server_op_observer.cpp @@ -285,19 +285,21 @@ void ShardServerOpObserver::onInserts(OperationContext* opCtx, !recoverable_critical_section_util::inRecoveryMode(opCtx)) { const auto collCSDoc = CollectionCriticalSectionDocument::parse( IDLParserErrorContext("ShardServerOpObserver"), insertedDoc); - opCtx->recoveryUnit()->onCommit( - [opCtx, - insertedNss = collCSDoc.getNss(), - reason = collCSDoc.getReason().getOwned()](boost::optional<Timestamp>) { - boost::optional<AutoGetCollection> lockCollectionIfNotPrimary; - if (!isStandaloneOrPrimary(opCtx)) - lockCollectionIfNotPrimary.emplace(opCtx, insertedNss, MODE_IX); - - UninterruptibleLockGuard noInterrupt(opCtx->lockState()); - auto* const csr = CollectionShardingRuntime::get(opCtx, insertedNss); - auto csrLock = CollectionShardingRuntime ::CSRLock::lockExclusive(opCtx, csr); - csr->enterCriticalSectionCatchUpPhase(csrLock, reason); - }); + opCtx->recoveryUnit()->onCommit([opCtx, + insertedNss = collCSDoc.getNss(), + reason = collCSDoc.getReason().getOwned()]( + boost::optional<Timestamp>) { + boost::optional<AutoGetCollection> lockCollectionIfNotPrimary; + if (!isStandaloneOrPrimary(opCtx)) { + lockCollectionIfNotPrimary.emplace( + opCtx, insertedNss, MODE_IX, AutoGetCollectionViewMode::kViewsPermitted); + } + + UninterruptibleLockGuard noInterrupt(opCtx->lockState()); + auto* const csr = CollectionShardingRuntime::get(opCtx, insertedNss); + auto csrLock = CollectionShardingRuntime ::CSRLock::lockExclusive(opCtx, csr); + csr->enterCriticalSectionCatchUpPhase(csrLock, reason); + }); } if (metadata && metadata->isSharded()) { @@ -430,8 +432,10 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE [opCtx, updatedNss = collCSDoc.getNss(), reason = collCSDoc.getReason().getOwned()]( boost::optional<Timestamp>) { boost::optional<AutoGetCollection> lockCollectionIfNotPrimary; - if (!isStandaloneOrPrimary(opCtx)) - lockCollectionIfNotPrimary.emplace(opCtx, updatedNss, MODE_IX); + if (!isStandaloneOrPrimary(opCtx)) { + lockCollectionIfNotPrimary.emplace( + opCtx, updatedNss, MODE_IX, AutoGetCollectionViewMode::kViewsPermitted); + } UninterruptibleLockGuard noInterrupt(opCtx->lockState()); auto* const csr = CollectionShardingRuntime::get(opCtx, updatedNss); @@ -524,8 +528,10 @@ void ShardServerOpObserver::onDelete(OperationContext* opCtx, [opCtx, deletedNss = collCSDoc.getNss(), reason = collCSDoc.getReason().getOwned()]( boost::optional<Timestamp>) { boost::optional<AutoGetCollection> lockCollectionIfNotPrimary; - if (!isStandaloneOrPrimary(opCtx)) - lockCollectionIfNotPrimary.emplace(opCtx, deletedNss, MODE_IX); + if (!isStandaloneOrPrimary(opCtx)) { + lockCollectionIfNotPrimary.emplace( + opCtx, deletedNss, MODE_IX, AutoGetCollectionViewMode::kViewsPermitted); + } UninterruptibleLockGuard noInterrupt(opCtx->lockState()); auto* const csr = CollectionShardingRuntime::get(opCtx, deletedNss); |