summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2020-01-17 03:28:08 -0500
committerA. Jesse Jiryu Davis <jesse@mongodb.com>2020-01-27 15:40:40 -0500
commit735088a67a060303698e4b8a0d1d831549104f0c (patch)
tree311e71027ae91e6dbfdeecd83d136e7ecb326f88
parentd346a2beb3aaa9338dd351f3b085431b21a9e93f (diff)
downloadmongo-735088a67a060303698e4b8a0d1d831549104f0c.tar.gz
SERVER-43721 Rename DistCache to ReadThroughCache
rename src/mongo/util/{dist_cache.cpp => read_through_cache.cpp} (84%) rename src/mongo/util/{dist_cache.h => read_through_cache.h} (90%) rename src/mongo/util/{dist_cache_test.cpp => read_through_cache_test.cpp} (88%)
-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/SConscript4
-rw-r--r--src/mongo/util/read_through_cache.cpp (renamed from src/mongo/util/dist_cache.cpp)10
-rw-r--r--src/mongo/util/read_through_cache.h (renamed from src/mongo/util/dist_cache.h)37
-rw-r--r--src/mongo/util/read_through_cache_test.cpp (renamed from src/mongo/util/dist_cache_test.cpp)14
9 files changed, 54 insertions, 54 deletions
diff --git a/src/mongo/db/auth/authorization_manager_impl.cpp b/src/mongo/db/auth/authorization_manager_impl.cpp
index 03ba2a98884..f996254981d 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::AuthSchemaVersionDistCache::AuthSchemaVersionDistCache(
+AuthorizationManagerImpl::AuthSchemaVersionCache::AuthSchemaVersionCache(
AuthzManagerExternalState* externalState)
- : DistCache(1, _mutex), _externalState(externalState) {}
+ : ReadThroughCache(1, _mutex), _externalState(externalState) {}
-boost::optional<int> AuthorizationManagerImpl::AuthSchemaVersionDistCache::lookup(
+boost::optional<int> AuthorizationManagerImpl::AuthSchemaVersionCache::lookup(
OperationContext* opCtx, const int& unusedKey) {
invariant(unusedKey == 0);
@@ -593,16 +593,16 @@ boost::optional<int> AuthorizationManagerImpl::AuthSchemaVersionDistCache::looku
return authzVersion;
}
-AuthorizationManagerImpl::UserDistCacheImpl::UserDistCacheImpl(
- AuthSchemaVersionDistCache* authSchemaVersionCache,
+AuthorizationManagerImpl::UserCacheImpl::UserCacheImpl(
+ AuthSchemaVersionCache* authSchemaVersionCache,
AuthzManagerExternalState* externalState,
int cacheSize)
- : UserDistCache(cacheSize, _mutex),
+ : UserCache(cacheSize, _mutex),
_authSchemaVersionCache(authSchemaVersionCache),
_externalState(externalState) {}
-boost::optional<User> AuthorizationManagerImpl::UserDistCacheImpl::lookup(
- OperationContext* opCtx, const UserName& userName) {
+boost::optional<User> AuthorizationManagerImpl::UserCacheImpl::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 ecf7a9b1ace..81951ab3680 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 AuthSchemaVersionDistCache : public DistCache<int, int> {
+ class AuthSchemaVersionCache : public ReadThroughCache<int, int> {
public:
- AuthSchemaVersionDistCache(AuthzManagerExternalState* externalState);
+ AuthSchemaVersionCache(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 UserDistCacheImpl : public UserDistCache {
+ class UserCacheImpl : public UserCache {
public:
- UserDistCacheImpl(AuthSchemaVersionDistCache* authSchemaVersionCache,
- AuthzManagerExternalState* externalState,
- int cacheSize);
+ UserCacheImpl(AuthSchemaVersionCache* 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");
- AuthSchemaVersionDistCache* const _authSchemaVersionCache;
+ AuthSchemaVersionCache* const _authSchemaVersionCache;
AuthzManagerExternalState* const _externalState;
} _userCache;
diff --git a/src/mongo/db/auth/user.h b/src/mongo/db/auth/user.h
index c5114d19694..97c9994d2e9 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/dist_cache.h"
+#include "mongo/util/read_through_cache.h"
namespace mongo {
@@ -254,7 +254,7 @@ private:
RestrictionDocuments _restrictions;
};
-using UserDistCache = DistCache<UserName, User>;
-using UserHandle = UserDistCache::ValueHandle;
+using UserCache = ReadThroughCache<UserName, User>;
+using UserHandle = UserCache::ValueHandle;
} // namespace mongo
diff --git a/src/mongo/db/read_write_concern_defaults.cpp b/src/mongo/db/read_write_concern_defaults.cpp
index 91aed1bae92..a008c489e8b 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)
- : DistCache(1, _mutex), _lookupFn(lookupFn) {}
+ : ReadThroughCache(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 a711f29dc36..1f10af61999 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/dist_cache.h"
+#include "mongo/util/read_through_cache.h"
namespace mongo {
@@ -135,7 +135,7 @@ private:
boost::optional<RWConcernDefault> _getDefault(OperationContext* opCtx);
- class Cache : public DistCache<Type, RWConcernDefault> {
+ class Cache : public ReadThroughCache<Type, RWConcernDefault> {
Cache(const Cache&) = delete;
Cache& operator=(const Cache&) = delete;
@@ -146,7 +146,6 @@ 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 234ebc8c9ef..f38194523f6 100644
--- a/src/mongo/util/SConscript
+++ b/src/mongo/util/SConscript
@@ -205,7 +205,7 @@ env.Library(
env.Library(
target='caching',
source=[
- 'dist_cache.cpp',
+ 'read_through_cache.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
@@ -566,7 +566,6 @@ icuEnv.CppUnitTest(
'decimal_counter_test.cpp',
'decorable_test.cpp',
'diagnostic_info_test.cpp',
- 'dist_cache_test.cpp',
'dns_name_test.cpp',
'dns_query_test.cpp',
'duration_test.cpp',
@@ -595,6 +594,7 @@ icuEnv.CppUnitTest(
'procparser_test.cpp' if env.TargetOSIs('linux') else [],
'producer_consumer_queue_test.cpp',
'progress_meter_test.cpp',
+ 'read_through_cache_test.cpp',
'registry_list_test.cpp',
'represent_as_test.cpp',
'safe_num_test.cpp',
diff --git a/src/mongo/util/dist_cache.cpp b/src/mongo/util/read_through_cache.cpp
index b567992f14a..a46f93c326f 100644
--- a/src/mongo/util/dist_cache.cpp
+++ b/src/mongo/util/read_through_cache.cpp
@@ -29,20 +29,20 @@
#include "mongo/platform/basic.h"
-#include "mongo/util/dist_cache.h"
+#include "mongo/util/read_through_cache.h"
namespace mongo {
-DistCacheBase::DistCacheBase(Mutex& mutex) : _cacheWriteMutex(mutex) {}
+ReadThroughCacheBase::ReadThroughCacheBase(Mutex& mutex) : _cacheWriteMutex(mutex) {}
-DistCacheBase::~DistCacheBase() = default;
+ReadThroughCacheBase::~ReadThroughCacheBase() = default;
-OID DistCacheBase::getCacheGeneration() const {
+OID ReadThroughCacheBase::getCacheGeneration() const {
stdx::lock_guard<Latch> lk(_cacheWriteMutex);
return _fetchGeneration;
}
-void DistCacheBase::_updateCacheGeneration(const CacheGuard&) {
+void ReadThroughCacheBase::_updateCacheGeneration(const CacheGuard&) {
_fetchGeneration = OID::gen();
}
diff --git a/src/mongo/util/dist_cache.h b/src/mongo/util/read_through_cache.h
index 74b52b308ae..83790bd9605 100644
--- a/src/mongo/util/dist_cache.h
+++ b/src/mongo/util/read_through_cache.h
@@ -41,11 +41,11 @@ namespace mongo {
class OperationContext;
/**
- * Serves as a container of the non-templatised parts of the DistCache class below.
+ * Serves as a container of the non-templatised parts of the ReadThroughCache class below.
*/
-class DistCacheBase {
- DistCacheBase(const DistCacheBase&) = delete;
- DistCacheBase& operator=(const DistCacheBase&) = delete;
+class ReadThroughCacheBase {
+ ReadThroughCacheBase(const ReadThroughCacheBase&) = delete;
+ ReadThroughCacheBase& operator=(const ReadThroughCacheBase&) = delete;
public:
/**
@@ -54,14 +54,14 @@ public:
OID getCacheGeneration() const;
protected:
- DistCacheBase(Mutex& mutex);
+ ReadThroughCacheBase(Mutex& mutex);
- virtual ~DistCacheBase();
+ virtual ~ReadThroughCacheBase();
/**
* Type used to guard accesses and updates to the cache.
*
- * Guard object for synchronizing accesses to data cached in DistCache instances.
+ * Guard object for synchronizing accesses to data cached in ReadThroughCache 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 DistCache accesses.
+ * Constructs a cache guard, locking the mutex that synchronizes ReadThroughCache accesses.
*/
- explicit CacheGuard(DistCacheBase* distCache)
+ explicit CacheGuard(ReadThroughCacheBase* distCache)
: _distCache(distCache), _cacheLock(distCache->_cacheWriteMutex) {}
/**
@@ -168,7 +168,7 @@ protected:
}
private:
- DistCacheBase* const _distCache;
+ ReadThroughCacheBase* const _distCache;
stdx::unique_lock<Latch> _cacheLock;
@@ -176,7 +176,7 @@ protected:
OID _distCacheFetchGenerationAtFetchBegin;
};
- friend class DistCacheBase::CacheGuard;
+ friend class ReadThroughCacheBase::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 DistCache : public DistCacheBase {
+class ReadThroughCache : public ReadThroughCacheBase {
public:
using Cache = InvalidatingLRUCache<Key, Value>;
using ValueHandle = typename Cache::ValueHandle;
@@ -307,13 +307,14 @@ public:
protected:
/**
- * 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 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(int cacheSize, Mutex& mutex) : DistCacheBase(mutex), _cache(cacheSize) {}
+ ReadThroughCache(int cacheSize, Mutex& mutex)
+ : ReadThroughCacheBase(mutex), _cache(cacheSize) {}
private:
/**
diff --git a/src/mongo/util/dist_cache_test.cpp b/src/mongo/util/read_through_cache_test.cpp
index f0bf4ef81fd..f7420a235be 100644
--- a/src/mongo/util/dist_cache_test.cpp
+++ b/src/mongo/util/read_through_cache_test.cpp
@@ -33,7 +33,7 @@
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/unittest/unittest.h"
-#include "mongo/util/dist_cache.h"
+#include "mongo/util/read_through_cache.h"
namespace mongo {
namespace {
@@ -42,28 +42,28 @@ struct CachedValue {
const int counter;
};
-class Cache : public DistCache<std::string, CachedValue> {
+class Cache : public ReadThroughCache<std::string, CachedValue> {
public:
Cache(size_t size, LookupFn lookupFn)
- : DistCache(size, _mutex), _lookupFn(std::move(lookupFn)) {}
+ : ReadThroughCache(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("DistCacheTest::Cache");
+ Mutex _mutex = MONGO_MAKE_LATCH("ReadThroughCacheTest::Cache");
LookupFn _lookupFn;
};
-class DistCacheTest : public ServiceContextTest {
+class ReadThroughCacheTest : public ServiceContextTest {
protected:
const ServiceContext::UniqueOperationContext _opCtxHolder{makeOperationContext()};
OperationContext* _opCtx{_opCtxHolder.get()};
};
-TEST_F(DistCacheTest, FetchInvalidateAndRefetch) {
+TEST_F(ReadThroughCacheTest, FetchInvalidateAndRefetch) {
int countLookups = 0;
Cache cache(1, [&](OperationContext*, const std::string& key) {
ASSERT_EQ("TestKey", key);
@@ -85,7 +85,7 @@ TEST_F(DistCacheTest, FetchInvalidateAndRefetch) {
}
}
-TEST_F(DistCacheTest, CacheSizeZero) {
+TEST_F(ReadThroughCacheTest, CacheSizeZero) {
int countLookups = 0;
Cache cache(0, [&](OperationContext*, const std::string& key) {
ASSERT_EQ("TestKey", key);