diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2020-04-30 18:27:05 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-06 18:11:43 +0000 |
commit | bf3227e11dd689044ff4555c823c682899f41cf9 (patch) | |
tree | 8c65eb4a31e609ebd122828796ef951f04a121b8 | |
parent | e7b5473adb156afc20e8ff3b53446d5e17bec2d2 (diff) | |
download | mongo-bf3227e11dd689044ff4555c823c682899f41cf9.tar.gz |
SERVER-47695: Don't set lastOp for client backwards in terms of timestamp after rollback
(cherry picked from commit bd579c0d3f2583c2af7dcd98c7f6cfc55009b406)
-rw-r--r-- | src/mongo/db/repl/repl_client_info.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/mongo/db/repl/repl_client_info.cpp b/src/mongo/db/repl/repl_client_info.cpp index dc4c04342c7..370638aa250 100644 --- a/src/mongo/db/repl/repl_client_info.cpp +++ b/src/mongo/db/repl/repl_client_info.cpp @@ -71,10 +71,13 @@ void ReplClientInfo::setLastOpToSystemLastOpTime(OperationContext* opCtx) { if (replCoord->isReplEnabled() && opCtx->writesAreReplicated()) { 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) { + // If the system timestamp has gone backwards, that must mean that there was a rollback. + // If the system optime has a higher term but a lower timestamp than the client's lastOp, it + // means that this node's wallclock time was ahead of the current primary's before it rolled + // back. This is safe, but the timestamp of the last op for a Client should never go + // backwards, so just leave the last op for this Client as it was. + if (systemOpTime.getTerm() >= _lastOp.getTerm() && + systemOpTime.getTimestamp() >= _lastOp.getTimestamp()) { _lastOp = systemOpTime; } else { log() << "Not setting the last OpTime for this Client from " << _lastOp |