summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorJason Chan <jason.chan@10gen.com>2019-05-15 14:12:31 -0400
committerJason Chan <jason.chan@10gen.com>2019-05-15 14:12:31 -0400
commitdeac75e585f0c21d0a4bdf888e249bd9bdc374c3 (patch)
treed540f37f62ff16f9c5fe2b2685a832a1a0e820ff /src/mongo
parent2ca37502214304dddeb90ddac0c24b301ca1518b (diff)
downloadmongo-deac75e585f0c21d0a4bdf888e249bd9bdc374c3.tar.gz
SERVER-40763 Remove the inTxn field from oplog entries
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/dbcheck.cpp1
-rw-r--r--src/mongo/db/op_observer_impl.cpp23
-rw-r--r--src/mongo/db/repl/oplog.cpp25
-rw-r--r--src/mongo/db/repl/oplog.h2
-rw-r--r--src/mongo/db/repl/oplog_entry.h7
-rw-r--r--src/mongo/db/repl/oplog_entry.idl6
-rw-r--r--src/mongo/db/repl/oplog_test.cpp2
-rw-r--r--src/mongo/db/repl/session_update_tracker.cpp2
-rw-r--r--src/mongo/db/repl/session_update_tracker.h3
-rw-r--r--src/mongo/db/repl/transaction_oplog_application.cpp24
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination.cpp1
-rw-r--r--src/mongo/db/transaction_participant_retryable_writes_test.cpp3
12 files changed, 14 insertions, 85 deletions
diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp
index 90160598ba6..57d50acf240 100644
--- a/src/mongo/db/commands/dbcheck.cpp
+++ b/src/mongo/db/commands/dbcheck.cpp
@@ -485,7 +485,6 @@ private:
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
uow.commit();
return result;
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index 5a1243a8598..f2fce8fbf4f 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -88,7 +88,6 @@ repl::OpTime logOperation(OperationContext* opCtx,
StmtId stmtId,
const repl::OplogLink& oplogLink,
bool prepare,
- bool inTxn,
const OplogSlot& oplogSlot) {
auto& times = OpObserver::Times::get(opCtx).reservedOpTimes;
auto opTime = repl::logOp(opCtx,
@@ -103,7 +102,6 @@ repl::OpTime logOperation(OperationContext* opCtx,
stmtId,
oplogLink,
prepare,
- inTxn,
oplogSlot);
times.push_back(opTime);
@@ -212,7 +210,6 @@ OpTimeBundle replLogUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs&
args.updateArgs.stmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
opTimes.prePostImageOpTime = noteUpdateOpTime;
@@ -237,7 +234,6 @@ OpTimeBundle replLogUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs&
args.updateArgs.stmtId,
oplogLink,
false /* prepare */,
- false /* inTxn */,
OplogSlot());
return opTimes;
@@ -278,7 +274,6 @@ OpTimeBundle replLogDelete(OperationContext* opCtx,
stmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
opTimes.prePostImageOpTime = noteOplog;
oplogLink.preImageOpTime = noteOplog;
@@ -297,7 +292,6 @@ OpTimeBundle replLogDelete(OperationContext* opCtx,
stmtId,
oplogLink,
false /* prepare */,
- false /* inTxn */,
OplogSlot());
return opTimes;
}
@@ -327,7 +321,6 @@ OpTimeBundle replLogApplyOps(OperationContext* opCtx,
stmtId,
oplogLink,
prepare,
- false /* inTxn */,
oplogSlot);
return times;
}
@@ -367,7 +360,6 @@ void OpObserverImpl::onCreateIndex(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
@@ -405,7 +397,6 @@ void OpObserverImpl::onStartIndexBuild(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
@@ -443,7 +434,6 @@ void OpObserverImpl::onCommitIndexBuild(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
@@ -481,7 +471,6 @@ void OpObserverImpl::onAbortIndexBuild(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
@@ -708,7 +697,6 @@ void OpObserverImpl::onInternalOpMessage(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
@@ -736,7 +724,6 @@ void OpObserverImpl::onCreateCollection(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
createOpTime);
}
}
@@ -776,7 +763,6 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
@@ -813,7 +799,6 @@ void OpObserverImpl::onDropDatabase(OperationContext* opCtx, const std::string&
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
uassert(
@@ -847,7 +832,6 @@ repl::OpTime OpObserverImpl::onDropCollection(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
@@ -884,7 +868,6 @@ void OpObserverImpl::onDropIndex(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
@@ -926,7 +909,6 @@ repl::OpTime OpObserverImpl::preRenameCollection(OperationContext* const opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
return {};
@@ -986,7 +968,6 @@ void OpObserverImpl::onEmptyCapped(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
}
@@ -1186,7 +1167,6 @@ OpTimeBundle logReplOperationForTransaction(OperationContext* opCtx,
stmtId,
oplogLink,
false /* prepare */,
- true /* inTxn */,
oplogSlot);
return times;
}
@@ -1324,7 +1304,6 @@ void logCommitOrAbortForTransaction(OperationContext* opCtx,
stmtId,
oplogLink,
false /* prepare */,
- false /* inTxn */,
oplogSlot);
invariant(oplogSlot.isNull() || oplogSlot == oplogOpTime);
@@ -1371,7 +1350,6 @@ repl::OpTime logCommitForUnpreparedTransaction(OperationContext* opCtx,
stmtId,
oplogLink,
false /* prepare */,
- false /* inTxn */,
oplogSlot);
// In the present implementation, a reserved oplog slot is always provided. However that
// is not enforced at this level.
@@ -1490,7 +1468,6 @@ repl::OpTime logPrepareTransaction(OperationContext* opCtx,
stmtId,
oplogLink,
false /* prepare */,
- false /* inTxn */,
oplogSlot);
invariant(oplogSlot == oplogOpTime);
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 4bc58c29f1c..3d3abf0afb2 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -377,8 +377,7 @@ OplogDocWriter _logOpWriter(OperationContext* opCtx,
const OperationSessionInfo& sessionInfo,
StmtId statementId,
const OplogLink& oplogLink,
- bool prepare,
- bool inTxn) {
+ bool prepare) {
BSONObjBuilder b(256);
b.append("ts", optime.getTimestamp());
@@ -409,10 +408,6 @@ OplogDocWriter _logOpWriter(OperationContext* opCtx,
b.appendBool(OplogEntryBase::kPrepareFieldName, true);
}
- if (inTxn) {
- b.appendBool(OplogEntryBase::kInTxnFieldName, true);
- }
-
return OplogDocWriter(OplogDocWriter(b.obj(), obj));
}
} // end anon namespace
@@ -498,7 +493,6 @@ OpTime logOp(OperationContext* opCtx,
StmtId statementId,
const OplogLink& oplogLink,
bool prepare,
- bool inTxn,
const OplogSlot& oplogSlot) {
// All collections should have UUIDs now, so all insert, update, and delete oplog entries should
// also have uuids. Some no-op (n) and command (c) entries may still elide the uuid field.
@@ -552,8 +546,7 @@ OpTime logOp(OperationContext* opCtx,
sessionInfo,
statementId,
oplogLink,
- prepare,
- inTxn);
+ prepare);
const DocWriter* basePtr = &writer;
auto timestamp = slot.getTimestamp();
_logOpsInner(opCtx, nss, &basePtr, &timestamp, 1, oplog, slot, wallClockTime);
@@ -627,8 +620,7 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
sessionInfo,
begin[i].stmtId,
oplogLink,
- prepare,
- false /* inTxn */));
+ prepare));
oplogLink.prevOpTime = insertStatementOplogSlot;
timestamps[i] = oplogLink.prevOpTime.getTimestamp();
opTimes.push_back(insertStatementOplogSlot);
@@ -1330,9 +1322,8 @@ Status applyOperation_inlock(OperationContext* opCtx,
mode == repl::OplogApplication::Mode::kApplyOpsCmd || opCtx->writesAreReplicated();
OpCounters* opCounters = shouldUseGlobalOpCounters ? &globalOpCounters : &replOpCounters;
- // TODO(SERVER-40763): Remove "inTxn" entirely.
- std::array<StringData, 9> names = {"ts", "t", "o", "ui", "ns", "op", "b", "o2", "inTxn"};
- std::array<BSONElement, 9> fields;
+ std::array<StringData, 8> names = {"ts", "t", "o", "ui", "ns", "op", "b", "o2"};
+ std::array<BSONElement, 8> fields;
op.getFields(names, &fields);
BSONElement& fieldTs = fields[0];
BSONElement& fieldT = fields[1];
@@ -1342,17 +1333,11 @@ Status applyOperation_inlock(OperationContext* opCtx,
BSONElement& fieldOp = fields[5];
BSONElement& fieldB = fields[6];
BSONElement& fieldO2 = fields[7];
- BSONElement& fieldInTxn = fields[8];
BSONObj o;
if (fieldO.isABSONObj())
o = fieldO.embeddedObject();
- // Make sure we don't apply partial transactions through applyOps.
- uassert(51117,
- "Operations with 'inTxn' set are only used internally by secondaries.",
- fieldInTxn.eoo());
-
// operation type -- see logOp() comments for types
const char* opType = fieldOp.valuestrsafe();
diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h
index 926665fb76f..ab1fad62955 100644
--- a/src/mongo/db/repl/oplog.h
+++ b/src/mongo/db/repl/oplog.h
@@ -124,7 +124,6 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
* linked via prevTs, and the timestamps of the oplog entry that contains the document
* before/after update was applied. The timestamps are ignored if isNull() is true.
* prepare this specifies if the oplog entry should be put into a 'prepare' state.
- * inTxn this specifies that the oplog entry is part of a transaction in progress.
* oplogSlot If non-null, use this reserved oplog slot instead of a new one.
*
* Returns the optime of the oplog entry written to the oplog.
@@ -142,7 +141,6 @@ OpTime logOp(OperationContext* opCtx,
StmtId stmtId,
const OplogLink& oplogLink,
bool prepare,
- bool inTxn,
const OplogSlot& oplogSlot);
// Flush out the cached pointer to the oplog.
diff --git a/src/mongo/db/repl/oplog_entry.h b/src/mongo/db/repl/oplog_entry.h
index 7aeffa97a70..9fe47493b4e 100644
--- a/src/mongo/db/repl/oplog_entry.h
+++ b/src/mongo/db/repl/oplog_entry.h
@@ -149,11 +149,10 @@ public:
* and so this method will always return false for them.
*/
bool isPartialTransaction() const {
- if (getCommandType() == CommandType::kApplyOps) {
- return getObject()[ApplyOpsCommandInfoBase::kPartialTxnFieldName].booleanSafe();
+ if (getCommandType() != CommandType::kApplyOps) {
+ return false;
}
- // TODO(SERVER-40763): Remove "inTxn" entirely and return false here.
- return getInTxn() && *getInTxn();
+ return getObject()[ApplyOpsCommandInfoBase::kPartialTxnFieldName].booleanSafe();
}
/**
diff --git a/src/mongo/db/repl/oplog_entry.idl b/src/mongo/db/repl/oplog_entry.idl
index 773a791bb5e..a182d9ab4f7 100644
--- a/src/mongo/db/repl/oplog_entry.idl
+++ b/src/mongo/db/repl/oplog_entry.idl
@@ -147,9 +147,3 @@ structs:
type: bool
optional: true
description: "Specifies that this operation should be put into a 'prepare' state"
-
- inTxn:
- type: bool
- optional: true
- description: "Specifies that this oplog entry is part of a multi-statement
- transaction that has not yet been committed or prepared."
diff --git a/src/mongo/db/repl/oplog_test.cpp b/src/mongo/db/repl/oplog_test.cpp
index ac154664492..e8c96c5ecb9 100644
--- a/src/mongo/db/repl/oplog_test.cpp
+++ b/src/mongo/db/repl/oplog_test.cpp
@@ -113,7 +113,6 @@ TEST_F(OplogTest, LogOpReturnsOpTimeOnSuccessfulInsertIntoOplogCollection) {
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
ASSERT_FALSE(opTime.isNull());
wunit.commit();
@@ -238,7 +237,6 @@ OpTime _logOpNoopWithMsg(OperationContext* opCtx,
kUninitializedStmtId,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
ASSERT_FALSE(opTime.isNull());
diff --git a/src/mongo/db/repl/session_update_tracker.cpp b/src/mongo/db/repl/session_update_tracker.cpp
index d0fb90ff4ed..fa1354f2dbd 100644
--- a/src/mongo/db/repl/session_update_tracker.cpp
+++ b/src/mongo/db/repl/session_update_tracker.cpp
@@ -249,7 +249,7 @@ boost::optional<OplogEntry> SessionUpdateTracker::_createTransactionTableUpdateF
const repl::OplogEntry& entry) {
auto sessionInfo = entry.getOperationSessionInfo();
- // We only update the transaction table on the first inTxn operation.
+ // We only update the transaction table on the first partialTxn operation.
if (entry.isPartialTransaction() && !entry.getPrevWriteOpTimeInTransaction()->isNull()) {
return boost::none;
}
diff --git a/src/mongo/db/repl/session_update_tracker.h b/src/mongo/db/repl/session_update_tracker.h
index 4c646644cb0..4d84af6be96 100644
--- a/src/mongo/db/repl/session_update_tracker.h
+++ b/src/mongo/db/repl/session_update_tracker.h
@@ -91,7 +91,8 @@ private:
/**
* Returns an update to the transaction table generated by a transaction operation. This returns
- * boost::none if the operation is an inTxn operation that is not the first of the transaction.
+ * boost::none if the operation is a partialTxn operation that is not the first of the
+ * transaction.
*/
boost::optional<OplogEntry> _createTransactionTableUpdateFromTransactionOp(
const repl::OplogEntry& entry);
diff --git a/src/mongo/db/repl/transaction_oplog_application.cpp b/src/mongo/db/repl/transaction_oplog_application.cpp
index 26b2582de9f..24b4ca34af4 100644
--- a/src/mongo/db/repl/transaction_oplog_application.cpp
+++ b/src/mongo/db/repl/transaction_oplog_application.cpp
@@ -213,24 +213,6 @@ Status applyAbortTransaction(OperationContext* opCtx,
return Status::OK();
}
-namespace {
-// Reconstruct the entry "as if" it were at the time given in topLevelObj, with the session
-// information also from "topLevelObj", and remove the "partialTxn" indicator.
-// TODO(SERVER-40763): Remove "inTxn" entirely. We can replace this helper with a direct call to
-// repl::ApplyOps::extractOperationsTo.
-void _reconstructPartialTxnEntryAtGivenTime(const OplogEntry& operationEntry,
- const BSONObj& topLevelObj,
- repl::MultiApplier::Operations* operations) {
- if (operationEntry.getInTxn()) {
- BSONObjBuilder builder(operationEntry.getDurableReplOperation().toBSON());
- builder.appendElementsUnique(topLevelObj);
- operations->emplace_back(builder.obj());
- } else {
- repl::ApplyOps::extractOperationsTo(operationEntry, topLevelObj, operations);
- }
-}
-} // namespace
-
repl::MultiApplier::Operations readTransactionOperationsFromOplogChain(
OperationContext* opCtx,
const OplogEntry& commitOrPrepare,
@@ -263,7 +245,7 @@ repl::MultiApplier::Operations readTransactionOperationsFromOplogChain(
const auto& operationEntry = iter.next(opCtx);
invariant(operationEntry.isPartialTransaction());
auto prevOpsEnd = ops.size();
- _reconstructPartialTxnEntryAtGivenTime(operationEntry, commitOrPrepareObj, &ops);
+ repl::ApplyOps::extractOperationsTo(operationEntry, commitOrPrepareObj, &ops);
// Because BSONArrays do not have fast way of determining size without iterating through
// them, and we also have no way of knowing how many oplog entries are in a transaction
// without iterating, reversing each applyOps and then reversing the whole array is
@@ -278,12 +260,12 @@ repl::MultiApplier::Operations readTransactionOperationsFromOplogChain(
for (auto* cachedOp : cachedOps) {
const auto& operationEntry = *cachedOp;
invariant(operationEntry.isPartialTransaction());
- _reconstructPartialTxnEntryAtGivenTime(operationEntry, commitOrPrepareObj, &ops);
+ repl::ApplyOps::extractOperationsTo(operationEntry, commitOrPrepareObj, &ops);
}
// Reconstruct the operations from the commit or prepare oplog entry.
if (commitOrPrepare.getCommandType() == OplogEntry::CommandType::kApplyOps) {
- _reconstructPartialTxnEntryAtGivenTime(commitOrPrepare, commitOrPrepareObj, &ops);
+ repl::ApplyOps::extractOperationsTo(commitOrPrepare, commitOrPrepareObj, &ops);
}
return ops;
}
diff --git a/src/mongo/db/s/session_catalog_migration_destination.cpp b/src/mongo/db/s/session_catalog_migration_destination.cpp
index 9ba6b751d1e..e6530e6592c 100644
--- a/src/mongo/db/s/session_catalog_migration_destination.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination.cpp
@@ -306,7 +306,6 @@ ProcessOplogResult processSessionOplog(const BSONObj& oplogBSON,
stmtId,
oplogLink,
false /* prepare */,
- false /* inTxn */,
OplogSlot());
const auto& oplogOpTime = result.oplogTime;
diff --git a/src/mongo/db/transaction_participant_retryable_writes_test.cpp b/src/mongo/db/transaction_participant_retryable_writes_test.cpp
index ab88c014f73..4eb13d6e7c7 100644
--- a/src/mongo/db/transaction_participant_retryable_writes_test.cpp
+++ b/src/mongo/db/transaction_participant_retryable_writes_test.cpp
@@ -220,7 +220,6 @@ protected:
stmtId,
link,
false /* prepare */,
- false /* inTxn */,
OplogSlot());
}
@@ -589,7 +588,6 @@ TEST_F(TransactionParticipantRetryableWritesTest, ErrorOnlyWhenStmtIdBeingChecke
1,
{},
false /* prepare */,
- false /* inTxn */,
OplogSlot());
txnParticipant.onWriteOpCompletedOnPrimary(
opCtx(), txnNum, {1}, opTime, wallClockTime, boost::none, boost::none);
@@ -619,7 +617,6 @@ TEST_F(TransactionParticipantRetryableWritesTest, ErrorOnlyWhenStmtIdBeingChecke
kIncompleteHistoryStmtId,
link,
false /* prepare */,
- false /* inTxn */,
OplogSlot());
txnParticipant.onWriteOpCompletedOnPrimary(opCtx(),