Skip to content

Commit 316bcc9

Browse files
committed
Revert "SERVER-33954 Modified getDatabaseWithRefresh/getCollectionRoutingInfoWithRefresh to refresh twice if the first refresh is not performed by its own thread"
This reverts commit a000fcd.
1 parent f8ca0b9 commit 316bcc9

File tree

2 files changed

+13
-97
lines changed

2 files changed

+13
-97
lines changed

src/mongo/s/catalog_cache.cpp

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,10 @@ std::shared_ptr<RoutingTableHistory> refreshCollectionRoutingInfo(
118118
CatalogCache::CatalogCache(CatalogCacheLoader& cacheLoader) : _cacheLoader(cacheLoader) {}
119119

120120
CatalogCache::~CatalogCache() = default;
121+
121122
StatusWith<CachedDatabaseInfo> CatalogCache::getDatabase(OperationContext* opCtx,
122123
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;
132124
try {
133-
// Whether we performed refresh or someone else or not at all
134125
while (true) {
135126
stdx::unique_lock<stdx::mutex> ul(_mutex);
136127

@@ -145,9 +136,6 @@ CatalogCache::RefreshResult<CachedDatabaseInfo> CatalogCache::_getDatabase(Opera
145136
refreshNotification = (dbEntry->refreshCompletionNotification =
146137
std::make_shared<Notification<Status>>());
147138
_scheduleDatabaseRefresh(ul, dbName.toString(), dbEntry);
148-
refreshActionTaken = DatabaseInfoRefreshAction::kPerformedRefresh;
149-
} else {
150-
refreshActionTaken = DatabaseInfoRefreshAction::kJoinedInProgressRefresh;
151139
}
152140

153141
// Wait on the notification outside of the mutex.
@@ -183,53 +171,41 @@ CatalogCache::RefreshResult<CachedDatabaseInfo> CatalogCache::_getDatabase(Opera
183171

184172
auto primaryShard = uassertStatusOK(
185173
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))};
187175
}
188176
} catch (const DBException& ex) {
189-
return {ex.toStatus(), refreshActionTaken};
177+
return ex.toStatus();
190178
}
191179
}
192180

193181
StatusWith<CachedCollectionRoutingInfo> CatalogCache::getCollectionRoutingInfo(
194-
OperationContext* opCtx, const NamespaceString& nss) {
195-
return _getCollectionRoutingInfo(opCtx, nss).status;
196-
}
197-
198-
CatalogCache::RefreshResult<CachedCollectionRoutingInfo> CatalogCache::_getCollectionRoutingInfo(
199182
OperationContext* opCtx, const NamespaceString& nss) {
200183
return _getCollectionRoutingInfoAt(opCtx, nss, boost::none);
201184
}
202185

203-
204186
StatusWith<CachedCollectionRoutingInfo> CatalogCache::getCollectionRoutingInfoAt(
205187
OperationContext* opCtx, const NamespaceString& nss, Timestamp atClusterTime) {
206-
return _getCollectionRoutingInfoAt(opCtx, nss, atClusterTime).status;
188+
return _getCollectionRoutingInfoAt(opCtx, nss, atClusterTime);
207189
}
208190

