@@ -118,19 +118,10 @@ std::shared_ptr<RoutingTableHistory> refreshCollectionRoutingInfo(
118
118
CatalogCache::CatalogCache (CatalogCacheLoader& cacheLoader) : _cacheLoader(cacheLoader) {}
119
119
120
120
CatalogCache::~CatalogCache () = default ;
121
+
121
122
StatusWith<CachedDatabaseInfo> CatalogCache::getDatabase (OperationContext* opCtx,
122
123
StringData dbName) {
123
- return _getDatabase (opCtx, dbName).status ;
124
- }
125
-
126
- CatalogCache::RefreshResult<CachedDatabaseInfo> CatalogCache::_getDatabase (OperationContext* opCtx,
127
- StringData dbName) {
128
- using DatabaseInfoRefreshResult = RefreshResult<CachedDatabaseInfo>;
129
- using DatabaseInfoRefreshAction = RefreshResult<CachedDatabaseInfo>::RefreshAction;
130
-
131
- DatabaseInfoRefreshAction refreshActionTaken;
132
124
try {
133
- // Whether we performed refresh or someone else or not at all
134
125
while (true ) {
135
126
stdx::unique_lock<stdx::mutex> ul (_mutex);
136
127
@@ -145,9 +136,6 @@ CatalogCache::RefreshResult<CachedDatabaseInfo> CatalogCache::_getDatabase(Opera
145
136
refreshNotification = (dbEntry->refreshCompletionNotification =
146
137
std::make_shared<Notification<Status>>());
147
138
_scheduleDatabaseRefresh (ul, dbName.toString (), dbEntry);
148
- refreshActionTaken = DatabaseInfoRefreshAction::kPerformedRefresh ;
149
- } else {
150
- refreshActionTaken = DatabaseInfoRefreshAction::kJoinedInProgressRefresh ;
151
139
}
152
140
153
141
// Wait on the notification outside of the mutex.
@@ -183,53 +171,41 @@ CatalogCache::RefreshResult<CachedDatabaseInfo> CatalogCache::_getDatabase(Opera
183
171
184
172
auto primaryShard = uassertStatusOK (
185
173
Grid::get (opCtx)->shardRegistry ()->getShard (opCtx, dbEntry->dbt ->getPrimary ()));
186
- return {CachedDatabaseInfo (*dbEntry->dbt , std::move (primaryShard)), refreshActionTaken };
174
+ return {CachedDatabaseInfo (*dbEntry->dbt , std::move (primaryShard))};
187
175
}
188
176
} catch (const DBException& ex) {
189
- return { ex.toStatus (), refreshActionTaken} ;
177
+ return ex.toStatus ();
190
178
}
191
179
}
192
180
193
181
StatusWith<CachedCollectionRoutingInfo> CatalogCache::getCollectionRoutingInfo (
194
- OperationContext* opCtx, const NamespaceString& nss) {
195
- return _getCollectionRoutingInfo (opCtx, nss).status ;
196
- }
197
-
198
- CatalogCache::RefreshResult<CachedCollectionRoutingInfo> CatalogCache::_getCollectionRoutingInfo (
199
182
OperationContext* opCtx, const NamespaceString& nss) {
200
183
return _getCollectionRoutingInfoAt (opCtx, nss, boost::none);
201
184
}
202
185
203
-
204
186
StatusWith<CachedCollectionRoutingInfo> CatalogCache::getCollectionRoutingInfoAt (
205
187
OperationContext* opCtx, const NamespaceString& nss, Timestamp atClusterTime) {
206
- return _getCollectionRoutingInfoAt (opCtx, nss, atClusterTime). status ;
188
+ return _getCollectionRoutingInfoAt (opCtx, nss, atClusterTime);
207
189
}
208
190
209
- CatalogCache::RefreshResult <CachedCollectionRoutingInfo> CatalogCache::_getCollectionRoutingInfoAt (
191
+ StatusWith <CachedCollectionRoutingInfo> CatalogCache::_getCollectionRoutingInfoAt (
210
192
OperationContext* opCtx, const NamespaceString& nss, boost::optional<Timestamp> atClusterTime) {
211
- using CollectionRoutingInfoRefreshResult = RefreshResult<CachedCollectionRoutingInfo>;
212
- using CollectionRoutingInfoRefreshAction =
213
- RefreshResult<CachedCollectionRoutingInfo>::RefreshAction;
214
- CollectionRoutingInfoRefreshAction refreshActionTaken;
215
193
while (true ) {
216
194
const auto swDbInfo = getDatabase (opCtx, nss.db ());
217
195
if (!swDbInfo.isOK ()) {
218
- return { swDbInfo.getStatus (), CollectionRoutingInfoRefreshAction:: kPerformedRefresh } ;
196
+ return swDbInfo.getStatus ();
219
197
}
220
198
const auto dbInfo = std::move (swDbInfo.getValue ());
221
199
222
200
stdx::unique_lock<stdx::mutex> ul (_mutex);
223
201
224
202
const auto itDb = _collectionsByDb.find (nss.db ());
225
203
if (itDb == _collectionsByDb.end ()) {
226
- return {CachedCollectionRoutingInfo (nss, dbInfo, nullptr ),
227
- CollectionRoutingInfoRefreshAction::kPerformedRefresh };
204
+ return {CachedCollectionRoutingInfo (nss, dbInfo, nullptr )};
228
205
}
229
206
const auto itColl = itDb->second .find (nss.ns ());
230
207
if (itColl == itDb->second .end ()) {
231
- return {CachedCollectionRoutingInfo (nss, dbInfo, nullptr ),
232
- CollectionRoutingInfoRefreshAction::kPerformedRefresh };
208
+ return {CachedCollectionRoutingInfo (nss, dbInfo, nullptr )};
233
209
}
234
210
auto & collEntry = itColl->second ;
235
211
@@ -239,9 +215,6 @@ CatalogCache::RefreshResult<CachedCollectionRoutingInfo> CatalogCache::_getColle
239
215
refreshNotification = (collEntry->refreshCompletionNotification =
240
216
std::make_shared<Notification<Status>>());
241
217
_scheduleCollectionRefresh (ul, collEntry, nss, 1 );
242
- refreshActionTaken = CollectionRoutingInfoRefreshAction::kPerformedRefresh ;
243
- } else {
244
- refreshActionTaken = CollectionRoutingInfoRefreshAction::kJoinedInProgressRefresh ;
245
218
}
246
219
247
220
// Wait on the notification outside of the mutex
@@ -265,7 +238,7 @@ CatalogCache::RefreshResult<CachedCollectionRoutingInfo> CatalogCache::_getColle
265
238
}();
266
239
267
240
if (!refreshStatus.isOK ()) {
268
- return { refreshStatus, refreshActionTaken} ;
241
+ return refreshStatus;
269
242
}
270
243
271
244
// Once the refresh is complete, loop around to get the latest value
@@ -274,42 +247,20 @@ CatalogCache::RefreshResult<CachedCollectionRoutingInfo> CatalogCache::_getColle
274
247
275
248
auto cm = std::make_shared<ChunkManager>(collEntry->routingInfo , atClusterTime);
276
249
277
- return {CachedCollectionRoutingInfo (nss, dbInfo, std::move (cm)), refreshActionTaken };
250
+ return {CachedCollectionRoutingInfo (nss, dbInfo, std::move (cm))};
278
251
}
279
252
}
280
253
281
254
StatusWith<CachedDatabaseInfo> CatalogCache::getDatabaseWithRefresh (OperationContext* opCtx,
282
255
StringData dbName) {
283
256
invalidateDatabaseEntry (dbName);
284
- auto refreshResult = _getDatabase (opCtx, dbName);
285
- // We want to ensure that we don't join an in-progress refresh because that
286
- // could violate causal consistency for this client. We don't need to actually perform the
287
- // refresh ourselves but we do need the refresh to begin *after* this function is
288
- // called, so calling it twice is enough regardless of what happens the
289
- // second time. See SERVER-33954 for reasoning.
290
- if (refreshResult.actionTaken ==
291
- RefreshResult<CachedDatabaseInfo>::RefreshAction::kJoinedInProgressRefresh ) {
292
- invalidateDatabaseEntry (dbName);
293
- refreshResult = _getDatabase (opCtx, dbName);
294
- }
295
- return refreshResult.status ;
257
+ return getDatabase (opCtx, dbName);
296
258
}
297
259
298
260
StatusWith<CachedCollectionRoutingInfo> CatalogCache::getCollectionRoutingInfoWithRefresh (
299
261
OperationContext* opCtx, const NamespaceString& nss) {
300
262
invalidateShardedCollection (nss);
301
- auto refreshResult = _getCollectionRoutingInfo (opCtx, nss);
302
- // We want to ensure that we don't join an in-progress refresh because that
303
- // could violate causal consistency for this client. We don't need to actually perform the
304
- // refresh ourselves but we do need the refresh to begin *after* this function is
305
- // called, so calling it twice is enough regardless of what happens the
306
- // second time. See SERVER-33954 for reasoning.
307
- if (refreshResult.actionTaken ==
308
- RefreshResult<CachedCollectionRoutingInfo>::RefreshAction::kJoinedInProgressRefresh ) {
309
- invalidateShardedCollection (nss);
310
- refreshResult = _getCollectionRoutingInfo (opCtx, nss);
311
- }
312
- return refreshResult.status ;
263
+ return getCollectionRoutingInfo (opCtx, nss);
313
264
}
314
265
315
266
StatusWith<CachedCollectionRoutingInfo> CatalogCache::getShardedCollectionRoutingInfoWithRefresh (
0 commit comments