summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2020-04-30 18:27:05 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-27 02:30:14 +0000
commitd7ad6f6c417e711218729f2faee7fc59a19a5e5d (patch)
treed4fa8ef4614d4d252d9b387b9cfc06ef92b300c7
parent928320fcd24806a8292216fb17642cd69410459c (diff)
downloadmongo-d7ad6f6c417e711218729f2faee7fc59a19a5e5d.tar.gz
SERVER-47695: Don't set lastOp for client backwards in terms of timestamp after rollback
(cherry picked from commit bd579c0d3f2583c2af7dcd98c7f6cfc55009b406) (cherry picked from commit bf3227e11dd689044ff4555c823c682899f41cf9)
-rw-r--r--src/mongo/db/repl/repl_client_info.cpp11
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 254bbfcf541..6727312ed32 100644
--- a/src/mongo/db/repl/repl_client_info.cpp
+++ b/src/mongo/db/repl/repl_client_info.cpp
@@ -56,10 +56,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