summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2020-05-10 06:48:54 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-17 15:16:51 +0000
commit7e2111ef33fc40959a254bd3109466176ae60718 (patch)
tree2a31ac8ddccccb24784b161839fa1ca92aeb10bf /src/mongo/db
parenta7f769dd597e33e988832c43c99912c1d3139c9b (diff)
downloadmongo-7e2111ef33fc40959a254bd3109466176ae60718.tar.gz
SERVER-46154 Pull the InProgressLookup outside of ReadThroughCache
The InProgressLookup tracking already has quite complicated logic, so it seems prudent to pull it into a separate class, outside of the ReadThroughCache so it can be tested independently.
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/auth/authorization_manager_impl.cpp13
-rw-r--r--src/mongo/db/auth/authorization_manager_impl.h4
-rw-r--r--src/mongo/db/read_write_concern_defaults.cpp11
3 files changed, 15 insertions, 13 deletions
diff --git a/src/mongo/db/auth/authorization_manager_impl.cpp b/src/mongo/db/auth/authorization_manager_impl.cpp
index e3552ae7332..5f6e9ab1380 100644
--- a/src/mongo/db/auth/authorization_manager_impl.cpp
+++ b/src/mongo/db/auth/authorization_manager_impl.cpp
@@ -663,14 +663,14 @@ AuthorizationManagerImpl::AuthSchemaVersionCache::AuthSchemaVersionCache(
1 /* cacheSize */),
_externalState(externalState) {}
-boost::optional<int> AuthorizationManagerImpl::AuthSchemaVersionCache::_lookup(
- OperationContext* opCtx, int unusedKey) {
+AuthorizationManagerImpl::AuthSchemaVersionCache::LookupResult
+AuthorizationManagerImpl::AuthSchemaVersionCache::_lookup(OperationContext* opCtx, int unusedKey) {
invariant(unusedKey == 0);
int authzVersion;
uassertStatusOK(_externalState->getStoredAuthorizationVersion(opCtx, &authzVersion));
- return authzVersion;
+ return LookupResult(authzVersion);
}
AuthorizationManagerImpl::UserCacheImpl::UserCacheImpl(
@@ -689,8 +689,9 @@ AuthorizationManagerImpl::UserCacheImpl::UserCacheImpl(
_authSchemaVersionCache(authSchemaVersionCache),
_externalState(externalState) {}
-boost::optional<User> AuthorizationManagerImpl::UserCacheImpl::_lookup(OperationContext* opCtx,
- const UserRequest& userReq) {
+AuthorizationManagerImpl::UserCacheImpl::LookupResult
+AuthorizationManagerImpl::UserCacheImpl::_lookup(OperationContext* opCtx,
+ const UserRequest& userReq) {
LOGV2_DEBUG(20238, 1, "Getting user record", "user"_attr = userReq.name);
// Number of times to retry a user document that fetches due to transient AuthSchemaIncompatible
@@ -713,7 +714,7 @@ boost::optional<User> AuthorizationManagerImpl::UserCacheImpl::_lookup(Operation
User user(userReq.name);
uassertStatusOK(initializeUserFromPrivilegeDocument(&user, userObj));
- return user;
+ return LookupResult(std::move(user));
}
case schemaVersion24:
_authSchemaVersionCache->invalidateAll();
diff --git a/src/mongo/db/auth/authorization_manager_impl.h b/src/mongo/db/auth/authorization_manager_impl.h
index 17a3d731f1f..611aa427662 100644
--- a/src/mongo/db/auth/authorization_manager_impl.h
+++ b/src/mongo/db/auth/authorization_manager_impl.h
@@ -158,7 +158,7 @@ private:
// Even though the dist cache permits for lookup to return boost::none for non-existent
// values, the contract of the authorization manager is that it should throw an exception if
// the value can not be loaded, so if it returns, the value will always be set.
- boost::optional<int> _lookup(OperationContext* opCtx, int unusedKey);
+ LookupResult _lookup(OperationContext* opCtx, int unusedKey);
Mutex _mutex =
MONGO_MAKE_LATCH("AuthorizationManagerImpl::AuthSchemaVersionDistCache::_mutex");
@@ -181,7 +181,7 @@ private:
// Even though the dist cache permits for lookup to return boost::none for non-existent
// values, the contract of the authorization manager is that it should throw an exception if
// the value can not be loaded, so if it returns, the value will always be set.
- boost::optional<User> _lookup(OperationContext* opCtx, const UserRequest& user);
+ LookupResult _lookup(OperationContext* opCtx, const UserRequest& user);
Mutex _mutex = MONGO_MAKE_LATCH("AuthorizationManagerImpl::UserDistCacheImpl::_mutex");
diff --git a/src/mongo/db/read_write_concern_defaults.cpp b/src/mongo/db/read_write_concern_defaults.cpp
index f33c78215a3..3c69751348a 100644
--- a/src/mongo/db/read_write_concern_defaults.cpp
+++ b/src/mongo/db/read_write_concern_defaults.cpp
@@ -237,11 +237,12 @@ ReadWriteConcernDefaults::~ReadWriteConcernDefaults() = default;
ReadWriteConcernDefaults::Cache::Cache(ServiceContext* service,
ThreadPoolInterface& threadPool,
FetchDefaultsFn fetchDefaultsFn)
- : ReadThroughCache(_mutex,
- service,
- threadPool,
- [this](OperationContext* opCtx, Type) { return lookup(opCtx); },
- 1 /* cacheSize */),
+ : ReadThroughCache(
+ _mutex,
+ service,
+ threadPool,
+ [this](OperationContext* opCtx, Type) { return LookupResult(lookup(opCtx)); },
+ 1 /* cacheSize */),
_fetchDefaultsFn(std::move(fetchDefaultsFn)) {}
boost::optional<RWConcernDefault> ReadWriteConcernDefaults::Cache::lookup(OperationContext* opCtx) {