diff options
author | Spencer T Brody <spencer@mongodb.com> | 2017-08-25 14:37:50 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2017-10-05 11:12:10 -0400 |
commit | 88049437b3bdf8df78051b9885b9600892640141 (patch) | |
tree | 6d10dcea075cc5e64c0d0d9e0c5e3051f28d7a38 /src/mongo | |
parent | ebf6c1194dbe71c2d965524aa598953ab602b604 (diff) | |
download | mongo-88049437b3bdf8df78051b9885b9600892640141.tar.gz |
SERVER-30842 Don't try to set last optime for client backwards after rollback
(cherry picked from commit cee116558d7771b520c0fd4dd239c0a987dcc2ec)
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/repl/repl_client_info.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/mongo/db/repl/repl_client_info.cpp b/src/mongo/db/repl/repl_client_info.cpp index 3e98a0cb9d3..5b77e3aa6f3 100644 --- a/src/mongo/db/repl/repl_client_info.cpp +++ b/src/mongo/db/repl/repl_client_info.cpp @@ -26,6 +26,8 @@ * it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kReplication + #include "mongo/platform/basic.h" #include "mongo/db/repl/repl_client_info.h" @@ -36,6 +38,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/util/decorable.h" +#include "mongo/util/log.h" namespace mongo { namespace repl { @@ -48,10 +51,23 @@ void ReplClientInfo::setLastOp(const OpTime& ot) { _lastOp = ot; } + void ReplClientInfo::setLastOpToSystemLastOpTime(OperationContext* txn) { ReplicationCoordinator* replCoord = repl::ReplicationCoordinator::get(txn->getServiceContext()); if (replCoord->isReplEnabled() && txn->writesAreReplicated()) { - setLastOp(replCoord->getMyLastAppliedOpTime()); + auto systemOpTime = replCoord->getMyLastAppliedOpTime(); + + // If the system optime has gone backwards, that must mean that there was a rollback. + // This is safe, but the last op for a Client should never go backwards, so just leave + // the last op for this Client as it was. + if (systemOpTime >= _lastOp) { + _lastOp = systemOpTime; + } else { + log() << "Not setting the last OpTime for this Client from " << _lastOp + << " to the current system time of " << systemOpTime + << " as that would be moving the OpTime backwards. This should only happen if " + "there was a rollback recently"; + } } } |