summaryrefslogtreecommitdiff
path: root/src/mongo/util/lru_cache.h
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2019-12-29 19:13:13 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-01-16 12:41:35 +0000
commit73b89c6fc4ed6279b52e2588c102c7fc1182189b (patch)
tree0da24518364ce1e7cc753d64b53419595085bf6e /src/mongo/util/lru_cache.h
parentd4a93cea2eee5d2823d7a4d0224db06b4cd15b50 (diff)
downloadmongo-73b89c6fc4ed6279b52e2588c102c7fc1182189b.tar.gz
SERVER-43721 Make the AuthorizationManager use DistCache
The DistCache (to be later renamed to ReadThroughCache) was derived from the same implementation under AuthorizationManager and this change removes the code duplication. In addition, it makes the following changes to InvalidatingLRUCache and the DistCache: * Simplifies and optimises the InvalidatingLRUCache: The way it is implemented now, it performs up to 3 operations per lookup, unvalidates entries unnecessarily and has overly complicated logic, which is source of a crash. Instead of fixing the bug, this change rewrites it in a simpler way, which introduces a ValueHandle instead of bare shared_ptr for the return value, and only performs additional work if entries fall off the underlying LRUCache. * Moves the DistCache under src/util and adds unit tests: This change pulls the DistCache (which is the main consumer of InvalidatingLRUCache) into its own library and moves it to be under src/util like the other caches and adds unit tests. delete mode 100644 jstests/auth/pinned_users.js create mode 100644 jstests/auth/pinned_users_clear_pinned_user_list.js create mode 100644 jstests/auth/pinned_users_exclusive_lock_on_admin.js create mode 100644 jstests/auth/pinned_users_remove_user_document_unpins_user.js create mode 100644 src/mongo/util/dist_cache.cpp rename src/mongo/{db => util}/dist_cache.h (56%) create mode 100644 src/mongo/util/dist_cache_test.cpp
Diffstat (limited to 'src/mongo/util/lru_cache.h')
-rw-r--r--src/mongo/util/lru_cache.h8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/mongo/util/lru_cache.h b/src/mongo/util/lru_cache.h
index bfe3ba19bf4..adb35affa7c 100644
--- a/src/mongo/util/lru_cache.h
+++ b/src/mongo/util/lru_cache.h
@@ -29,12 +29,11 @@
#pragma once
+#include <boost/optional.hpp>
#include <cstdlib>
#include <iterator>
#include <list>
-#include <boost/optional.hpp>
-
#include "mongo/stdx/unordered_map.h"
namespace mongo {
@@ -87,7 +86,7 @@ public:
* This method does not provide the strong exception safe guarantee. If a call
* to this method throws, the cache may be left in an inconsistent state.
*/
- boost::optional<V> add(const K& key, V entry) {
+ boost::optional<std::pair<K, V>> add(const K& key, V entry) {
// If the key already exists, delete it first.
auto i = this->_map.find(key);
if (i != this->_map.end()) {
@@ -101,13 +100,12 @@ public:
// evict the least recently used entry.
if (this->size() > this->_maxSize) {
auto pair = std::move(this->_list.back());
- auto result = std::move(pair.second);
this->_map.erase(pair.first);
this->_list.pop_back();
invariant(this->size() <= this->_maxSize);
- return std::move(result);
+ return std::move(pair);
}
invariant(this->size() <= this->_maxSize);