diff options
Diffstat (limited to 'src/mongo/db/repl/replication_coordinator_impl.cpp')
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index c6fb608d76b..a6a4d0084bb 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -48,6 +48,7 @@ #include "mongo/db/logical_time.h" #include "mongo/db/logical_time_validator.h" #include "mongo/db/operation_context_noop.h" +#include "mongo/db/repl/always_allow_non_local_writes.h" #include "mongo/db/repl/check_quorum_for_config_change.h" #include "mongo/db/repl/data_replicator_external_state_initial_sync.h" #include "mongo/db/repl/elect_cmd_runner.h" @@ -105,9 +106,6 @@ using NextAction = Fetcher::NextAction; namespace { const char kLocalDB[] = "local"; -// Overrides _canAcceptLocalWrites for the decorated OperationContext. -const OperationContext::Decoration<bool> alwaysAllowNonLocalWrites = - OperationContext::declareDecoration<bool>(); MONGO_EXPORT_SERVER_PARAMETER(numInitialSyncAttempts, int, 10); @@ -130,31 +128,6 @@ MONGO_INITIALIZER(periodicNoopIntervalSecs)(InitializerContext*) { return Status::OK(); } - -/** - * Allows non-local writes despite _canAcceptNonlocalWrites being false on a single OperationContext - * while in scope. - * - * Resets to original value when leaving scope so it is safe to nest. - */ -class AllowNonLocalWritesBlock { - MONGO_DISALLOW_COPYING(AllowNonLocalWritesBlock); - -public: - AllowNonLocalWritesBlock(OperationContext* opCtx) - : _opCtx(opCtx), _initialState(alwaysAllowNonLocalWrites(_opCtx)) { - alwaysAllowNonLocalWrites(_opCtx) = true; - } - - ~AllowNonLocalWritesBlock() { - alwaysAllowNonLocalWrites(_opCtx) = _initialState; - } - -private: - OperationContext* const _opCtx; - const bool _initialState; -}; - void lockAndCall(stdx::unique_lock<stdx::mutex>* lk, const stdx::function<void()>& fn) { if (!lk->owns_lock()) { lk->lock(); @@ -2009,7 +1982,7 @@ bool ReplicationCoordinatorImpl::canAcceptWritesForDatabase_UNSAFE(OperationCont // accept writes. Similarly, writes are always permitted to the "local" database. Finally, // in the event that a node is started with --slave and --master, we allow writes unless the // master/slave system has set the replAllDead flag. - if (_canAcceptNonLocalWrites.loadRelaxed() || alwaysAllowNonLocalWrites(*opCtx)) { + if (_canAcceptNonLocalWrites.loadRelaxed() || alwaysAllowNonLocalWrites(opCtx)) { return true; } if (dbName == kLocalDB) { @@ -2038,7 +2011,7 @@ bool ReplicationCoordinatorImpl::canAcceptWritesFor_UNSAFE(OperationContext* opC // If we can accept non local writes (ie we're PRIMARY) then we must not be in ROLLBACK. // This check is redundant of the check of _memberState below, but since this can be checked // without locking, we do it as an optimization. - if (_canAcceptNonLocalWrites.loadRelaxed() || alwaysAllowNonLocalWrites(*opCtx)) { + if (_canAcceptNonLocalWrites.loadRelaxed() || alwaysAllowNonLocalWrites(opCtx)) { return true; } |