summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/shard_server_op_observer.cpp
diff options
context:
space:
mode:
authorTommaso Tocci <tommaso.tocci@mongodb.com>2021-05-13 16:34:00 +0200
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-14 16:37:12 +0000
commitd424434cec79ba3a13166ae4b69794bbd83cc3e0 (patch)
treedf5de406b7109760c16af1bdb5ebd28f6bdfde7c /src/mongo/db/s/shard_server_op_observer.cpp
parent13e28eb1e3a70211038e10afec3b6713fd63f4b8 (diff)
downloadmongo-d424434cec79ba3a13166ae4b69794bbd83cc3e0.tar.gz
SERVER-56910 Skip Recoverable CS opObserver actions during recovery
Diffstat (limited to 'src/mongo/db/s/shard_server_op_observer.cpp')
-rw-r--r--src/mongo/db/s/shard_server_op_observer.cpp81
1 files changed, 48 insertions, 33 deletions
diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp
index 73a842da95c..c1e0e01da88 100644
--- a/src/mongo/db/s/shard_server_op_observer.cpp
+++ b/src/mongo/db/s/shard_server_op_observer.cpp
@@ -274,12 +274,16 @@ void ShardServerOpObserver::onInserts(OperationContext* opCtx,
}
if (nss == NamespaceString::kCollectionCriticalSectionsNamespace) {
- const auto collCSDoc = CollectionCriticalSectionDocument::parse(
- IDLParserErrorContext("ShardServerOpObserver"), insertedDoc);
+ auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ if (!replCoord->isReplEnabled() ||
+ (!replCoord->getMemberState().recovering() &&
+ !replCoord->getMemberState().rollback())) {
+ const auto collCSDoc = CollectionCriticalSectionDocument::parse(
+ IDLParserErrorContext("ShardServerOpObserver"), insertedDoc);
- opCtx->recoveryUnit()->onCommit(
- [opCtx, insertedNss = collCSDoc.getNss()](boost::optional<Timestamp>) {
+ opCtx->recoveryUnit()->onCommit([opCtx, insertedNss = collCSDoc.getNss()](
+ boost::optional<Timestamp>) {
boost::optional<AutoGetCollection> lockCollectionIfNotPrimary;
if (!isStandaloneOrPrimary(opCtx))
lockCollectionIfNotPrimary.emplace(opCtx, insertedNss, MODE_IX);
@@ -289,6 +293,7 @@ void ShardServerOpObserver::onInserts(OperationContext* opCtx,
auto csrLock = CollectionShardingRuntime ::CSRLock::lockExclusive(opCtx, csr);
csr->enterCriticalSectionCatchUpPhase(csrLock);
});
+ }
}
if (metadata && metadata->isSharded()) {
@@ -406,21 +411,26 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE
}
if (args.nss == NamespaceString::kCollectionCriticalSectionsNamespace) {
+ auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ if (!replCoord->isReplEnabled() ||
+ (!replCoord->getMemberState().recovering() &&
+ !replCoord->getMemberState().rollback())) {
- const auto collCSDoc = CollectionCriticalSectionDocument::parse(
- IDLParserErrorContext("ShardServerOpObserver"), args.updateArgs.updatedDoc);
+ const auto collCSDoc = CollectionCriticalSectionDocument::parse(
+ IDLParserErrorContext("ShardServerOpObserver"), args.updateArgs.updatedDoc);
- opCtx->recoveryUnit()->onCommit(
- [opCtx, updatedNss = collCSDoc.getNss()](boost::optional<Timestamp>) {
- boost::optional<AutoGetCollection> lockCollectionIfNotPrimary;
- if (!isStandaloneOrPrimary(opCtx))
- lockCollectionIfNotPrimary.emplace(opCtx, updatedNss, MODE_IX);
+ opCtx->recoveryUnit()->onCommit(
+ [opCtx, updatedNss = collCSDoc.getNss()](boost::optional<Timestamp>) {
+ boost::optional<AutoGetCollection> lockCollectionIfNotPrimary;
+ if (!isStandaloneOrPrimary(opCtx))
+ lockCollectionIfNotPrimary.emplace(opCtx, updatedNss, MODE_IX);
- UninterruptibleLockGuard noInterrupt(opCtx->lockState());
- auto* const csr = CollectionShardingRuntime::get(opCtx, updatedNss);
- auto csrLock = CollectionShardingRuntime ::CSRLock::lockExclusive(opCtx, csr);
- csr->enterCriticalSectionCommitPhase(csrLock);
- });
+ UninterruptibleLockGuard noInterrupt(opCtx->lockState());
+ auto* const csr = CollectionShardingRuntime::get(opCtx, updatedNss);
+ auto csrLock = CollectionShardingRuntime ::CSRLock::lockExclusive(opCtx, csr);
+ csr->enterCriticalSectionCommitPhase(csrLock);
+ });
+ }
}
auto* const csr = CollectionShardingRuntime::get(opCtx, args.nss);
@@ -489,24 +499,29 @@ void ShardServerOpObserver::onDelete(OperationContext* opCtx,
}
if (nss == NamespaceString::kCollectionCriticalSectionsNamespace) {
- const auto deletedNss([&] {
- std::string coll;
- fassert(5514801,
- bsonExtractStringField(
- documentId, CollectionCriticalSectionDocument::kNssFieldName, &coll));
- return NamespaceString(coll);
- }());
-
- opCtx->recoveryUnit()->onCommit([opCtx, deletedNss](boost::optional<Timestamp>) {
- boost::optional<AutoGetCollection> lockCollectionIfNotPrimary;
- if (!isStandaloneOrPrimary(opCtx))
- lockCollectionIfNotPrimary.emplace(opCtx, deletedNss, MODE_IX);
+ auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ if (!replCoord->isReplEnabled() ||
+ (!replCoord->getMemberState().recovering() &&
+ !replCoord->getMemberState().rollback())) {
+ const auto deletedNss([&] {
+ std::string coll;
+ fassert(5514801,
+ bsonExtractStringField(
+ documentId, CollectionCriticalSectionDocument::kNssFieldName, &coll));
+ return NamespaceString(coll);
+ }());
+
+ opCtx->recoveryUnit()->onCommit([opCtx, deletedNss](boost::optional<Timestamp>) {
+ boost::optional<AutoGetCollection> lockCollectionIfNotPrimary;
+ if (!isStandaloneOrPrimary(opCtx))
+ lockCollectionIfNotPrimary.emplace(opCtx, deletedNss, MODE_IX);
- UninterruptibleLockGuard noInterrupt(opCtx->lockState());
- auto* const csr = CollectionShardingRuntime::get(opCtx, deletedNss);
- auto csrLock = CollectionShardingRuntime::CSRLock::lockExclusive(opCtx, csr);
- csr->exitCriticalSection(csrLock);
- });
+ UninterruptibleLockGuard noInterrupt(opCtx->lockState());
+ auto* const csr = CollectionShardingRuntime::get(opCtx, deletedNss);
+ auto csrLock = CollectionShardingRuntime::CSRLock::lockExclusive(opCtx, csr);
+ csr->exitCriticalSection(csrLock);
+ });
+ }
}
}