summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorVesselina Ratcheva <vesselina.ratcheva@10gen.com>2019-06-12 11:47:12 -0400
committerVesselina Ratcheva <vesselina.ratcheva@10gen.com>2019-07-03 14:33:37 -0400
commit3ed072af4e98b34189b29a4c86287c8d9c72b11a (patch)
treeac00f9aa614c1afd02350978c8b92c6b12a48d7d /src/mongo/db
parent42eb2a542f26756134bd617373aa6ef87828b85a (diff)
downloadmongo-3ed072af4e98b34189b29a4c86287c8d9c72b11a.tar.gz
Add support for 'recoverFromOplogAsStandalone' with prepared transactions
(cherry picked from commit fd8538074a35666a8f18f54ffae798095cbc43f9)
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/repl/local_oplog_info.cpp5
-rw-r--r--src/mongo/db/repl/oplog.cpp24
2 files changed, 18 insertions, 11 deletions
diff --git a/src/mongo/db/repl/local_oplog_info.cpp b/src/mongo/db/repl/local_oplog_info.cpp
index a712d9c2777..069c199def1 100644
--- a/src/mongo/db/repl/local_oplog_info.cpp
+++ b/src/mongo/db/repl/local_oplog_info.cpp
@@ -74,7 +74,10 @@ void LocalOplogInfo::setOplogCollectionName(ServiceContext* service) {
_oplogName = NamespaceString::kRsOplogNamespace;
break;
case ReplicationCoordinator::modeNone:
- // leave empty.
+ if (ReplSettings::shouldRecoverFromOplogAsStandalone()) {
+ _oplogName = NamespaceString::kRsOplogNamespace;
+ }
+ // leave empty otherwise.
break;
}
}
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 1335c308b85..d9fc1390de3 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -1417,26 +1417,30 @@ Status applyOperation_inlock(OperationContext* opCtx,
// We do not assign timestamps on replicated writes since they will get their oplog
// timestamp once they are logged.
return false;
+ } else if (haveWrappingWriteUnitOfWork) {
+ // We do not assign timestamps to non-replicated writes that have a wrapping
+ // WriteUnitOfWork, as they will get the timestamp on that WUOW.
+ // The typical usage of this is for operations inside of atomic 'applyOps' commands
+ // being applied on a secondary. They will get the timestamp of the outer 'applyOps'
+ // oplog entry in their wrapper WUOW.
+ // We also use a WUOW for replaying a prepared transaction when we encounter its
+ // corresponding commitTransaction entry during recovery. We set the timestamp on the
+ // WUOW to be the commit timestamp.
+ return false;
} else {
switch (replMode) {
case ReplicationCoordinator::modeReplSet: {
- if (haveWrappingWriteUnitOfWork) {
- // We do not assign timestamps to non-replicated writes that have a wrapping
- // WUOW. These must be operations inside of atomic 'applyOps' commands being
- // applied on a secondary. They will get the timestamp of the outer
- // 'applyOps' oplog entry in their wrapper WUOW.
- return false;
- }
- break;
+ // We typically timestamp these writes, unless they are in a WUOW.
+ return true;
}
case ReplicationCoordinator::modeNone: {
// Only assign timestamps on standalones during replication recovery when
- // started with 'recoverFromOplogAsStandalone'.
+ // started with the 'recoverFromOplogAsStandalone' flag.
return mode == OplogApplication::Mode::kRecovering;
}
}
}
- return true;
+ MONGO_UNREACHABLE;
}();
invariant(!assignOperationTimestamp || !fieldTs.eoo(),
str::stream() << "Oplog entry did not have 'ts' field when expected: " << redact(op));