summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Polato <paolo.polato@mongodb.com>2022-07-19 19:41:33 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-19 20:33:36 +0000
commit9743d69c7dbc92fd5abcf9c799daff89e30ca233 (patch)
treed4e434bc99a562fb841883c42b4407ab3b1cf9a4
parentd894ba136c7e3fbd7c979aad6128313ea690ec9c (diff)
downloadmongo-9743d69c7dbc92fd5abcf9c799daff89e30ca233.tar.gz
SERVER-68083 Allow the acquisition of a CriticalSection on view namespaces by secondary nodes
-rw-r--r--src/mongo/db/s/shard_server_op_observer.cpp40
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);