summaryrefslogtreecommitdiff
path: root/src/mongo/db/user_write_block_mode_op_observer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/user_write_block_mode_op_observer.cpp')
-rw-r--r--src/mongo/db/user_write_block_mode_op_observer.cpp127
1 files changed, 57 insertions, 70 deletions
diff --git a/src/mongo/db/user_write_block_mode_op_observer.cpp b/src/mongo/db/user_write_block_mode_op_observer.cpp
index c024231909d..ab043ce7f9e 100644
--- a/src/mongo/db/user_write_block_mode_op_observer.cpp
+++ b/src/mongo/db/user_write_block_mode_op_observer.cpp
@@ -55,60 +55,19 @@ void UserWriteBlockModeOpObserver::onInserts(OperationContext* opCtx,
bool fromMigrate) {
_checkWriteAllowed(opCtx, nss);
- if (nss == NamespaceString::kUserWritesCriticalSectionsNamespace) {
+ if (nss == NamespaceString::kUserWritesCriticalSectionsNamespace &&
+ !user_writes_recoverable_critical_section_util::inRecoveryMode(opCtx)) {
for (auto it = first; it != last; ++it) {
const auto& insertedDoc = it->doc;
- auto replCoord = repl::ReplicationCoordinator::get(opCtx);
- if (!replCoord->isReplEnabled() ||
- (!replCoord->getMemberState().recovering() &&
- !replCoord->getMemberState().rollback())) {
- const auto collCSDoc = UserWriteBlockingCriticalSectionDocument::parse(
- IDLParserErrorContext("UserWriteBlockOpObserver"), insertedDoc);
- opCtx->recoveryUnit()->onCommit(
- [opCtx,
- blockShardedDDL = collCSDoc.getBlockNewUserShardedDDL(),
- blockWrites = collCSDoc.getBlockUserWrites(),
- insertedNss = collCSDoc.getNss()](boost::optional<Timestamp>) {
- invariant(insertedNss.isEmpty());
- boost::optional<Lock::GlobalLock> globalLockIfNotPrimary;
- if (!isStandaloneOrPrimary(opCtx)) {
- globalLockIfNotPrimary.emplace(opCtx, MODE_IX);
- }
-
- if (blockShardedDDL) {
- GlobalUserWriteBlockState::get(opCtx)->enableUserShardedDDLBlocking(
- opCtx);
- }
-
- if (blockWrites) {
- GlobalUserWriteBlockState::get(opCtx)->enableUserWriteBlocking(opCtx);
- }
- });
- }
- }
- }
-}
-
-void UserWriteBlockModeOpObserver::onUpdate(OperationContext* opCtx,
- const OplogUpdateEntryArgs& args) {
- _checkWriteAllowed(opCtx, args.nss);
-
- if (args.nss == NamespaceString::kUserWritesCriticalSectionsNamespace) {
- auto replCoord = repl::ReplicationCoordinator::get(opCtx);
- if (!replCoord->isReplEnabled() ||
- (!replCoord->getMemberState().recovering() &&
- !replCoord->getMemberState().rollback())) {
const auto collCSDoc = UserWriteBlockingCriticalSectionDocument::parse(
- IDLParserErrorContext("UserWriteBlockOpObserver"), args.updateArgs->updatedDoc);
-
+ IDLParserErrorContext("UserWriteBlockOpObserver"), insertedDoc);
opCtx->recoveryUnit()->onCommit(
[opCtx,
- updatedNss = collCSDoc.getNss(),
blockShardedDDL = collCSDoc.getBlockNewUserShardedDDL(),
blockWrites = collCSDoc.getBlockUserWrites(),
insertedNss = collCSDoc.getNss()](boost::optional<Timestamp>) {
- invariant(updatedNss.isEmpty());
+ invariant(insertedNss.isEmpty());
boost::optional<Lock::GlobalLock> globalLockIfNotPrimary;
if (!isStandaloneOrPrimary(opCtx)) {
globalLockIfNotPrimary.emplace(opCtx, MODE_IX);
@@ -116,20 +75,52 @@ void UserWriteBlockModeOpObserver::onUpdate(OperationContext* opCtx,
if (blockShardedDDL) {
GlobalUserWriteBlockState::get(opCtx)->enableUserShardedDDLBlocking(opCtx);
- } else {
- GlobalUserWriteBlockState::get(opCtx)->disableUserShardedDDLBlocking(opCtx);
}
if (blockWrites) {
GlobalUserWriteBlockState::get(opCtx)->enableUserWriteBlocking(opCtx);
- } else {
- GlobalUserWriteBlockState::get(opCtx)->disableUserWriteBlocking(opCtx);
}
});
}
}
}
+void UserWriteBlockModeOpObserver::onUpdate(OperationContext* opCtx,
+ const OplogUpdateEntryArgs& args) {
+ _checkWriteAllowed(opCtx, args.nss);
+
+ if (args.nss == NamespaceString::kUserWritesCriticalSectionsNamespace &&
+ !user_writes_recoverable_critical_section_util::inRecoveryMode(opCtx)) {
+ const auto collCSDoc = UserWriteBlockingCriticalSectionDocument::parse(
+ IDLParserErrorContext("UserWriteBlockOpObserver"), args.updateArgs->updatedDoc);
+
+ opCtx->recoveryUnit()->onCommit(
+ [opCtx,
+ updatedNss = collCSDoc.getNss(),
+ blockShardedDDL = collCSDoc.getBlockNewUserShardedDDL(),
+ blockWrites = collCSDoc.getBlockUserWrites(),
+ insertedNss = collCSDoc.getNss()](boost::optional<Timestamp>) {
+ invariant(updatedNss.isEmpty());
+ boost::optional<Lock::GlobalLock> globalLockIfNotPrimary;
+ if (!isStandaloneOrPrimary(opCtx)) {
+ globalLockIfNotPrimary.emplace(opCtx, MODE_IX);
+ }
+
+ if (blockShardedDDL) {
+ GlobalUserWriteBlockState::get(opCtx)->enableUserShardedDDLBlocking(opCtx);
+ } else {
+ GlobalUserWriteBlockState::get(opCtx)->disableUserShardedDDLBlocking(opCtx);
+ }
+
+ if (blockWrites) {
+ GlobalUserWriteBlockState::get(opCtx)->enableUserWriteBlocking(opCtx);
+ } else {
+ GlobalUserWriteBlockState::get(opCtx)->disableUserWriteBlocking(opCtx);
+ }
+ });
+ }
+}
+
void UserWriteBlockModeOpObserver::aboutToDelete(OperationContext* opCtx,
NamespaceString const& nss,
const UUID& uuid,
@@ -147,30 +138,26 @@ void UserWriteBlockModeOpObserver::onDelete(OperationContext* opCtx,
const OplogDeleteEntryArgs& args) {
_checkWriteAllowed(opCtx, nss);
- if (nss == NamespaceString::kUserWritesCriticalSectionsNamespace) {
+ if (nss == NamespaceString::kUserWritesCriticalSectionsNamespace &&
+ !user_writes_recoverable_critical_section_util::inRecoveryMode(opCtx)) {
auto& documentId = documentIdDecoration(opCtx);
invariant(!documentId.isEmpty());
- auto replCoord = repl::ReplicationCoordinator::get(opCtx);
- if (!replCoord->isReplEnabled() ||
- (!replCoord->getMemberState().recovering() &&
- !replCoord->getMemberState().rollback())) {
- const auto& deletedDoc = documentId;
- const auto collCSDoc = UserWriteBlockingCriticalSectionDocument::parse(
- IDLParserErrorContext("UserWriteBlockOpObserver"), deletedDoc);
-
- opCtx->recoveryUnit()->onCommit(
- [opCtx, deletedNss = collCSDoc.getNss()](boost::optional<Timestamp>) {
- invariant(deletedNss.isEmpty());
- boost::optional<Lock::GlobalLock> globalLockIfNotPrimary;
- if (!isStandaloneOrPrimary(opCtx)) {
- globalLockIfNotPrimary.emplace(opCtx, MODE_IX);
- }
-
- GlobalUserWriteBlockState::get(opCtx)->disableUserShardedDDLBlocking(opCtx);
- GlobalUserWriteBlockState::get(opCtx)->disableUserWriteBlocking(opCtx);
- });
- }
+ const auto& deletedDoc = documentId;
+ const auto collCSDoc = UserWriteBlockingCriticalSectionDocument::parse(
+ IDLParserErrorContext("UserWriteBlockOpObserver"), deletedDoc);
+
+ opCtx->recoveryUnit()->onCommit(
+ [opCtx, deletedNss = collCSDoc.getNss()](boost::optional<Timestamp>) {
+ invariant(deletedNss.isEmpty());
+ boost::optional<Lock::GlobalLock> globalLockIfNotPrimary;
+ if (!isStandaloneOrPrimary(opCtx)) {
+ globalLockIfNotPrimary.emplace(opCtx, MODE_IX);
+ }
+
+ GlobalUserWriteBlockState::get(opCtx)->disableUserShardedDDLBlocking(opCtx);
+ GlobalUserWriteBlockState::get(opCtx)->disableUserWriteBlocking(opCtx);
+ });
}
}