diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2019-12-29 19:13:13 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-01-16 12:41:35 +0000 |
commit | 73b89c6fc4ed6279b52e2588c102c7fc1182189b (patch) | |
tree | 0da24518364ce1e7cc753d64b53419595085bf6e /src/mongo/db/read_write_concern_defaults.h | |
parent | d4a93cea2eee5d2823d7a4d0224db06b4cd15b50 (diff) | |
download | mongo-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/db/read_write_concern_defaults.h')
-rw-r--r-- | src/mongo/db/read_write_concern_defaults.h | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/mongo/db/read_write_concern_defaults.h b/src/mongo/db/read_write_concern_defaults.h index 7c0b3f520d7..a711f29dc36 100644 --- a/src/mongo/db/read_write_concern_defaults.h +++ b/src/mongo/db/read_write_concern_defaults.h @@ -31,7 +31,6 @@ #include <map> -#include "mongo/db/dist_cache.h" #include "mongo/db/operation_context.h" #include "mongo/db/repl/read_concern_args.h" #include "mongo/db/rw_concern_default_gen.h" @@ -39,6 +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" namespace mongo { @@ -53,7 +53,7 @@ public: using ReadConcern = repl::ReadConcernArgs; using WriteConcern = WriteConcernOptions; - using LookupFn = std::function<boost::optional<RWConcernDefault>(OperationContext*)>; + using FetchDefaultsFn = std::function<boost::optional<RWConcernDefault>(OperationContext*)>; static constexpr StringData readConcernFieldName = ReadConcern::kReadConcernFieldName; static constexpr StringData writeConcernFieldName = WriteConcern::kWriteConcernField; @@ -62,13 +62,20 @@ public: static constexpr StringData kPersistedDocumentId = "ReadWriteConcernDefaults"_sd; static ReadWriteConcernDefaults& get(ServiceContext* service); - static ReadWriteConcernDefaults& get(ServiceContext& service); static ReadWriteConcernDefaults& get(OperationContext* opCtx); - static void create(ServiceContext* service, LookupFn lookupFn); + static void create(ServiceContext* service, FetchDefaultsFn fetchDefaultsFn); - ReadWriteConcernDefaults() = delete; - ReadWriteConcernDefaults(LookupFn lookupFn); - ~ReadWriteConcernDefaults() = default; + ReadWriteConcernDefaults(FetchDefaultsFn fetchDefaultsFn); + ~ReadWriteConcernDefaults(); + + /** + * Syntactic sugar around 'getDefault' below. A return value of boost::none means that there is + * no default specified for that particular concern. + */ + boost::optional<ReadConcern> getDefaultReadConcern(OperationContext* opCtx); + boost::optional<WriteConcern> getDefaultWriteConcern(OperationContext* opCtx); + + RWConcernDefault getDefault(OperationContext* opCtx); /** * Returns true if the RC level is permissible to use as a default, and false if it cannot be a @@ -118,10 +125,6 @@ public: */ void refreshIfNecessary(OperationContext* opCtx); - RWConcernDefault getDefault(OperationContext* opCtx); - boost::optional<ReadConcern> getDefaultReadConcern(OperationContext* opCtx); - boost::optional<WriteConcern> getDefaultWriteConcern(OperationContext* opCtx); - /** * Sets the given read write concern as the defaults in the cache. */ |