diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2019-05-16 17:13:35 -0400 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2019-05-22 16:42:49 -0400 |
commit | 5a3bc788f03b02fe121bcf1f81528a74c3114ced (patch) | |
tree | 3d46b1ff284913d38c8d7ee9723a3648666e21dc | |
parent | 7ac68bb3418650654599b6ffb768daf4bacc979d (diff) | |
download | mongo-5a3bc788f03b02fe121bcf1f81528a74c3114ced.tar.gz |
SERVER-41188 Remove support for explicit prepare oplog entry on secondary
-rw-r--r-- | jstests/replsets/initial_sync_fetch_from_oldest_active_transaction_timestamp.js | 4 | ||||
-rw-r--r-- | src/mongo/db/auth/role_graph_update.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/commands/txn_cmds.idl | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_entry.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_entry.h | 1 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_recovery_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/rollback_impl.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/repl/session_update_tracker.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/repl/transaction_oplog_application.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/repl/transaction_oplog_application.h | 2 |
11 files changed, 15 insertions, 56 deletions
diff --git a/jstests/replsets/initial_sync_fetch_from_oldest_active_transaction_timestamp.js b/jstests/replsets/initial_sync_fetch_from_oldest_active_transaction_timestamp.js index cfc5a252646..a15f5290ea6 100644 --- a/jstests/replsets/initial_sync_fetch_from_oldest_active_transaction_timestamp.js +++ b/jstests/replsets/initial_sync_fetch_from_oldest_active_transaction_timestamp.js @@ -6,7 +6,7 @@ * * To make sure that it is applying from the correct point, the test prepares a transaction before * the beginFetchingTimestamp and commits it before the beginApplyingTimestamp. Since the - * transaction is not active by the time initial sync begins, its prepareTransaction oplog entry + * transaction is not active by the time initial sync begins, its prepare oplog entry * won't be fetched during oplog application and trying to apply the commitTransaction oplog entry * will cause initial sync to fail. * @@ -71,7 +71,7 @@ // Commit the first transaction so that we have an operation that is fetched during initial sync // but should not be applied. If this is applied, initial sync will fail because while trying to - // apply the commitTransaction oplog entry, it will fail to get the prepareTransaction oplog + // apply the commitTransaction oplog entry, it will fail to get the prepare oplog // entry since its optime is before the beginFetchingTimestamp. Doing another operation will // also cause the beginApplyingTimestamp to be different from the beginFetchingTimestamp. Note // that since the beginApplyingTimestamp is the timestamp after which operations are applied diff --git a/src/mongo/db/auth/role_graph_update.cpp b/src/mongo/db/auth/role_graph_update.cpp index b5956069f85..02c89f36bd7 100644 --- a/src/mongo/db/auth/role_graph_update.cpp +++ b/src/mongo/db/auth/role_graph_update.cpp @@ -297,8 +297,7 @@ Status handleOplogCommand(RoleGraph* roleGraph, const BSONObj& cmdObj) { return Status::OK(); } - if (cmdName == "commitTransaction" || cmdName == "abortTransaction" || - cmdName == "prepareTransaction") { + if (cmdName == "commitTransaction" || cmdName == "abortTransaction") { return Status::OK(); } diff --git a/src/mongo/db/commands/txn_cmds.idl b/src/mongo/db/commands/txn_cmds.idl index 0e58d8302bd..c9a479c63c3 100644 --- a/src/mongo/db/commands/txn_cmds.idl +++ b/src/mongo/db/commands/txn_cmds.idl @@ -77,13 +77,6 @@ structs: type: int default: 1 - PrepareTransactionOplogObject: - description: A document representing the 'o' field of a 'prepareTransaction' oplog entry. - fields: - prepareTransaction: - type: int - default: 1 - commands: commitTransaction: description: "commitTransaction Command" diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 1c785e6186b..2e9190198bf 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -1238,17 +1238,6 @@ const StringMap<ApplyOpMetadata> kOpsMap = { boost::optional<Timestamp> stableTimestampForRecovery) -> Status { return applyCommitTransaction(opCtx, entry, mode); }}}, - {"prepareTransaction", - {[](OperationContext* opCtx, - const char* ns, - const BSONElement& ui, - BSONObj& cmd, - const OpTime& opTime, - const OplogEntry& entry, - OplogApplication::Mode mode, - boost::optional<Timestamp> stableTimestampForRecovery) -> Status { - return applyPrepareTransaction(opCtx, entry, mode); - }}}, {"abortTransaction", {[](OperationContext* opCtx, const char* ns, @@ -1823,12 +1812,8 @@ Status applyCommand_inlock(OperationContext* opCtx, // for each collection dropped. 'applyOps' and 'commitTransaction' will try to apply each // individual operation, and those will be caught then if they are a problem. 'abortTransaction' // won't ever change the server configuration collection. - std::vector<std::string> whitelistedOps{"dropDatabase", - "applyOps", - "dbCheck", - "commitTransaction", - "abortTransaction", - "prepareTransaction"}; + std::vector<std::string> whitelistedOps{ + "dropDatabase", "applyOps", "dbCheck", "commitTransaction", "abortTransaction"}; if ((mode == OplogApplication::Mode::kInitialSync) && (std::find(whitelistedOps.begin(), whitelistedOps.end(), o.firstElementFieldName()) == whitelistedOps.end()) && @@ -1859,8 +1844,9 @@ Status applyCommand_inlock(OperationContext* opCtx, // Don't assign commit timestamp for transaction commands. const StringData commandName(o.firstElementFieldName()); - if (entry.shouldPrepare() || commandName == "abortTransaction" || - commandName == "commitTransaction" || commandName == "prepareTransaction") + if (entry.shouldPrepare() || + entry.getCommandType() == OplogEntry::CommandType::kCommitTransaction || + entry.getCommandType() == OplogEntry::CommandType::kAbortTransaction) return false; switch (replMode) { diff --git a/src/mongo/db/repl/oplog_entry.cpp b/src/mongo/db/repl/oplog_entry.cpp index 8bdce328f4a..6d549dd1965 100644 --- a/src/mongo/db/repl/oplog_entry.cpp +++ b/src/mongo/db/repl/oplog_entry.cpp @@ -78,8 +78,6 @@ OplogEntry::CommandType parseCommandType(const BSONObj& objectField) { return OplogEntry::CommandType::kCommitTransaction; } else if (commandString == "abortTransaction") { return OplogEntry::CommandType::kAbortTransaction; - } else if (commandString == "prepareTransaction") { - return OplogEntry::CommandType::kPrepareTransaction; } else { uasserted(ErrorCodes::BadValue, str::stream() << "Unknown oplog entry command type: " << commandString diff --git a/src/mongo/db/repl/oplog_entry.h b/src/mongo/db/repl/oplog_entry.h index 1574a995bdb..7337d79165e 100644 --- a/src/mongo/db/repl/oplog_entry.h +++ b/src/mongo/db/repl/oplog_entry.h @@ -89,7 +89,6 @@ public: kDropIndexes, kCommitTransaction, kAbortTransaction, - kPrepareTransaction, }; // Current oplog version, should be the value of the v field in all oplog entries. diff --git a/src/mongo/db/repl/replication_recovery_test.cpp b/src/mongo/db/repl/replication_recovery_test.cpp index dba35e6f823..f85d0de2252 100644 --- a/src/mongo/db/repl/replication_recovery_test.cpp +++ b/src/mongo/db/repl/replication_recovery_test.cpp @@ -244,7 +244,7 @@ repl::OplogEntry _makeOplogEntry(repl::OpTime opTime, } /** - * Creates a prepareTransaction, commitTransaction or abortTransaction OplogEntry. + * Creates a transaction oplog entry. */ repl::OplogEntry _makeTransactionOplogEntry(repl::OpTime opTime, repl::OpTypeEnum opType, diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp index 25e82217d30..9bdc79ffbf2 100644 --- a/src/mongo/db/repl/rollback_impl.cpp +++ b/src/mongo/db/repl/rollback_impl.cpp @@ -438,7 +438,6 @@ StatusWith<std::set<NamespaceString>> RollbackImpl::_namespacesForOp(const Oplog break; } case OplogEntry::CommandType::kCommitTransaction: - case OplogEntry::CommandType::kPrepareTransaction: case OplogEntry::CommandType::kAbortTransaction: { break; } diff --git a/src/mongo/db/repl/session_update_tracker.cpp b/src/mongo/db/repl/session_update_tracker.cpp index 176135f5bed..28ed0f215f0 100644 --- a/src/mongo/db/repl/session_update_tracker.cpp +++ b/src/mongo/db/repl/session_update_tracker.cpp @@ -115,7 +115,6 @@ bool isTransactionEntry(OplogEntry entry) { } return entry.isPartialTransaction() || - entry.getCommandType() == repl::OplogEntry::CommandType::kPrepareTransaction || entry.getCommandType() == repl::OplogEntry::CommandType::kAbortTransaction || entry.getCommandType() == repl::OplogEntry::CommandType::kCommitTransaction || entry.getCommandType() == repl::OplogEntry::CommandType::kApplyOps; @@ -301,17 +300,6 @@ boost::optional<OplogEntry> SessionUpdateTracker::_createTransactionTableUpdateF newTxnRecord.setState(DurableTxnStateEnum::kCommitted); } break; - case repl::OplogEntry::CommandType::kPrepareTransaction: - newTxnRecord.setState(DurableTxnStateEnum::kPrepared); - if (entry.getPrevWriteOpTimeInTransaction()->isNull()) { - // The 'prepareTransaction' entry is the first operation of the transaction. - newTxnRecord.setStartOpTime(entry.getOpTime()); - } else { - // Update the transaction record using $set to avoid overwriting the - // startOpTime. - return BSON("$set" << newTxnRecord.toBSON()); - } - break; case repl::OplogEntry::CommandType::kCommitTransaction: newTxnRecord.setState(DurableTxnStateEnum::kCommitted); break; diff --git a/src/mongo/db/repl/transaction_oplog_application.cpp b/src/mongo/db/repl/transaction_oplog_application.cpp index 360024e5405..c5fbb2f7177 100644 --- a/src/mongo/db/repl/transaction_oplog_application.cpp +++ b/src/mongo/db/repl/transaction_oplog_application.cpp @@ -74,11 +74,8 @@ Status _applyOperationsForTransaction(OperationContext* opCtx, } /** - * Helper that will find the previous oplog entry for that transaction, then for old-style applyOps - * entries, will transform it to be a normal applyOps command and applies the oplog entry. - * - * For new-style transactions, with multiple oplog entries, will then read the entire set of oplog - * entries for the transaction and apply each of them. + * Helper that will read the entire sequence of oplog entries for the transaction and apply each of + * them. * * Currently used for oplog application of a commitTransaction oplog entry during recovery, rollback * and initial sync. @@ -96,7 +93,7 @@ Status _applyTransactionFromOplogChain(OperationContext* opCtx, // Traverse the oplog chain with its own snapshot and read timestamp. ReadSourceScope readSourceScope(opCtx); - // Get the corresponding prepareTransaction oplog entry. + // Get the corresponding prepare applyOps oplog entry. const auto prepareOpTime = entry.getPrevWriteOpTimeInTransaction(); invariant(prepareOpTime); TransactionHistoryIterator iter(prepareOpTime.get()); @@ -213,7 +210,7 @@ Status applyAbortTransaction(OperationContext* opCtx, repl::MultiApplier::Operations readTransactionOperationsFromOplogChain( OperationContext* opCtx, const OplogEntry& commitOrPrepare, - const std::vector<OplogEntry*> cachedOps) { + const std::vector<OplogEntry*>& cachedOps) { repl::MultiApplier::Operations ops; // Get the previous oplog entry. @@ -382,7 +379,7 @@ Status applyPrepareTransaction(OperationContext* opCtx, // Return error if run via applyOps command. uassert(51145, - "prepareTransaction oplog entry is only used internally by secondaries.", + "prepare applyOps oplog entry is only used internally by secondaries.", oplogApplicationMode != repl::OplogApplication::Mode::kApplyOpsCmd); invariant(oplogApplicationMode == repl::OplogApplication::Mode::kSecondary); diff --git a/src/mongo/db/repl/transaction_oplog_application.h b/src/mongo/db/repl/transaction_oplog_application.h index 09607e820f2..dc145d2c701 100644 --- a/src/mongo/db/repl/transaction_oplog_application.h +++ b/src/mongo/db/repl/transaction_oplog_application.h @@ -57,7 +57,7 @@ Status applyAbortTransaction(OperationContext* opCtx, repl::MultiApplier::Operations readTransactionOperationsFromOplogChain( OperationContext* opCtx, const repl::OplogEntry& entry, - const std::vector<repl::OplogEntry*> cachedOps); + const std::vector<repl::OplogEntry*>& cachedOps); /** * Apply `prepareTransaction` oplog entry. |