4949#include " mongo/util/background.h"
5050#include " mongo/util/concurrency/idle_thread_block.h"
5151#include " mongo/util/duration.h"
52- #include " mongo/util/exit.h"
5352#include " mongo/util/log.h"
5453#include " mongo/util/time_support.h"
5554
@@ -71,20 +70,36 @@ class ThreadSleepInterval {
7170 }
7271
7372 void start () {
73+ stdx::unique_lock<Latch> lock (_mutex);
7474 _last = Date_t::now ();
7575 }
7676
77- void wait () {
77+ void abort () {
78+ stdx::unique_lock<Latch> lock (_mutex);
79+ _inShutdown = true ;
80+ _condition.notify_all ();
81+ }
82+
83+ /* *
84+ * Sleeps until either an interval has elapsed since the last call to wait(), or a shutdown
85+ * event is triggered via abort(). Returns false if interrupted due to shutdown, or true if an
86+ * interval has elapsed.
87+ */
88+ bool wait () {
7889 stdx::unique_lock<Latch> lock (_mutex);
7990 while (true ) {
91+ if (_inShutdown) {
92+ return false ;
93+ }
94+
8095 Date_t now = Date_t::now ();
8196 Date_t expiry = _last + _interval;
8297 MONGO_LOG (5 ) << " wait: now=" << now << " , expiry=" << expiry;
8398
8499 if (now >= expiry) {
85100 _last = now;
86101 MONGO_LOG (5 ) << " wait: done" ;
87- return ;
102+ return true ;
88103 }
89104
90105 MONGO_LOG (5 ) << " wait: blocking" ;
@@ -97,6 +112,7 @@ class ThreadSleepInterval {
97112 Seconds _interval;
98113 Mutex _mutex = MONGO_MAKE_LATCH(" ThreadSleepInterval::_mutex" );
99114 stdx::condition_variable _condition;
115+ bool _inShutdown = false ;
100116 Date_t _last;
101117};
102118
@@ -136,7 +152,7 @@ UserCacheInvalidator::UserCacheInvalidator(AuthorizationManager* authzManager)
136152 : _authzManager(authzManager) {}
137153
138154UserCacheInvalidator::~UserCacheInvalidator () {
139- invariant ( globalInShutdownDeprecated () );
155+ globalInvalidationInterval ()-> abort ( );
140156 // Wait to stop running.
141157 wait ();
142158}
@@ -164,25 +180,14 @@ void UserCacheInvalidator::run() {
164180 Client::initThread (" UserCacheInvalidator" );
165181 auto interval = globalInvalidationInterval ();
166182 interval->start ();
167- while (true ) {
168- interval->wait ();
169-
170- if (globalInShutdownDeprecated ()) {
171- break ;
172- }
173-
183+ while (interval->wait ()) {
174184 auto opCtx = cc ().makeOperationContext ();
175185 StatusWith<OID> currentGeneration = getCurrentCacheGeneration (opCtx.get ());
176186 if (!currentGeneration.isOK ()) {
177- if (currentGeneration.getStatus ().code () == ErrorCodes::CommandNotFound) {
178- warning () << " _getUserCacheGeneration command not found on config server(s), "
179- " this most likely means you are running an outdated version of mongod "
180- " on the config servers" ;
181- } else {
182- warning () << " An error occurred while fetching current user cache generation "
183- " to check if user cache needs invalidation: "
184- << currentGeneration.getStatus ();
185- }
187+ warning () << " An error occurred while fetching current user cache generation "
188+ " to check if user cache needs invalidation: "
189+ << currentGeneration.getStatus ();
190+
186191 // When in doubt, invalidate the cache
187192 try {
188193 _authzManager->invalidateUserCache (opCtx.get ());
0 commit comments