49
49
#include " mongo/util/background.h"
50
50
#include " mongo/util/concurrency/idle_thread_block.h"
51
51
#include " mongo/util/duration.h"
52
- #include " mongo/util/exit.h"
53
52
#include " mongo/util/log.h"
54
53
#include " mongo/util/time_support.h"
55
54
@@ -71,20 +70,36 @@ class ThreadSleepInterval {
71
70
}
72
71
73
72
void start () {
73
+ stdx::unique_lock<Latch> lock (_mutex);
74
74
_last = Date_t::now ();
75
75
}
76
76
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 () {
78
89
stdx::unique_lock<Latch> lock (_mutex);
79
90
while (true ) {
91
+ if (_inShutdown) {
92
+ return false ;
93
+ }
94
+
80
95
Date_t now = Date_t::now ();
81
96
Date_t expiry = _last + _interval;
82
97
MONGO_LOG (5 ) << " wait: now=" << now << " , expiry=" << expiry;
83
98
84
99
if (now >= expiry) {
85
100
_last = now;
86
101
MONGO_LOG (5 ) << " wait: done" ;
87
- return ;
102
+ return true ;
88
103
}
89
104
90
105
MONGO_LOG (5 ) << " wait: blocking" ;
@@ -97,6 +112,7 @@ class ThreadSleepInterval {
97
112
Seconds _interval;
98
113
Mutex _mutex = MONGO_MAKE_LATCH(" ThreadSleepInterval::_mutex" );
99
114
stdx::condition_variable _condition;
115
+ bool _inShutdown = false ;
100
116
Date_t _last;
101
117
};
102
118
@@ -136,7 +152,7 @@ UserCacheInvalidator::UserCacheInvalidator(AuthorizationManager* authzManager)
136
152
: _authzManager(authzManager) {}
137
153
138
154
UserCacheInvalidator::~UserCacheInvalidator () {
139
- invariant ( globalInShutdownDeprecated () );
155
+ globalInvalidationInterval ()-> abort ( );
140
156
// Wait to stop running.
141
157
wait ();
142
158
}
@@ -164,25 +180,14 @@ void UserCacheInvalidator::run() {
164
180
Client::initThread (" UserCacheInvalidator" );
165
181
auto interval = globalInvalidationInterval ();
166
182
interval->start ();
167
- while (true ) {
168
- interval->wait ();
169
-
170
- if (globalInShutdownDeprecated ()) {
171
- break ;
172
- }
173
-
183
+ while (interval->wait ()) {
174
184
auto opCtx = cc ().makeOperationContext ();
175
185
StatusWith<OID> currentGeneration = getCurrentCacheGeneration (opCtx.get ());
176
186
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
+
186
191
// When in doubt, invalidate the cache
187
192
try {
188
193
_authzManager->invalidateUserCache (opCtx.get ());
0 commit comments