summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-10-25 15:46:47 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-10-25 17:35:26 -0400
commit31d94c844e76b3204b2280640d639a3141c2231c (patch)
tree63b8c8a97d24f1635987dded92378e473f6739f5
parent7d39fcc31b1b05a3baae46db0463b5bdad0727ee (diff)
downloadmongo-31d94c844e76b3204b2280640d639a3141c2231c.tar.gz
SERVER-31678 Thread through the operation wall-clock time for oplog entries
-rw-r--r--src/mongo/db/commands/dbcheck.cpp16
-rw-r--r--src/mongo/db/op_observer_impl.cpp140
-rw-r--r--src/mongo/db/repl/oplog.cpp9
-rw-r--r--src/mongo/db/repl/oplog.h7
-rw-r--r--src/mongo/db/repl/oplog_test.cpp16
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination.cpp5
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination_test.cpp56
-rw-r--r--src/mongo/db/session_test.cpp19
8 files changed, 236 insertions, 32 deletions
diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp
index 3650b93af48..fe7bcd178c6 100644
--- a/src/mongo/db/commands/dbcheck.cpp
+++ b/src/mongo/db/commands/dbcheck.cpp
@@ -461,9 +461,21 @@ private:
const BSONObj& obj) {
return writeConflictRetry(
opCtx, "dbCheck oplog entry", NamespaceString::kRsOplogNamespace.ns(), [&] {
+ auto const clockSource = opCtx->getServiceContext()->getFastClockSource();
+ const auto wallClockTime = clockSource->now();
+
WriteUnitOfWork uow(opCtx);
- repl::OpTime result = repl::logOp(
- opCtx, "c", nss, uuid, obj, nullptr, false, {}, kUninitializedStmtId, {});
+ repl::OpTime result = repl::logOp(opCtx,
+ "c",
+ nss,
+ uuid,
+ obj,
+ nullptr,
+ false,
+ wallClockTime,
+ {},
+ kUninitializedStmtId,
+ {});
uow.commit();
return result;
});
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index 0f3c08b0e07..5621f9da8a2 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -117,9 +117,15 @@ BSONObj makeCollModCmdObj(const BSONObj& collModCmd,
return cmdObjBuilder.obj();
}
+Date_t getWallClockTimeForOpLog(OperationContext* opCtx) {
+ auto const clockSource = opCtx->getServiceContext()->getFastClockSource();
+ return clockSource->now();
+}
+
struct OpTimeBundle {
repl::OpTime writeOpTime;
repl::OpTime prePostImageOpTime;
+ Date_t wallClockTime;
};
/**
@@ -146,6 +152,7 @@ OpTimeBundle replLogUpdate(OperationContext* opCtx,
}
OpTimeBundle opTimes;
+ opTimes.wallClockTime = getWallClockTimeForOpLog(opCtx);
if (!storeObj.isEmpty() && opCtx->getTxnNumber()) {
auto noteUpdateOpTime = repl::logOp(opCtx,
@@ -155,6 +162,7 @@ OpTimeBundle replLogUpdate(OperationContext* opCtx,
storeObj,
nullptr,
false,
+ opTimes.wallClockTime,
sessionInfo,
args.stmtId,
{});
@@ -175,6 +183,7 @@ OpTimeBundle replLogUpdate(OperationContext* opCtx,
args.update,
&args.criteria,
args.fromMigrate,
+ opTimes.wallClockTime,
sessionInfo,
args.stmtId,
oplogLink);
@@ -203,10 +212,20 @@ OpTimeBundle replLogDelete(OperationContext* opCtx,
}
OpTimeBundle opTimes;
+ opTimes.wallClockTime = getWallClockTimeForOpLog(opCtx);
if (deletedDoc && opCtx->getTxnNumber()) {
- auto noteOplog = repl::logOp(
- opCtx, "n", nss, uuid, deletedDoc.get(), nullptr, false, sessionInfo, stmtId, {});
+ auto noteOplog = repl::logOp(opCtx,
+ "n",
+ nss,
+ uuid,
+ deletedDoc.get(),
+ nullptr,
+ false,
+ opTimes.wallClockTime,
+ sessionInfo,
+ stmtId,
+ {});
opTimes.prePostImageOpTime = noteOplog;
oplogLink.preImageOpTime = noteOplog;
}
@@ -218,6 +237,7 @@ OpTimeBundle replLogDelete(OperationContext* opCtx,
deleteState.documentKey,
nullptr,
fromMigrate,
+ opTimes.wallClockTime,
sessionInfo,
stmtId,
oplogLink);
@@ -249,6 +269,7 @@ void OpObserverImpl::onCreateIndex(OperationContext* opCtx,
builder.done(),
nullptr,
fromMigrate,
+ getWallClockTimeForOpLog(opCtx),
{},
kUninitializedStmtId,
{});
@@ -260,6 +281,7 @@ void OpObserverImpl::onCreateIndex(OperationContext* opCtx,
indexDoc,
nullptr,
fromMigrate,
+ getWallClockTimeForOpLog(opCtx),
{},
kUninitializedStmtId,
{});
@@ -282,7 +304,8 @@ void OpObserverImpl::onInserts(OperationContext* opCtx,
bool fromMigrate) {
Session* const session = opCtx->getTxnNumber() ? OperationContextSession::get(opCtx) : nullptr;
- const auto opTimeList = repl::logInsertOps(opCtx, nss, uuid, session, begin, end, fromMigrate);
+ const auto opTimeList = repl::logInsertOps(
+ opCtx, nss, uuid, session, begin, end, fromMigrate, getWallClockTimeForOpLog(opCtx));
auto css = CollectionShardingState::get(opCtx, nss.ns());
@@ -420,7 +443,17 @@ void OpObserverImpl::onInternalOpMessage(OperationContext* opCtx,
const BSONObj& msgObj,
const boost::optional<BSONObj> o2MsgObj) {
const BSONObj* o2MsgPtr = o2MsgObj ? o2MsgObj.get_ptr() : nullptr;
- repl::logOp(opCtx, "n", nss, uuid, msgObj, o2MsgPtr, false, {}, kUninitializedStmtId, {});
+ repl::logOp(opCtx,
+ "n",
+ nss,
+ uuid,
+ msgObj,
+ o2MsgPtr,
+ false,
+ getWallClockTimeForOpLog(opCtx),
+ {},
+ kUninitializedStmtId,
+ {});
}
void OpObserverImpl::onCreateCollection(OperationContext* opCtx,
@@ -453,8 +486,17 @@ void OpObserverImpl::onCreateCollection(OperationContext* opCtx,
if (!collectionName.isSystemDotProfile()) {
// do not replicate system.profile modifications
- repl::logOp(
- opCtx, "c", cmdNss, options.uuid, cmdObj, nullptr, false, {}, kUninitializedStmtId, {});
+ repl::logOp(opCtx,
+ "c",
+ cmdNss,
+ options.uuid,
+ cmdObj,
+ nullptr,
+ false,
+ getWallClockTimeForOpLog(opCtx),
+ {},
+ kUninitializedStmtId,
+ {});
}
AuthorizationManager::get(opCtx->getServiceContext())
@@ -492,7 +534,17 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx,
if (!nss.isSystemDotProfile()) {
// do not replicate system.profile modifications
- repl::logOp(opCtx, "c", cmdNss, uuid, cmdObj, &o2Obj, false, {}, kUninitializedStmtId, {});
+ repl::logOp(opCtx,
+ "c",
+ cmdNss,
+ uuid,
+ cmdObj,
+ &o2Obj,
+ false,
+ getWallClockTimeForOpLog(opCtx),
+ {},
+ kUninitializedStmtId,
+ {});
}
AuthorizationManager::get(opCtx->getServiceContext())
@@ -522,7 +574,17 @@ void OpObserverImpl::onDropDatabase(OperationContext* opCtx, const std::string&
const NamespaceString cmdNss{dbName, "$cmd"};
const auto cmdObj = BSON("dropDatabase" << 1);
- repl::logOp(opCtx, "c", cmdNss, {}, cmdObj, nullptr, false, {}, kUninitializedStmtId, {});
+ repl::logOp(opCtx,
+ "c",
+ cmdNss,
+ {},
+ cmdObj,
+ nullptr,
+ false,
+ getWallClockTimeForOpLog(opCtx),
+ {},
+ kUninitializedStmtId,
+ {});
if (dbName == FeatureCompatibilityVersion::kDatabase) {
FeatureCompatibilityVersion::onDropCollection(opCtx);
@@ -545,8 +607,17 @@ repl::OpTime OpObserverImpl::onDropCollection(OperationContext* opCtx,
repl::OpTime dropOpTime;
if (!collectionName.isSystemDotProfile()) {
// Do not replicate system.profile modifications
- dropOpTime = repl::logOp(
- opCtx, "c", cmdNss, uuid, cmdObj, nullptr, false, {}, kUninitializedStmtId, {});
+ dropOpTime = repl::logOp(opCtx,
+ "c",
+ cmdNss,
+ uuid,
+ cmdObj,
+ nullptr,
+ false,
+ getWallClockTimeForOpLog(opCtx),
+ {},
+ kUninitializedStmtId,
+ {});
}
if (collectionName.coll() == DurableViewCatalog::viewsCollectionName()) {
@@ -583,7 +654,17 @@ void OpObserverImpl::onDropIndex(OperationContext* opCtx,
const auto cmdNss = nss.getCommandNS();
const auto cmdObj = BSON("dropIndexes" << nss.coll() << "index" << indexName);
- repl::logOp(opCtx, "c", cmdNss, uuid, cmdObj, &indexInfo, false, {}, kUninitializedStmtId, {});
+ repl::logOp(opCtx,
+ "c",
+ cmdNss,
+ uuid,
+ cmdObj,
+ &indexInfo,
+ false,
+ getWallClockTimeForOpLog(opCtx),
+ {},
+ kUninitializedStmtId,
+ {});
AuthorizationManager::get(opCtx->getServiceContext())
->logOp(opCtx, "c", cmdNss, cmdObj, &indexInfo);
@@ -610,8 +691,17 @@ repl::OpTime OpObserverImpl::onRenameCollection(OperationContext* opCtx,
const auto cmdObj = builder.done();
- const auto renameOpTime =
- repl::logOp(opCtx, "c", cmdNss, uuid, cmdObj, nullptr, false, {}, kUninitializedStmtId, {});
+ const auto renameOpTime = repl::logOp(opCtx,
+ "c",
+ cmdNss,
+ uuid,
+ cmdObj,
+ nullptr,
+ false,
+ getWallClockTimeForOpLog(opCtx),
+ {},
+ kUninitializedStmtId,
+ {});
if (fromCollection.isSystemDotViews())
DurableViewCatalog::onExternalChange(opCtx, fromCollection);
@@ -647,7 +737,17 @@ void OpObserverImpl::onApplyOps(OperationContext* opCtx,
const std::string& dbName,
const BSONObj& applyOpCmd) {
const NamespaceString cmdNss{dbName, "$cmd"};
- repl::logOp(opCtx, "c", cmdNss, {}, applyOpCmd, nullptr, false, {}, kUninitializedStmtId, {});
+ repl::logOp(opCtx,
+ "c",
+ cmdNss,
+ {},
+ applyOpCmd,
+ nullptr,
+ false,
+ getWallClockTimeForOpLog(opCtx),
+ {},
+ kUninitializedStmtId,
+ {});
AuthorizationManager::get(opCtx->getServiceContext())
->logOp(opCtx, "c", cmdNss, applyOpCmd, nullptr);
@@ -661,7 +761,17 @@ void OpObserverImpl::onEmptyCapped(OperationContext* opCtx,
if (!collectionName.isSystemDotProfile()) {
// Do not replicate system.profile modifications
- repl::logOp(opCtx, "c", cmdNss, uuid, cmdObj, nullptr, false, {}, kUninitializedStmtId, {});
+ repl::logOp(opCtx,
+ "c",
+ cmdNss,
+ uuid,
+ cmdObj,
+ nullptr,
+ false,
+ getWallClockTimeForOpLog(opCtx),
+ {},
+ kUninitializedStmtId,
+ {});
}
AuthorizationManager::get(opCtx->getServiceContext())
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index b7503de1082..8fd70dff826 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -408,6 +408,7 @@ OpTime logOp(OperationContext* opCtx,
const BSONObj& obj,
const BSONObj* o2,
bool fromMigrate,
+ Date_t wallClockTime,
const OperationSessionInfo& sessionInfo,
StmtId statementId,
const OplogLink& oplogLink) {
@@ -434,7 +435,7 @@ OpTime logOp(OperationContext* opCtx,
fromMigrate,
slot.opTime,
slot.hash,
- Date_t::now(),
+ wallClockTime,
sessionInfo,
statementId,
oplogLink);
@@ -451,7 +452,8 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
Session* session,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
- bool fromMigrate) {
+ bool fromMigrate,
+ Date_t wallClockTime) {
invariant(begin != end);
auto replCoord = ReplicationCoordinator::get(opCtx);
@@ -468,7 +470,6 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
Lock::CollectionLock lock(opCtx->lockState(), _oplogCollectionName, MODE_IX);
WriteUnitOfWork wuow(opCtx);
- auto wallTime = Date_t::now();
OperationSessionInfo sessionInfo;
OplogLink oplogLink;
@@ -497,7 +498,7 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
fromMigrate,
insertStatementOplogSlot.opTime,
insertStatementOplogSlot.hash,
- wallTime,
+ wallClockTime,
sessionInfo,
begin[i].stmtId,
oplogLink));
diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h
index 78f1c4f8103..df2178a66aa 100644
--- a/src/mongo/db/repl/oplog.h
+++ b/src/mongo/db/repl/oplog.h
@@ -110,7 +110,8 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
Session* session,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
- bool fromMigrate);
+ bool fromMigrate,
+ Date_t wallClockTime);
/**
* @param opstr
@@ -124,6 +125,9 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
* For 'u' records, 'obj' captures the mutation made to the object but not
* the object itself. 'o2' captures the the criteria for the object that will be modified.
*
+ * wallClockTime this specifies the wall-clock timestamp of then this oplog entry was generated. It
+ * is purely informational, may not be monotonically increasing and is not interpreted in any way
+ * by the replication subsystem.
* oplogLink this contains the timestamp that points to the previous write that will be
* 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.
@@ -138,6 +142,7 @@ OpTime logOp(OperationContext* opCtx,
const BSONObj& obj,
const BSONObj* o2,
bool fromMigrate,
+ Date_t wallClockTime,
const OperationSessionInfo& sessionInfo,
StmtId stmtId,
const OplogLink& oplogLink);
diff --git a/src/mongo/db/repl/oplog_test.cpp b/src/mongo/db/repl/oplog_test.cpp
index cad60def20f..7666e026955 100644
--- a/src/mongo/db/repl/oplog_test.cpp
+++ b/src/mongo/db/repl/oplog_test.cpp
@@ -100,8 +100,17 @@ TEST_F(OplogTest, LogOpReturnsOpTimeOnSuccessfulInsertIntoOplogCollection) {
{
AutoGetDb autoDb(opCtx.get(), nss.db(), MODE_X);
WriteUnitOfWork wunit(opCtx.get());
- opTime =
- logOp(opCtx.get(), "n", nss, {}, msgObj, nullptr, false, {}, kUninitializedStmtId, {});
+ opTime = logOp(opCtx.get(),
+ "n",
+ nss,
+ {},
+ msgObj,
+ nullptr,
+ false,
+ Date_t::now(),
+ {},
+ kUninitializedStmtId,
+ {});
ASSERT_FALSE(opTime.isNull());
wunit.commit();
}
@@ -213,7 +222,8 @@ OpTime _logOpNoopWithMsg(OperationContext* opCtx,
// logOp() must be called while holding lock because ephemeralForTest storage engine does not
// support concurrent updates to its internal state.
const auto msgObj = BSON("msg" << nss.ns());
- auto opTime = logOp(opCtx, "n", nss, {}, msgObj, nullptr, false, {}, kUninitializedStmtId, {});
+ auto opTime = logOp(
+ opCtx, "n", nss, {}, msgObj, nullptr, false, Date_t::now(), {}, kUninitializedStmtId, {});
ASSERT_FALSE(opTime.isNull());
ASSERT(opTimeNssMap->find(opTime) == opTimeNssMap->end())
diff --git a/src/mongo/db/s/session_catalog_migration_destination.cpp b/src/mongo/db/s/session_catalog_migration_destination.cpp
index cdf0f0a778d..461d53e40b2 100644
--- a/src/mongo/db/s/session_catalog_migration_destination.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination.cpp
@@ -242,6 +242,10 @@ ProcessOplogResult processSessionOplog(OperationContext* opCtx,
result.txnNum = sessionInfo.getTxnNumber().value();
const auto stmtId = *oplogEntry.getStatementId();
+ // Session oplog entries must always contain wall clock time, because we will not be
+ // transferring anything from a previous version of the server
+ invariant(oplogEntry.getWallClockTime());
+
auto scopedSession = SessionCatalog::get(opCtx)->getOrCreateSession(opCtx, result.sessionId);
scopedSession->beginTxn(opCtx, result.txnNum);
@@ -285,6 +289,7 @@ ProcessOplogResult processSessionOplog(OperationContext* opCtx,
object,
&object2,
true,
+ *oplogEntry.getWallClockTime(),
sessionInfo,
stmtId,
oplogLink);
diff --git a/src/mongo/db/s/session_catalog_migration_destination_test.cpp b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
index 45ef7d0350c..99ee8eae5d8 100644
--- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
@@ -298,14 +298,17 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithSameTxn) {
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(sessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry oplog2(OpTime(Timestamp(80, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 80));
oplog2.setOperationSessionInfo(sessionInfo);
oplog2.setStatementId(45);
+ oplog2.setWallClockTime(Date_t::now());
OplogEntry oplog3(OpTime(Timestamp(60, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 60));
oplog3.setOperationSessionInfo(sessionInfo);
oplog3.setStatementId(5);
+ oplog3.setWallClockTime(Date_t::now());
returnOplog({oplog1, oplog2, oplog3});
@@ -347,16 +350,19 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldOnlyStoreHistoryOfLatestTxn
sessionInfo.setTxnNumber(txnNum++);
oplog1.setOperationSessionInfo(sessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry oplog2(OpTime(Timestamp(80, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 80));
sessionInfo.setTxnNumber(txnNum++);
oplog2.setOperationSessionInfo(sessionInfo);
oplog2.setStatementId(45);
+ oplog2.setWallClockTime(Date_t::now());
OplogEntry oplog3(OpTime(Timestamp(60, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 60));
sessionInfo.setTxnNumber(txnNum);
oplog3.setOperationSessionInfo(sessionInfo);
oplog3.setStatementId(5);
+ oplog3.setWallClockTime(Date_t::now());
returnOplog({oplog1, oplog2, oplog3});
@@ -388,17 +394,19 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithSameTxnInSeparate
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(sessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry oplog2(OpTime(Timestamp(80, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 80));
oplog2.setOperationSessionInfo(sessionInfo);
oplog2.setStatementId(45);
+ oplog2.setWallClockTime(Date_t::now());
OplogEntry oplog3(OpTime(Timestamp(60, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 60));
oplog3.setOperationSessionInfo(sessionInfo);
oplog3.setStatementId(5);
+ oplog3.setWallClockTime(Date_t::now());
// Return in 2 batches
-
returnOplog({oplog1, oplog2});
returnOplog({oplog3});
@@ -444,14 +452,17 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithDifferentSession)
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(sessionInfo1);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry oplog2(OpTime(Timestamp(80, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 80));
oplog2.setOperationSessionInfo(sessionInfo2);
oplog2.setStatementId(45);
+ oplog2.setWallClockTime(Date_t::now());
OplogEntry oplog3(OpTime(Timestamp(60, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 60));
oplog3.setOperationSessionInfo(sessionInfo2);
oplog3.setStatementId(5);
+ oplog3.setWallClockTime(Date_t::now());
returnOplog({oplog1, oplog2, oplog3});
@@ -518,6 +529,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldNotNestAlreadyNestedOplog)
origInnerOplog1.toBSON());
oplog1.setOperationSessionInfo(sessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry oplog2(OpTime(Timestamp(1080, 2), 1),
0,
@@ -528,6 +540,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldNotNestAlreadyNestedOplog)
origInnerOplog2.toBSON());
oplog2.setOperationSessionInfo(sessionInfo);
oplog2.setStatementId(45);
+ oplog2.setWallClockTime(Date_t::now());
returnOplog({oplog1, oplog2});
@@ -565,6 +578,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandlePreImageFindA
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kNoop, kNs, 0, BSON("x" << 100));
preImageOplog.setOperationSessionInfo(sessionInfo);
preImageOplog.setStatementId(45);
+ preImageOplog.setWallClockTime(Date_t::now());
OplogEntry updateOplog(OpTime(Timestamp(80, 2), 1),
0,
@@ -575,6 +589,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandlePreImageFindA
BSON("$set" << BSON("x" << 101)));
updateOplog.setOperationSessionInfo(sessionInfo);
updateOplog.setStatementId(45);
+ updateOplog.setWallClockTime(Date_t::now());
updateOplog.setPreImageOpTime(repl::OpTime(Timestamp(100, 2), 1));
returnOplog({preImageOplog, updateOplog});
@@ -652,6 +667,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandlePostImageFind
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kNoop, kNs, 0, BSON("x" << 100));
postImageOplog.setOperationSessionInfo(sessionInfo);
postImageOplog.setStatementId(45);
+ postImageOplog.setWallClockTime(Date_t::now());
OplogEntry updateOplog(OpTime(Timestamp(80, 2), 1),
0,
@@ -662,6 +678,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandlePostImageFind
BSON("$set" << BSON("x" << 101)));
updateOplog.setOperationSessionInfo(sessionInfo);
updateOplog.setStatementId(45);
+ updateOplog.setWallClockTime(Date_t::now());
updateOplog.setPostImageOpTime(repl::OpTime(Timestamp(100, 2), 1));
returnOplog({postImageOplog, updateOplog});
@@ -739,6 +756,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandleFindAndModify
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kNoop, kNs, 0, BSON("x" << 100));
preImageOplog.setOperationSessionInfo(sessionInfo);
preImageOplog.setStatementId(45);
+ preImageOplog.setWallClockTime(Date_t::now());
OplogEntry updateOplog(OpTime(Timestamp(80, 2), 1),
0,
@@ -749,6 +767,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandleFindAndModify
BSON("$set" << BSON("x" << 101)));
updateOplog.setOperationSessionInfo(sessionInfo);
updateOplog.setStatementId(45);
+ updateOplog.setWallClockTime(Date_t::now());
updateOplog.setPreImageOpTime(repl::OpTime(Timestamp(100, 2), 1));
returnOplog({preImageOplog});
@@ -841,10 +860,12 @@ TEST_F(SessionCatalogMigrationDestinationTest, OlderTxnShouldBeIgnored) {
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(oldSessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry oplog2(OpTime(Timestamp(80, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 80));
oplog2.setOperationSessionInfo(oldSessionInfo);
oplog2.setStatementId(45);
+ oplog2.setWallClockTime(Date_t::now());
returnOplog({oplog1, oplog2});
@@ -883,6 +904,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, NewerTxnWriteShouldNotBeOverwritt
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(oldSessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
returnOplog({oplog1});
@@ -902,6 +924,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, NewerTxnWriteShouldNotBeOverwritt
OplogEntry oplog2(OpTime(Timestamp(80, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 80));
oplog2.setOperationSessionInfo(oldSessionInfo);
oplog2.setStatementId(45);
+ oplog2.setWallClockTime(Date_t::now());
returnOplog({oplog2});
@@ -982,6 +1005,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldJoinProperlyForResponseWith
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog.setOperationSessionInfo(sessionInfo);
oplog.setStatementId(23);
+ oplog.setWallClockTime(Date_t::now());
returnOplog({oplog});
@@ -1004,6 +1028,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldJoinProperlyForResponseWith
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog.setOperationSessionInfo(sessionInfo);
oplog.setStatementId(23);
+ oplog.setWallClockTime(Date_t::now());
returnOplog({oplog});
@@ -1027,6 +1052,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldJoinProperlyForResponseWith
OplogEntry oplog(
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog.setOperationSessionInfo(sessionInfo);
+ oplog.setWallClockTime(Date_t::now());
returnOplog({oplog});
@@ -1053,6 +1079,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(sessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
returnOplog({oplog1});
@@ -1068,6 +1095,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
OplogEntry oplog2(OpTime(Timestamp(80, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 80));
oplog2.setOperationSessionInfo(sessionInfo);
oplog2.setStatementId(45);
+ oplog2.setWallClockTime(Date_t::now());
returnOplog({oplog2});
@@ -1108,17 +1136,19 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldErrorForConsecutivePreImage
sessionInfo.setSessionId(sessionId);
sessionInfo.setTxnNumber(2);
- OplogEntry preImageOplog(
+ OplogEntry preImageOplog1(
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kNoop, kNs, 0, BSON("x" << 100));
- preImageOplog.setOperationSessionInfo(sessionInfo);
- preImageOplog.setStatementId(45);
+ preImageOplog1.setOperationSessionInfo(sessionInfo);
+ preImageOplog1.setStatementId(45);
+ preImageOplog1.setWallClockTime(Date_t::now());
OplogEntry preImageOplog2(
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kNoop, kNs, 0, BSON("x" << 100));
preImageOplog2.setOperationSessionInfo(sessionInfo);
preImageOplog2.setStatementId(45);
+ preImageOplog2.setWallClockTime(Date_t::now());
- returnOplog({preImageOplog, preImageOplog2});
+ returnOplog({preImageOplog1, preImageOplog2});
sessionMigration.join();
@@ -1145,6 +1175,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kNoop, kNs, 0, BSON("x" << 100));
preImageOplog.setOperationSessionInfo(sessionInfo);
preImageOplog.setStatementId(45);
+ preImageOplog.setWallClockTime(Date_t::now());
OplogEntry updateOplog(OpTime(Timestamp(80, 2), 1),
0,
@@ -1156,6 +1187,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
sessionInfo.setSessionId(makeLogicalSessionIdForTest());
updateOplog.setOperationSessionInfo(sessionInfo);
updateOplog.setStatementId(45);
+ updateOplog.setWallClockTime(Date_t::now());
updateOplog.setPreImageOpTime(repl::OpTime(Timestamp(100, 2), 1));
returnOplog({preImageOplog, updateOplog});
@@ -1185,6 +1217,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldErrorForPreImageOplogWithNo
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kNoop, kNs, 0, BSON("x" << 100));
preImageOplog.setOperationSessionInfo(sessionInfo);
preImageOplog.setStatementId(45);
+ preImageOplog.setWallClockTime(Date_t::now());
OplogEntry updateOplog(OpTime(Timestamp(80, 2), 1),
0,
@@ -1196,6 +1229,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldErrorForPreImageOplogWithNo
sessionInfo.setTxnNumber(56);
updateOplog.setOperationSessionInfo(sessionInfo);
updateOplog.setStatementId(45);
+ updateOplog.setWallClockTime(Date_t::now());
updateOplog.setPreImageOpTime(repl::OpTime(Timestamp(100, 2), 1));
returnOplog({preImageOplog, updateOplog});
@@ -1226,6 +1260,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kNoop, kNs, 0, BSON("x" << 100));
preImageOplog.setOperationSessionInfo(sessionInfo);
preImageOplog.setStatementId(45);
+ preImageOplog.setWallClockTime(Date_t::now());
OplogEntry updateOplog(OpTime(Timestamp(80, 2), 1),
0,
@@ -1236,6 +1271,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
BSON("$set" << BSON("x" << 101)));
updateOplog.setOperationSessionInfo(sessionInfo);
updateOplog.setStatementId(45);
+ updateOplog.setWallClockTime(Date_t::now());
returnOplog({preImageOplog, updateOplog});
@@ -1265,6 +1301,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(sessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry updateOplog(OpTime(Timestamp(80, 2), 1),
0,
@@ -1275,6 +1312,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
BSON("$set" << BSON("x" << 101)));
updateOplog.setOperationSessionInfo(sessionInfo);
updateOplog.setStatementId(45);
+ updateOplog.setWallClockTime(Date_t::now());
updateOplog.setPreImageOpTime(repl::OpTime(Timestamp(100, 2), 1));
returnOplog({oplog1, updateOplog});
@@ -1305,6 +1343,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(sessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry updateOplog(OpTime(Timestamp(80, 2), 1),
0,
@@ -1315,6 +1354,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
BSON("$set" << BSON("x" << 101)));
updateOplog.setOperationSessionInfo(sessionInfo);
updateOplog.setStatementId(45);
+ updateOplog.setWallClockTime(Date_t::now());
updateOplog.setPostImageOpTime(repl::OpTime(Timestamp(100, 2), 1));
returnOplog({oplog1, updateOplog});
@@ -1344,14 +1384,17 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldIgnoreAlreadyExecutedStatem
OpTime(Timestamp(60, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(sessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry oplog2(OpTime(Timestamp(70, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 80));
oplog2.setOperationSessionInfo(sessionInfo);
oplog2.setStatementId(30);
+ oplog2.setWallClockTime(Date_t::now());
OplogEntry oplog3(OpTime(Timestamp(80, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 80));
oplog3.setOperationSessionInfo(sessionInfo);
oplog3.setStatementId(45);
+ oplog3.setWallClockTime(Date_t::now());
returnOplog({oplog1, oplog2, oplog3});
@@ -1395,15 +1438,18 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithIncompleteHistory
OpTime(Timestamp(100, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 100));
oplog1.setOperationSessionInfo(sessionInfo);
oplog1.setStatementId(23);
+ oplog1.setWallClockTime(Date_t::now());
OplogEntry oplog2(
OpTime(Timestamp(80, 2), 1), 0, OpTypeEnum::kNoop, kNs, 0, {}, Session::kDeadEndSentinel);
oplog2.setOperationSessionInfo(sessionInfo);
oplog2.setStatementId(kIncompleteHistoryStmtId);
+ oplog2.setWallClockTime(Date_t::now());
OplogEntry oplog3(OpTime(Timestamp(60, 2), 1), 0, OpTypeEnum::kInsert, kNs, 0, BSON("x" << 60));
oplog3.setOperationSessionInfo(sessionInfo);
oplog3.setStatementId(5);
+ oplog3.setWallClockTime(Date_t::now());
returnOplog({oplog1, oplog2, oplog3});
// migration always fetches at least twice to transition from committing to done.
diff --git a/src/mongo/db/session_test.cpp b/src/mongo/db/session_test.cpp
index 15cbcd8ba27..4c40d91197c 100644
--- a/src/mongo/db/session_test.cpp
+++ b/src/mongo/db/session_test.cpp
@@ -84,8 +84,17 @@ protected:
repl::OplogLink link;
link.prevOpTime = prevOpTime;
- return repl::logOp(
- opCtx, "n", nss, kUUID, BSON("TestValue" << 0), nullptr, false, osi, stmtId, link);
+ return repl::logOp(opCtx,
+ "n",
+ nss,
+ kUUID,
+ BSON("TestValue" << 0),
+ nullptr,
+ false,
+ Date_t::now(),
+ osi,
+ stmtId,
+ link);
}
};
@@ -354,6 +363,8 @@ TEST_F(SessionTest, ErrorOnlyWhenStmtIdBeingCheckedIsNotInCache) {
AutoGetCollection autoColl(opCtx(), kNss, MODE_IX);
WriteUnitOfWork wuow(opCtx());
+ const auto wallClockTime = Date_t::now();
+
auto opTime = repl::logOp(opCtx(),
"i",
kNss,
@@ -361,6 +372,7 @@ TEST_F(SessionTest, ErrorOnlyWhenStmtIdBeingCheckedIsNotInCache) {
BSON("x" << 1),
&Session::kDeadEndSentinel,
false,
+ wallClockTime,
osi,
1,
{});
@@ -377,6 +389,8 @@ TEST_F(SessionTest, ErrorOnlyWhenStmtIdBeingCheckedIsNotInCache) {
AutoGetCollection autoColl(opCtx(), kNss, MODE_IX);
WriteUnitOfWork wuow(opCtx());
+ const auto wallClockTime = Date_t::now();
+
auto opTime = repl::logOp(opCtx(),
"n",
kNss,
@@ -384,6 +398,7 @@ TEST_F(SessionTest, ErrorOnlyWhenStmtIdBeingCheckedIsNotInCache) {
{},
&Session::kDeadEndSentinel,
false,
+ wallClockTime,
osi,
kIncompleteHistoryStmtId,
link);