diff options
author | David Hatch <david.hatch@mongodb.com> | 2016-07-22 15:03:05 -0400 |
---|---|---|
committer | David Hatch <david.hatch@mongodb.com> | 2016-08-02 17:36:40 -0400 |
commit | a6ed9e2e39e7860d04a7249dc7f68a085903b6bd (patch) | |
tree | d8b430d135cfcb8a28f22b6c0b3de6d997bf3ab8 /src/mongo/db/query/query_settings.h | |
parent | 5f9ba2374bd1ec479b150518456b5c786c313845 (diff) | |
download | mongo-a6ed9e2e39e7860d04a7249dc7f68a085903b6bd.tar.gz |
SERVER-24239 Refactor QuerySettings to use values instead of unowned pointer.
Diffstat (limited to 'src/mongo/db/query/query_settings.h')
-rw-r--r-- | src/mongo/db/query/query_settings.h | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/src/mongo/db/query/query_settings.h b/src/mongo/db/query/query_settings.h index dbf3f1a19bc..6017f307fab 100644 --- a/src/mongo/db/query/query_settings.h +++ b/src/mongo/db/query/query_settings.h @@ -28,8 +28,8 @@ #pragma once +#include <boost/optional.hpp> #include <string> -#include <vector> #include "mongo/base/disallow_copying.h" #include "mongo/bson/bsonobj.h" @@ -50,7 +50,9 @@ private: public: AllowedIndices(const std::vector<BSONObj>& indexKeyPatterns); - ~AllowedIndices(); + AllowedIndices(AllowedIndices&& other) = default; + + AllowedIndices& operator=(AllowedIndices&& other) = default; // These are the index key patterns that // we will use to override the indexes retrieved from @@ -65,17 +67,12 @@ public: * vector of index specs */ class AllowedIndexEntry { -private: - MONGO_DISALLOW_COPYING(AllowedIndexEntry); - public: AllowedIndexEntry(const BSONObj& query, const BSONObj& sort, const BSONObj& projection, const BSONObj& collation, const std::vector<BSONObj>& indexKeyPatterns); - ~AllowedIndexEntry(); - AllowedIndexEntry* clone() const; // query, sort, projection, and collation collectively represent the query shape that we are // storing hint overrides for. @@ -98,28 +95,21 @@ private: MONGO_DISALLOW_COPYING(QuerySettings); public: - QuerySettings(); - - ~QuerySettings(); + QuerySettings() = default; /** - * Returns true and fills out allowedIndicesOut if a hint is set in the query settings - * for the query. - * Returns false and sets allowedIndicesOut to NULL otherwise. - * Caller owns AllowedIndices. + * Returns AllowedIndices for the query if it is set in the query settings, or boost::none. */ - bool getAllowedIndices(const PlanCacheKey& query, AllowedIndices** allowedIndicesOut) const; + boost::optional<AllowedIndices> getAllowedIndices(const PlanCacheKey& query) const; /** - * Returns copies all overrides for the collection.. - * Caller owns overrides in vector. + * Returns copies of all overrides for the collection. */ - std::vector<AllowedIndexEntry*> getAllAllowedIndices() const; + std::vector<AllowedIndexEntry> getAllAllowedIndices() const; /** * Adds or replaces entry in query settings. - * If existing entry is found for the same key, - * frees resources for existing entry before replacing. + * If existing entry is found for the same key, replaces it. */ void setAllowedIndices(const CanonicalQuery& canonicalQuery, const PlanCacheKey& key, @@ -136,12 +126,8 @@ public: void clearAllowedIndices(); private: - /** - * Clears entries without acquiring mutex. - */ - void _clear(); - - typedef unordered_map<PlanCacheKey, AllowedIndexEntry*> AllowedIndexEntryMap; + // Allowed index entries owned here. + using AllowedIndexEntryMap = unordered_map<PlanCacheKey, AllowedIndexEntry>; AllowedIndexEntryMap _allowedIndexEntryMap; /** |