summaryrefslogtreecommitdiff
path: root/src/mongo/s/catalog/catalog_cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/catalog/catalog_cache.cpp')
-rw-r--r--src/mongo/s/catalog/catalog_cache.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/mongo/s/catalog/catalog_cache.cpp b/src/mongo/s/catalog/catalog_cache.cpp
index cde72edbc46..b418977f8b2 100644
--- a/src/mongo/s/catalog/catalog_cache.cpp
+++ b/src/mongo/s/catalog/catalog_cache.cpp
@@ -41,11 +41,12 @@ namespace mongo {
using std::shared_ptr;
using std::string;
+CatalogCache::CatalogCache() = default;
-CatalogCache::CatalogCache() {}
+CatalogCache::~CatalogCache() = default;
-StatusWith<shared_ptr<DBConfig>> CatalogCache::getDatabase(OperationContext* txn,
- const string& dbName) {
+StatusWith<std::shared_ptr<DBConfig>> CatalogCache::getDatabase(OperationContext* txn,
+ StringData dbName) {
stdx::lock_guard<stdx::mutex> guard(_mutex);
ShardedDatabasesMap::iterator it = _databases.find(dbName);
@@ -54,25 +55,26 @@ StatusWith<shared_ptr<DBConfig>> CatalogCache::getDatabase(OperationContext* txn
}
// Need to load from the store
- auto status = Grid::get(txn)->catalogClient(txn)->getDatabase(txn, dbName);
+ auto status = Grid::get(txn)->catalogClient(txn)->getDatabase(txn, dbName.toString());
if (!status.isOK()) {
return status.getStatus();
}
- const auto dbOpTimePair = status.getValue();
- shared_ptr<DBConfig> db = std::make_shared<DBConfig>(dbOpTimePair.value, dbOpTimePair.opTime);
+ const auto& dbOpTimePair = status.getValue();
+ auto db = std::make_shared<DBConfig>(dbOpTimePair.value, dbOpTimePair.opTime);
try {
db->load(txn);
} catch (const DBException& excep) {
return excep.toStatus();
}
- invariant(_databases.insert(std::make_pair(dbName, db)).second);
+ auto emplaceResult = _databases.try_emplace(dbName, std::move(db));
+ invariant(emplaceResult.second);
- return db;
+ return emplaceResult.first->second;
}
-void CatalogCache::invalidate(const string& dbName) {
+void CatalogCache::invalidate(StringData dbName) {
stdx::lock_guard<stdx::mutex> guard(_mutex);
ShardedDatabasesMap::iterator it = _databases.find(dbName);