diff options
author | Lamont Nelson <lamont.nelson@mongodb.com> | 2020-06-04 16:36:26 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-10 00:55:41 +0000 |
commit | ea468d841174cdf4678b747cefbe0abcb4e969eb (patch) | |
tree | 88d4f00cdc1a9e966c8dcffb16b652daf0561058 | |
parent | 0620421a92e9fb9d3e638c1a221ed43b49641516 (diff) | |
download | mongo-ea468d841174cdf4678b747cefbe0abcb4e969eb.tar.gz |
SERVER-48070: account for system clock drift when calculating the time since the last isMaster
(cherry picked from commit 7d6fb98b2ff8758cf246d8e0260487f805e16663)
-rw-r--r-- | src/mongo/client/server_is_master_monitor.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/mongo/client/server_is_master_monitor.cpp b/src/mongo/client/server_is_master_monitor.cpp index ad360946436..894b481aa9a 100644 --- a/src/mongo/client/server_is_master_monitor.cpp +++ b/src/mongo/client/server_is_master_monitor.cpp @@ -165,7 +165,10 @@ boost::optional<Milliseconds> SingleServerIsMasterMonitor::calculateExpeditedDel } boost::optional<Milliseconds> SingleServerIsMasterMonitor::_timeSinceLastCheck() const { - return (_lastIsMasterAt) ? boost::optional<Milliseconds>(_executor->now() - *_lastIsMasterAt) + // Since the system clock is not monotonic, the returned value can be negative. In this case we + // choose a conservative estimate of 0ms as the time we last checked. + return (_lastIsMasterAt) ? boost::optional<Milliseconds>( + std::max(Milliseconds(0), _executor->now() - *_lastIsMasterAt)) : boost::none; } |