summaryrefslogtreecommitdiff
path: root/src/mongo/db/op_observer_impl.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-10-23 10:58:04 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-10-25 09:10:33 -0400
commit080514c9ee36564d8342cd832f3c5f3a199a9845 (patch)
tree00b92f28d6e00826b9b094a01d14248a550d0cca /src/mongo/db/op_observer_impl.cpp
parent67f735e6705091659e2a8cf46a9285f09bcf749a (diff)
downloadmongo-080514c9ee36564d8342cd832f3c5f3a199a9845.tar.gz
SERVER-31678 Thread through the operation wall-clock time for oplog entries
Diffstat (limited to 'src/mongo/db/op_observer_impl.cpp')
-rw-r--r--src/mongo/db/op_observer_impl.cpp140
1 files changed, 125 insertions, 15 deletions
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())