209-
CatalogCache::RefreshResult<CachedCollectionRoutingInfo> CatalogCache::_getCollectionRoutingInfoAt(
191+
StatusWith<CachedCollectionRoutingInfo> CatalogCache::_getCollectionRoutingInfoAt(
210192
OperationContext* opCtx, const NamespaceString& nss, boost::optional<Timestamp> atClusterTime) {
211-
using CollectionRoutingInfoRefreshResult = RefreshResult<CachedCollectionRoutingInfo>;
212-
using CollectionRoutingInfoRefreshAction =
213-
RefreshResult<CachedCollectionRoutingInfo>::RefreshAction;
214-
CollectionRoutingInfoRefreshAction refreshActionTaken;
215193
while (true) {
216194
const auto swDbInfo = getDatabase(opCtx, nss.db());
217195
if (!swDbInfo.isOK()) {
218-
return {swDbInfo.getStatus(), CollectionRoutingInfoRefreshAction::kPerformedRefresh};
196+
return swDbInfo.getStatus();
219197
}
220198
const auto dbInfo = std::move(swDbInfo.getValue());
221199

222200
stdx::unique_lock<stdx::mutex> ul(_mutex);
223201

224202
const auto itDb = _collectionsByDb.find(nss.db());
225203
if (itDb == _collectionsByDb.end()) {
226-
return {CachedCollectionRoutingInfo(nss, dbInfo, nullptr),
227-
CollectionRoutingInfoRefreshAction::kPerformedRefresh};
204+
return {CachedCollectionRoutingInfo(nss, dbInfo, nullptr)};
228205
}
229206
const auto itColl = itDb->second.find(nss.ns());
230207
if (itColl == itDb->second.end()) {
231-
return {CachedCollectionRoutingInfo(nss, dbInfo, nullptr),
232-
CollectionRoutingInfoRefreshAction::kPerformedRefresh};
208+
return {CachedCollectionRoutingInfo(nss, dbInfo, nullptr)};
233209
}
234210
auto& collEntry = itColl->second;
235211

@@ -239,9 +215,6 @@ CatalogCache::RefreshResult<CachedCollectionRoutingInfo> CatalogCache::_getColle
239215
refreshNotification = (collEntry->refreshCompletionNotification =
240216
std::make_shared<Notification<Status>>());
241217
_scheduleCollectionRefresh(ul, collEntry, nss, 1);
242-
refreshActionTaken = CollectionRoutingInfoRefreshAction::kPerformedRefresh;
243-
} else {
244-
refreshActionTaken = CollectionRoutingInfoRefreshAction::kJoinedInProgressRefresh;
245218
}
246219

247220
// Wait on the notification outside of the mutex
@@ -265,7 +238,7 @@ CatalogCache::RefreshResult<CachedCollectionRoutingInfo> CatalogCache::_getColle
265238
}();
266239

267240
if (!refreshStatus.isOK()) {
268-
return {refreshStatus, refreshActionTaken};
241+
return refreshStatus;
269242
}
270243

271244
// Once the refresh is complete, loop around to get the latest value
@@ -274,42 +247,20 @@ CatalogCache::RefreshResult<CachedCollectionRoutingInfo> CatalogCache::_getColle
274247

275248
auto cm = std::make_shared<ChunkManager>(collEntry->routingInfo, atClusterTime);
276249

277-
return {CachedCollectionRoutingInfo(nss, dbInfo, std::move(cm)), refreshActionTaken};
250+
return {CachedCollectionRoutingInfo(nss, dbInfo, std::move(cm))};
278251
}
279252
}
280253

281254
StatusWith<CachedDatabaseInfo> CatalogCache::getDatabaseWithRefresh(OperationContext* opCtx,
282255
StringData dbName) {
283256
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);
296258
}
297259

298260
StatusWith<CachedCollectionRoutingInfo> CatalogCache::getCollectionRoutingInfoWithRefresh(
299261
OperationContext* opCtx, const NamespaceString& nss) {
300262
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);
313264
}
314265

315266
StatusWith<CachedCollectionRoutingInfo> CatalogCache::getShardedCollectionRoutingInfoWithRefresh(

src/mongo/s/catalog_cache.h

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -211,33 +211,6 @@ class CatalogCache {
211211
boost::optional<DatabaseType> dbt;
212212
};
213213

214-
/**
215-
* Return type for helper functions performing refreshes so that they can
216-
* indicate both status and whether or not this thread joined an in
217-
* progress refresh.
218-
*/
219-
template <class T>
220-
struct RefreshResult {
221-
// Status containing result of refresh
222-
StatusWith<T> status;
223-
224-
// Flag indicating whether or not this thread performed its own
225-
// refresh. kDidNotPerformRefresh could mean that either no refresh was
226-
// performed at all (which would be indicated by the status) or that it
227-
// joined an already in-progress refresh.
228-
enum class RefreshAction {
229-
kPerformedRefresh,
230-
kJoinedInProgressRefresh,
231-
} actionTaken;
232-
};
233-
234-
/**
235-
* Helper function for getDatabase that includes in its result what refresh
236-
* action was taken
237-
*/
238-
RefreshResult<CachedDatabaseInfo> _getDatabase(OperationContext* opCtx, StringData dbName);
239-
240-
241214
/**
242215
* Non-blocking call which schedules an asynchronous refresh for the specified database. The
243216
* database entry must be in the 'needsRefresh' state.
@@ -255,15 +228,7 @@ class CatalogCache {
255228
NamespaceString const& nss,
256229
int refreshAttempt);
257230

258-
259-
/**
260-
* Helper function used when we need the refresh action taken (e.g. when we
261-
* want to force refresh)
262-
*/
263-
RefreshResult<CachedCollectionRoutingInfo> _getCollectionRoutingInfo(
264-
OperationContext* opCtx, const NamespaceString& nss);
265-
266-
RefreshResult<CachedCollectionRoutingInfo> _getCollectionRoutingInfoAt(
231+
StatusWith<CachedCollectionRoutingInfo> _getCollectionRoutingInfoAt(
267232
OperationContext* opCtx,
268233
const NamespaceString& nss,
269234
boost::optional<Timestamp> atClusterTime);

0 commit comments

Comments
 (0)