diff options
author | jannaerin <golden.janna@gmail.com> | 2019-07-03 13:24:58 -0400 |
---|---|---|
committer | jannaerin <golden.janna@gmail.com> | 2019-07-08 17:09:04 -0400 |
commit | c6468f7d3ac783b4bcdeb6744fc976c8ecee2969 (patch) | |
tree | 1f425d3bc85d26cd24ff1fdf0d8c9ad81aca8d66 /src/mongo/db/s/shard_filtering_metadata_refresh.cpp | |
parent | 13434801be12a72d370147aed4c2ac194e658062 (diff) | |
download | mongo-c6468f7d3ac783b4bcdeb6744fc976c8ecee2969.tar.gz |
SERVER-34431 MoveDatabaseShardingState into its own map
Diffstat (limited to 'src/mongo/db/s/shard_filtering_metadata_refresh.cpp')
-rw-r--r-- | src/mongo/db/s/shard_filtering_metadata_refresh.cpp | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp index 155be7189d5..fe3790eaffd 100644 --- a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp +++ b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp @@ -228,29 +228,32 @@ void forceDatabaseRefresh(OperationContext* opCtx, const StringData dbName) { auto const shardingState = ShardingState::get(opCtx); invariant(shardingState->canAcceptShardedCommands()); - const auto refreshedDbVersion = - uassertStatusOK(Grid::get(opCtx)->catalogCache()->getDatabaseWithRefresh(opCtx, dbName)) - .databaseVersion(); + DatabaseVersion refreshedDbVersion; + try { + refreshedDbVersion = + uassertStatusOK(Grid::get(opCtx)->catalogCache()->getDatabaseWithRefresh(opCtx, dbName)) + .databaseVersion(); + } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) { + // db has been dropped, set the db version to boost::none + Lock::DBLock dbLock(opCtx, dbName, MODE_X); + auto dss = DatabaseShardingState::get(opCtx, dbName); + auto dssLock = DatabaseShardingState::DSSLock::lockExclusive(opCtx, dss); + + dss->setDbVersion(opCtx, boost::none, dssLock); + return; + } // First, check under a shared lock if another thread already updated the cached version. // This is a best-effort optimization to make as few threads as possible to convoy on the // exclusive lock below. - auto databaseHolder = DatabaseHolder::get(opCtx); { // Take the DBLock directly rather than using AutoGetDb, to prevent a recursive call // into checkDbVersion(). Lock::DBLock dbLock(opCtx, dbName, MODE_IS); - auto db = databaseHolder->getDb(opCtx, dbName); - if (!db) { - log() << "Database " << dbName - << " has been dropped; not caching the refreshed databaseVersion"; - return; - } + auto dss = DatabaseShardingState::get(opCtx, dbName); + auto dssLock = DatabaseShardingState::DSSLock::lockShared(opCtx, dss); - auto& dss = DatabaseShardingState::get(db); - auto dssLock = DatabaseShardingState::DSSLock::lockShared(opCtx, &dss); - - const auto cachedDbVersion = dss.getDbVersion(opCtx, dssLock); + const auto cachedDbVersion = dss->getDbVersion(opCtx, dssLock); if (cachedDbVersion && cachedDbVersion->getUuid() == refreshedDbVersion.getUuid() && cachedDbVersion->getLastMod() >= refreshedDbVersion.getLastMod()) { LOG(2) << "Skipping setting cached databaseVersion for " << dbName @@ -263,17 +266,10 @@ void forceDatabaseRefresh(OperationContext* opCtx, const StringData dbName) { // The cached version is older than the refreshed version; update the cached version. Lock::DBLock dbLock(opCtx, dbName, MODE_X); - auto db = databaseHolder->getDb(opCtx, dbName); - if (!db) { - log() << "Database " << dbName - << " has been dropped; not caching the refreshed databaseVersion"; - return; - } - - auto& dss = DatabaseShardingState::get(db); - auto dssLock = DatabaseShardingState::DSSLock::lockExclusive(opCtx, &dss); + auto dss = DatabaseShardingState::get(opCtx, dbName); + auto dssLock = DatabaseShardingState::DSSLock::lockExclusive(opCtx, dss); - dss.setDbVersion(opCtx, std::move(refreshedDbVersion), dssLock); + dss->setDbVersion(opCtx, std::move(refreshedDbVersion), dssLock); } } // namespace mongo |