diff options
Diffstat (limited to 'src/mongo/db/repl/transaction_oplog_application.cpp')
| -rw-r--r-- | src/mongo/db/repl/transaction_oplog_application.cpp | 50 |
1 files changed, 9 insertions, 41 deletions
diff --git a/src/mongo/db/repl/transaction_oplog_application.cpp b/src/mongo/db/repl/transaction_oplog_application.cpp index 20d8459a18b..af8fa188671 100644 --- a/src/mongo/db/repl/transaction_oplog_application.cpp +++ b/src/mongo/db/repl/transaction_oplog_application.cpp @@ -33,13 +33,11 @@ #include "mongo/db/repl/transaction_oplog_application.h" -#include "mongo/db/catalog/document_validation.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/commands/txn_cmds_gen.h" -#include "mongo/db/concurrency/exception_util.h" +#include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/index_builds_coordinator.h" -#include "mongo/db/op_observer.h" #include "mongo/db/repl/apply_ops.h" #include "mongo/db/repl/storage_interface_impl.h" #include "mongo/db/repl/timestamp_block.h" @@ -90,26 +88,9 @@ Status _applyOperationsForTransaction(OperationContext* opCtx, } } catch (const DBException& ex) { // Ignore NamespaceNotFound errors if we are in initial sync or recovering mode. - // During recovery we reconsutuct prepared transactions at the end after applying all - // the oplogs, so 'NamespaceNotFound' error shouldn't be hit whether it is a stable or - // unstable recovery. However we have some scenarios when this error should be skipped: - // 1- This code path can be called while applying commit oplog during unstable recovery - // when 'startupRecoveryForRestore' is set. - // 2- During selective backup: - // - During restore when 'recoverFromOplogAsStandalone' is set which is usually be - // done in a stable recovery mode. - // - After the restore finished as the standalone node started with the flag - // 'takeUnstableCheckpointOnShutdown' so after restarting the node as a replica - // set member it will go through unstable recovery. const bool ignoreException = ex.code() == ErrorCodes::NamespaceNotFound && (oplogApplicationMode == repl::OplogApplication::Mode::kInitialSync || - repl::OplogApplication::inRecovering(oplogApplicationMode)); - - if (ex.code() == ErrorCodes::NamespaceNotFound && - oplogApplicationMode == repl::OplogApplication::Mode::kStableRecovering) { - repl::OplogApplication::checkOnOplogFailureForRecovery( - opCtx, op.getNss(), redact(op.toBSONForLogging()), redact(ex)); - } + oplogApplicationMode == repl::OplogApplication::Mode::kRecovering); if (!ignoreException) { LOGV2_DEBUG( @@ -149,7 +130,7 @@ Status _applyTransactionFromOplogChain(OperationContext* opCtx, repl::OplogApplication::Mode mode, Timestamp commitTimestamp, Timestamp durableTimestamp) { - invariant(repl::OplogApplication::inRecovering(mode)); + invariant(mode == repl::OplogApplication::Mode::kRecovering); auto ops = readTransactionOperationsFromOplogChain(opCtx, entry, {}); @@ -208,8 +189,7 @@ Status applyCommitTransaction(OperationContext* opCtx, invariant(commitCommand.getCommitTimestamp()); switch (mode) { - case repl::OplogApplication::Mode::kUnstableRecovering: - case repl::OplogApplication::Mode::kStableRecovering: { + case repl::OplogApplication::Mode::kRecovering: { return _applyTransactionFromOplogChain(opCtx, entry, mode, @@ -256,8 +236,7 @@ Status applyAbortTransaction(OperationContext* opCtx, const OplogEntry& entry, repl::OplogApplication::Mode mode) { switch (mode) { - case repl::OplogApplication::Mode::kUnstableRecovering: - case repl::OplogApplication::Mode::kStableRecovering: { + case repl::OplogApplication::Mode::kRecovering: { // We don't put transactions into the prepare state until the end of recovery, // so there is no transaction to abort. return Status::OK(); @@ -409,7 +388,7 @@ Status _applyPrepareTransaction(OperationContext* opCtx, // The prepare time of the transaction is set explicitly below. auto ops = readTransactionOperationsFromOplogChain(opCtx, entry, {}); - if (repl::OplogApplication::inRecovering(mode) || + if (mode == repl::OplogApplication::Mode::kRecovering || mode == repl::OplogApplication::Mode::kInitialSync) { // We might replay a prepared transaction behind oldest timestamp. Note that since this is // scoped to the storage transaction, and readTransactionOperationsFromOplogChain implicitly @@ -486,7 +465,7 @@ Status _applyPrepareTransaction(OperationContext* opCtx, // Set this in case the application of any ops need to use the prepare timestamp of this // transaction. It should be cleared automatically when the transaction finishes. - if (repl::OplogApplication::inRecovering(mode) || + if (mode == repl::OplogApplication::Mode::kRecovering || mode == repl::OplogApplication::Mode::kInitialSync) { txnParticipant.setPrepareOpTimeForRecovery(opCtx, entry.getOpTime()); } @@ -519,11 +498,6 @@ Status _applyPrepareTransaction(OperationContext* opCtx, } txnParticipant.prepareTransaction(opCtx, entry.getOpTime()); - - auto opObserver = opCtx->getServiceContext()->getOpObserver(); - invariant(opObserver); - opObserver->onTransactionPrepareNonPrimary(opCtx, ops, entry.getOpTime()); - // Prepare transaction success. abortOnError.dismiss(); @@ -539,8 +513,6 @@ void _reconstructPreparedTransaction(OperationContext* opCtx, const OplogEntry& prepareEntry, repl::OplogApplication::Mode mode) { repl::UnreplicatedWritesBlock uwb(opCtx); - // The transaction may have been prepared originally with document validation bypassed. - DisableDocumentValidation validationDisabler(opCtx); // Snapshot transaction can never conflict with the PBWM lock. opCtx->lockState()->setShouldConflictWithSecondaryBatchApplication(false); @@ -571,8 +543,7 @@ Status applyPrepareTransaction(OperationContext* opCtx, const OplogEntry& entry, repl::OplogApplication::Mode mode) { switch (mode) { - case repl::OplogApplication::Mode::kUnstableRecovering: - case repl::OplogApplication::Mode::kStableRecovering: { + case repl::OplogApplication::Mode::kRecovering: { if (!serverGlobalParams.enableMajorityReadConcern) { LOGV2_ERROR( 21850, @@ -642,10 +613,7 @@ void reconstructPreparedTransactions(OperationContext* opCtx, repl::OplogApplica AlternativeClientRegion acr(newClient); const auto newOpCtx = cc().makeOperationContext(); - // Ignore interruptions while reconstructing prepared transactions, so that we do not - // fassert and crash due to interruptions inside this call. - newOpCtx->runWithoutInterruptionExceptAtGlobalShutdown( - [&] { _reconstructPreparedTransaction(newOpCtx.get(), prepareOplogEntry, mode); }); + _reconstructPreparedTransaction(newOpCtx.get(), prepareOplogEntry, mode); } } } |
