summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Russell <gabriel.russell@mongodb.com>2020-01-16 20:01:39 +0000
committerA. Jesse Jiryu Davis <jesse@mongodb.com>2020-01-27 15:40:35 -0500
commit9cd4690536ef82a7a163943e727f94a7e9cb006c (patch)
tree568b36e85f327c7c0bcd83bbbe58d119c68a6ecc
parent775b2785128829327277ff0842914259c7eb7261 (diff)
downloadmongo-9cd4690536ef82a7a163943e727f94a7e9cb006c.tar.gz
Revert "SERVER-43721 Rename DistCache to ReadThroughCache"
This reverts commit 4ea0e5f400e2dc8a18c2cf407f13e7780d0c5d14.
-rw-r--r--src/mongo/db/auth/authorization_manager_impl.cpp16
-rw-r--r--src/mongo/db/auth/authorization_manager_impl.h14
-rw-r--r--src/mongo/db/auth/user.h6
-rw-r--r--src/mongo/db/read_write_concern_defaults.cpp2
-rw-r--r--src/mongo/db/read_write_concern_defaults.h5
-rw-r--r--src/mongo/util/SConscript2
-rw-r--r--src/mongo/util/dist_cache.cpp (renamed from src/mongo/util/read_through_cache.cpp)10
-rw-r--r--src/mongo/util/dist_cache.h (renamed from src/mongo/util/read_through_cache.h)37
-rw-r--r--src/mongo/util/dist_cache_test.cpp (renamed from src/mongo/util/read_through_cache_test.cpp)14
9 files changed, 53 insertions, 53 deletions
diff --git a/src/mongo/db/auth/authorization_manager_impl.cpp b/src/mongo/db/auth/authorization_manager_impl.cpp
index f996254981d..03ba2a98884 100644
--- a/src/mongo/db/auth/authorization_manager_impl.cpp
+++ b/src/mongo/db/auth/authorization_manager_impl.cpp
@@ -579,11 +579,11 @@ std::vector<AuthorizationManager::CachedUserInfo> AuthorizationManagerImpl::getU
return ret;
}
-AuthorizationManagerImpl::AuthSchemaVersionCache::AuthSchemaVersionCache(
+AuthorizationManagerImpl::AuthSchemaVersionDistCache::AuthSchemaVersionDistCache(
AuthzManagerExternalState* externalState)
- : ReadThroughCache(1, _mutex), _externalState(externalState) {}
+ : DistCache(1, _mutex), _externalState(externalState) {}
-boost::optional<int> AuthorizationManagerImpl::AuthSchemaVersionCache::lookup(
+boost::optional<int> AuthorizationManagerImpl::AuthSchemaVersionDistCache::lookup(
OperationContext* opCtx, const int& unusedKey) {
invariant(unusedKey == 0);
@@ -593,16 +593,16 @@ boost::optional<int> AuthorizationManagerImpl::AuthSchemaVersionCache::lookup(
return authzVersion;
}
-AuthorizationManagerImpl::UserCacheImpl::UserCacheImpl(
- AuthSchemaVersionCache* authSchemaVersionCache,
+AuthorizationManagerImpl::UserDistCacheImpl::UserDistCacheImpl(
+ AuthSchemaVersionDistCache* authSchemaVersionCache,
AuthzManagerExternalState* externalState,
int cacheSize)
- : UserCache(cacheSize, _mutex),
+ : UserDistCache(cacheSize, _mutex),
_authSchemaVersionCache(authSchemaVersionCache),
_externalState(externalState) {}
-boost::optional<User> AuthorizationManagerImpl::UserCacheImpl::lookup(OperationContext* opCtx,
- const UserName& userName) {
+boost::optional<User> AuthorizationManagerImpl::UserDistCacheImpl::lookup(
+ OperationContext* opCtx, const UserName& userName) {
LOG(1) << "Getting user " << userName << " from disk";
// Number of times to retry a user document that fetches due to transient AuthSchemaIncompatible
diff --git a/src/mongo/db/auth/authorization_manager_impl.h b/src/mongo/db/auth/authorization_manager_impl.h
index 81951ab3680..ecf7a9b1ace 100644
--- a/src/mongo/db/auth/authorization_manager_impl.h
+++ b/src/mongo/db/auth/authorization_manager_impl.h
@@ -160,9 +160,9 @@ private:
* Cache which contains at most a single entry (which has key 0), whose value is the version of
* the auth schema.
*/
- class AuthSchemaVersionCache : public ReadThroughCache<int, int> {
+ class AuthSchemaVersionDistCache : public DistCache<int, int> {
public:
- AuthSchemaVersionCache(AuthzManagerExternalState* externalState);
+ AuthSchemaVersionDistCache(AuthzManagerExternalState* externalState);
// 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
@@ -179,11 +179,11 @@ private:
/**
* Cache of the users known to the authentication subsystem.
*/
- class UserCacheImpl : public UserCache {
+ class UserDistCacheImpl : public UserDistCache {
public:
- UserCacheImpl(AuthSchemaVersionCache* authSchemaVersionCache,
- AuthzManagerExternalState* externalState,
- int cacheSize);
+ UserDistCacheImpl(AuthSchemaVersionDistCache* authSchemaVersionCache,
+ AuthzManagerExternalState* externalState,
+ int cacheSize);
// 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
@@ -193,7 +193,7 @@ private:
private:
Mutex _mutex = MONGO_MAKE_LATCH("AuthorizationManagerImpl::UserDistCacheImpl::_mutex");
- AuthSchemaVersionCache* const _authSchemaVersionCache;
+ AuthSchemaVersionDistCache* const _authSchemaVersionCache;
AuthzManagerExternalState* const _externalState;
} _userCache;
diff --git a/src/mongo/db/auth/user.h b/src/mongo/db/auth/user.h
index 97c9994d2e9..c5114d19694 100644
--- a/src/mongo/db/auth/user.h
+++ b/src/mongo/db/auth/user.h
@@ -42,7 +42,7 @@
#include "mongo/platform/atomic_word.h"
#include "mongo/stdx/unordered_map.h"
#include "mongo/stdx/unordered_set.h"
-#include "mongo/util/read_through_cache.h"
+#include "mongo/util/dist_cache.h"
namespace mongo {
@@ -254,7 +254,7 @@ private:
RestrictionDocuments _restrictions;
};
-using UserCache = ReadThroughCache<UserName, User>;
-using UserHandle = UserCache::ValueHandle;
+using UserDistCache = DistCache<UserName, User>;
+using UserHandle = UserDistCache::ValueHandle;
} // namespace mongo
diff --git a/src/mongo/db/read_write_concern_defaults.cpp b/src/mongo/db/read_write_concern_defaults.cpp
index a008c489e8b..91aed1bae92 100644
--- a/src/mongo/db/read_write_concern_defaults.cpp
+++ b/src/mongo/db/read_write_concern_defaults.cpp
@@ -234,7 +234,7 @@ ReadWriteConcernDefaults::ReadWriteConcernDefaults(FetchDefaultsFn fetchDefaults
ReadWriteConcernDefaults::~ReadWriteConcernDefaults() = default;
ReadWriteConcernDefaults::Cache::Cache(LookupFn lookupFn)
- : ReadThroughCache(1, _mutex), _lookupFn(lookupFn) {}
+ : DistCache(1, _mutex), _lookupFn(lookupFn) {}
boost::optional<RWConcernDefault> ReadWriteConcernDefaults::Cache::lookup(
OperationContext* opCtx, const ReadWriteConcernDefaults::Type& key) {
diff --git a/src/mongo/db/read_write_concern_defaults.h b/src/mongo/db/read_write_concern_defaults.h
index 1f10af61999..a711f29dc36 100644
--- a/src/mongo/db/read_write_concern_defaults.h
+++ b/src/mongo/db/read_write_concern_defaults.h
@@ -38,7 +38,7 @@
#include "mongo/db/write_concern_options.h"
#include "mongo/platform/mutex.h"
#include "mongo/util/concurrency/with_lock.h"
-#include "mongo/util/read_through_cache.h"
+#include "mongo/util/dist_cache.h"
namespace mongo {
@@ -135,7 +135,7 @@ private:
boost::optional<RWConcernDefault> _getDefault(OperationContext* opCtx);
- class Cache : public ReadThroughCache<Type, RWConcernDefault> {
+ class Cache : public DistCache<Type, RWConcernDefault> {
Cache(const Cache&) = delete;
Cache& operator=(const Cache&) = delete;
@@ -146,6 +146,7 @@ private:
boost::optional<RWConcernDefault> lookup(OperationContext* opCtx, const Type& key) override;
private:
+ // For exclusive use by DistCache only.
Mutex _mutex = MONGO_MAKE_LATCH("ReadWriteConcernDefaults::Cache");
LookupFn _lookupFn;
diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript
index 5161614eedb..234ebc8c9ef 100644
--- a/src/mongo/util/SConscript
+++ b/src/mongo/util/SConscript
@@ -205,7 +205,7 @@ env.Library(
env.Library(
target='caching',
source=[
- 'read_through_cache.cpp',
+ 'dist_cache.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
diff --git a/src/mongo/util/read_through_cache.cpp b/src/mongo/util/dist_cache.cpp
index a46f93c326f..b567992f14a 100644
--- a/src/mongo/util/read_through_cache.cpp
+++ b/src/mongo/util/dist_cache.cpp
@@ -29,20 +29,20 @@
#include "mongo/platform/basic.h"
-#include "mongo/util/read_through_cache.h"
+#include "mongo/util/dist_cache.h"
namespace mongo {
-ReadThroughCacheBase::ReadThroughCacheBase(Mutex& mutex) : _cacheWriteMutex(mutex) {}
+DistCacheBase::DistCacheBase(Mutex& mutex) : _cacheWriteMutex(mutex) {}
-ReadThroughCacheBase::~ReadThroughCacheBase() = default;
+DistCacheBase::~DistCacheBase() = default;
-OID ReadThroughCacheBase::getCacheGeneration() const {
+OID DistCacheBase::getCacheGeneration() const {
stdx::lock_guard<Latch> lk(_cacheWriteMutex);
return _fetchGeneration;
}
-void ReadThroughCacheBase::_updateCacheGeneration(const CacheGuard&) {
+void DistCacheBase::_updateCacheGeneration(const CacheGuard&) {
_fetchGeneration = OID::gen();
}
diff --git a/src/mongo/util/read_through_cache.h b/src/mongo/util/dist_cache.h
index 83790bd9605..74b52b308ae 100644
--- a/src/mongo/util/read_through_cache.h
+++ b/src/mongo/util/dist_cache.h
@@ -41,11 +41,11 @@ namespace mongo {
class OperationContext;
/**
- * Serves as a container of the non-templatised parts of the ReadThroughCache class below.
+ * Serves as a container of the non-templatised parts of the DistCache class below.
*/
-class ReadThroughCacheBase {
- ReadThroughCacheBase(const ReadThroughCacheBase&) = delete;
- ReadThroughCacheBase& operator=(const ReadThroughCacheBase&) = delete;
+class DistCacheBase {
+ DistCacheBase(const DistCacheBase&) = delete;
+ DistCacheBase& operator=(const DistCacheBase&) = delete;
public:
/**
@@ -54,14 +54,14 @@ public:
OID getCacheGeneration() const;
protected:
- ReadThroughCacheBase(Mutex& mutex);
+ DistCacheBase(Mutex& mutex);
- virtual ~ReadThroughCacheBase();
+ virtual ~DistCacheBase();
/**
* Type used to guard accesses and updates to the cache.
*
- * Guard object for synchronizing accesses to data cached in ReadThroughCache instances.
+ * Guard object for synchronizing accesses to data cached in DistCache instances.
* This guard allows one thread to access the cache at a time, and provides an exception-safe
* mechanism for a thread to release the cache mutex while performing network or disk operations
* while allowing other readers to proceed.
@@ -92,9 +92,9 @@ protected:
public:
/**
- * Constructs a cache guard, locking the mutex that synchronizes ReadThroughCache accesses.
+ * Constructs a cache guard, locking the mutex that synchronizes DistCache accesses.
*/
- explicit CacheGuard(ReadThroughCacheBase* distCache)
+ explicit CacheGuard(DistCacheBase* distCache)
: _distCache(distCache), _cacheLock(distCache->_cacheWriteMutex) {}
/**
@@ -168,7 +168,7 @@ protected:
}
private:
- ReadThroughCacheBase* const _distCache;
+ DistCacheBase* const _distCache;
stdx::unique_lock<Latch> _cacheLock;
@@ -176,7 +176,7 @@ protected:
OID _distCacheFetchGenerationAtFetchBegin;
};
- friend class ReadThroughCacheBase::CacheGuard;
+ friend class DistCacheBase::CacheGuard;
/**
* Updates _fetchGeneration to a new OID
@@ -213,7 +213,7 @@ protected:
* Implements a generic read-through cache built on top of InvalidatingLRUCache.
*/
template <typename Key, typename Value>
-class ReadThroughCache : public ReadThroughCacheBase {
+class DistCache : public DistCacheBase {
public:
using Cache = InvalidatingLRUCache<Key, Value>;
using ValueHandle = typename Cache::ValueHandle;
@@ -307,14 +307,13 @@ public:
protected:
/**
- * ReadThroughCache constructor, to be called by sub-classes. Accepts the initial size of the
- * cache, and a reference to a Mutex. The Mutex is for the exclusive use of the
- * ReadThroughCache, the sub-class should never actually use it (apart from passing it to this
- * constructor). Having the Mutex stored by the sub-class allows latch diagnostics to be
- * correctly associated with the sub-class (not the generic ReadThroughCache class).
+ * DistCache constructor, to be called by sub-classes. Accepts the initial size of the cache,
+ * and a reference to a Mutex. The Mutex is for the exclusive use of the DistCache, the
+ * sub-class should never actually use it (apart from passing it to this constructor). Having
+ * the Mutex stored by the sub-class allows latch diagnostics to be correctly associated with
+ * the sub-class (not the generic DistCache class).
*/
- ReadThroughCache(int cacheSize, Mutex& mutex)
- : ReadThroughCacheBase(mutex), _cache(cacheSize) {}
+ DistCache(int cacheSize, Mutex& mutex) : DistCacheBase(mutex), _cache(cacheSize) {}
private:
/**
diff --git a/src/mongo/util/read_through_cache_test.cpp b/src/mongo/util/dist_cache_test.cpp
index f7420a235be..f0bf4ef81fd 100644
--- a/src/mongo/util/read_through_cache_test.cpp
+++ b/src/mongo/util/dist_cache_test.cpp
@@ -33,7 +33,7 @@
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/unittest/unittest.h"
-#include "mongo/util/read_through_cache.h"
+#include "mongo/util/dist_cache.h"
namespace mongo {
namespace {
@@ -42,28 +42,28 @@ struct CachedValue {
const int counter;
};
-class Cache : public ReadThroughCache<std::string, CachedValue> {
+class Cache : public DistCache<std::string, CachedValue> {
public:
Cache(size_t size, LookupFn lookupFn)
- : ReadThroughCache(size, _mutex), _lookupFn(std::move(lookupFn)) {}
+ : DistCache(size, _mutex), _lookupFn(std::move(lookupFn)) {}
private:
boost::optional<CachedValue> lookup(OperationContext* opCtx, const std::string& key) override {
return _lookupFn(opCtx, key);
}
- Mutex _mutex = MONGO_MAKE_LATCH("ReadThroughCacheTest::Cache");
+ Mutex _mutex = MONGO_MAKE_LATCH("DistCacheTest::Cache");
LookupFn _lookupFn;
};
-class ReadThroughCacheTest : public ServiceContextTest {
+class DistCacheTest : public ServiceContextTest {
protected:
const ServiceContext::UniqueOperationContext _opCtxHolder{makeOperationContext()};
OperationContext* _opCtx{_opCtxHolder.get()};
};
-TEST_F(ReadThroughCacheTest, FetchInvalidateAndRefetch) {
+TEST_F(DistCacheTest, FetchInvalidateAndRefetch) {
int countLookups = 0;
Cache cache(1, [&](OperationContext*, const std::string& key) {
ASSERT_EQ("TestKey", key);
@@ -85,7 +85,7 @@ TEST_F(ReadThroughCacheTest, FetchInvalidateAndRefetch) {
}
}
-TEST_F(ReadThroughCacheTest, CacheSizeZero) {
+TEST_F(DistCacheTest, CacheSizeZero) {
int countLookups = 0;
Cache cache(0, [&](OperationContext*, const std::string& key) {
ASSERT_EQ("TestKey", key);