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-05 17:02:48 +0000 |
commit | 7d6fb98b2ff8758cf246d8e0260487f805e16663 (patch) | |
tree | aa9cb3f03a1087335e46ad78993495197ec11f19 | |
parent | 11e55b207f4dfc9432c4be7066e8c584cb832a0b (diff) | |
download | mongo-7d6fb98b2ff8758cf246d8e0260487f805e16663.tar.gz |
SERVER-48070: account for system clock drift when calculating the time since the last isMaster
-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 321bffca176..7fe68565ca4 100644 --- a/src/mongo/client/server_is_master_monitor.cpp +++ b/src/mongo/client/server_is_master_monitor.cpp @@ -166,7 +166,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; } |