diff options
Diffstat (limited to 'src/mongo/db/query/query_settings.cpp')
-rw-r--r-- | src/mongo/db/query/query_settings.cpp | 215 |
1 files changed, 110 insertions, 105 deletions
diff --git a/src/mongo/db/query/query_settings.cpp b/src/mongo/db/query/query_settings.cpp index c6b2f34fcb8..487f34ebcf9 100644 --- a/src/mongo/db/query/query_settings.cpp +++ b/src/mongo/db/query/query_settings.cpp @@ -32,132 +32,137 @@ namespace mongo { - using std::vector; - - // - // HintOverride - // - - AllowedIndices::AllowedIndices(const std::vector<BSONObj>& indexKeyPatterns) { - for (std::vector<BSONObj>::const_iterator i = indexKeyPatterns.begin(); - i != indexKeyPatterns.end(); ++i) { - const BSONObj& indexKeyPattern = *i; - this->indexKeyPatterns.push_back(indexKeyPattern.getOwned()); - } +using std::vector; + +// +// HintOverride +// + +AllowedIndices::AllowedIndices(const std::vector<BSONObj>& indexKeyPatterns) { + for (std::vector<BSONObj>::const_iterator i = indexKeyPatterns.begin(); + i != indexKeyPatterns.end(); + ++i) { + const BSONObj& indexKeyPattern = *i; + this->indexKeyPatterns.push_back(indexKeyPattern.getOwned()); } - - AllowedIndices::~AllowedIndices() { } - - // - // AllowedIndexEntry - // - - AllowedIndexEntry::AllowedIndexEntry(const BSONObj& query, const BSONObj& sort, - const BSONObj& projection, - const std::vector<BSONObj>& indexKeyPatterns) - : query(query.getOwned()), - sort(sort.getOwned()), - projection(projection.getOwned()) { - for (std::vector<BSONObj>::const_iterator i = indexKeyPatterns.begin(); - i != indexKeyPatterns.end(); ++i) { - const BSONObj& indexKeyPattern = *i; - this->indexKeyPatterns.push_back(indexKeyPattern.getOwned()); - } - } - - AllowedIndexEntry::~AllowedIndexEntry() { } - - AllowedIndexEntry* AllowedIndexEntry::clone() const { - AllowedIndexEntry* entry = new AllowedIndexEntry(query, sort, projection, indexKeyPatterns); - return entry; +} + +AllowedIndices::~AllowedIndices() {} + +// +// AllowedIndexEntry +// + +AllowedIndexEntry::AllowedIndexEntry(const BSONObj& query, + const BSONObj& sort, + const BSONObj& projection, + const std::vector<BSONObj>& indexKeyPatterns) + : query(query.getOwned()), sort(sort.getOwned()), projection(projection.getOwned()) { + for (std::vector<BSONObj>::const_iterator i = indexKeyPatterns.begin(); + i != indexKeyPatterns.end(); + ++i) { + const BSONObj& indexKeyPattern = *i; + this->indexKeyPatterns.push_back(indexKeyPattern.getOwned()); } +} - // - // QuerySettings - // - - QuerySettings::QuerySettings() { } - - QuerySettings::~QuerySettings() { - _clear(); - } +AllowedIndexEntry::~AllowedIndexEntry() {} - bool QuerySettings::getAllowedIndices(const PlanCacheKey& key, - AllowedIndices** allowedIndicesOut) const { - invariant(allowedIndicesOut); +AllowedIndexEntry* AllowedIndexEntry::clone() const { + AllowedIndexEntry* entry = new AllowedIndexEntry(query, sort, projection, indexKeyPatterns); + return entry; +} - stdx::lock_guard<stdx::mutex> cacheLock(_mutex); - AllowedIndexEntryMap::const_iterator cacheIter = _allowedIndexEntryMap.find(key); +// +// QuerySettings +// - // Nothing to do if key does not exist in query settings. - if (cacheIter == _allowedIndexEntryMap.end()) { - *allowedIndicesOut = NULL; - return false; - } +QuerySettings::QuerySettings() {} - AllowedIndexEntry* entry = cacheIter->second; +QuerySettings::~QuerySettings() { + _clear(); +} - // Create a AllowedIndices from entry. - *allowedIndicesOut = new AllowedIndices(entry->indexKeyPatterns); +bool QuerySettings::getAllowedIndices(const PlanCacheKey& key, + AllowedIndices** allowedIndicesOut) const { + invariant(allowedIndicesOut); - return true; - } + stdx::lock_guard<stdx::mutex> cacheLock(_mutex); + AllowedIndexEntryMap::const_iterator cacheIter = _allowedIndexEntryMap.find(key); - std::vector<AllowedIndexEntry*> QuerySettings::getAllAllowedIndices() const { - stdx::lock_guard<stdx::mutex> cacheLock(_mutex); - vector<AllowedIndexEntry*> entries; - for (AllowedIndexEntryMap::const_iterator i = _allowedIndexEntryMap.begin(); i != _allowedIndexEntryMap.end(); ++i) { - AllowedIndexEntry* entry = i->second; - entries.push_back(entry->clone()); - } - return entries; + // Nothing to do if key does not exist in query settings. + if (cacheIter == _allowedIndexEntryMap.end()) { + *allowedIndicesOut = NULL; + return false; } - void QuerySettings::setAllowedIndices(const CanonicalQuery& canonicalQuery, - const PlanCacheKey& key, - const std::vector<BSONObj>& indexes) { - const LiteParsedQuery& lpq = canonicalQuery.getParsed(); - const BSONObj& query = lpq.getFilter(); - const BSONObj& sort = lpq.getSort(); - const BSONObj& projection = lpq.getProj(); - AllowedIndexEntry* entry = new AllowedIndexEntry(query, sort, projection, indexes); - - stdx::lock_guard<stdx::mutex> cacheLock(_mutex); - AllowedIndexEntryMap::iterator i = _allowedIndexEntryMap.find(key); - // Replace existing entry. - if (i != _allowedIndexEntryMap.end()) { - AllowedIndexEntry* entry = i->second; - delete entry; - } - _allowedIndexEntryMap[key] = entry; - } + AllowedIndexEntry* entry = cacheIter->second; - void QuerySettings::removeAllowedIndices(const PlanCacheKey& key) { - stdx::lock_guard<stdx::mutex> cacheLock(_mutex); - AllowedIndexEntryMap::iterator i = _allowedIndexEntryMap.find(key); + // Create a AllowedIndices from entry. + *allowedIndicesOut = new AllowedIndices(entry->indexKeyPatterns); - // Nothing to do if key does not exist in query settings. - if (i == _allowedIndexEntryMap.end()) { - return; - } + return true; +} - // Free up resources and delete entry. +std::vector<AllowedIndexEntry*> QuerySettings::getAllAllowedIndices() const { + stdx::lock_guard<stdx::mutex> cacheLock(_mutex); + vector<AllowedIndexEntry*> entries; + for (AllowedIndexEntryMap::const_iterator i = _allowedIndexEntryMap.begin(); + i != _allowedIndexEntryMap.end(); + ++i) { + AllowedIndexEntry* entry = i->second; + entries.push_back(entry->clone()); + } + return entries; +} + +void QuerySettings::setAllowedIndices(const CanonicalQuery& canonicalQuery, + const PlanCacheKey& key, + const std::vector<BSONObj>& indexes) { + const LiteParsedQuery& lpq = canonicalQuery.getParsed(); + const BSONObj& query = lpq.getFilter(); + const BSONObj& sort = lpq.getSort(); + const BSONObj& projection = lpq.getProj(); + AllowedIndexEntry* entry = new AllowedIndexEntry(query, sort, projection, indexes); + + stdx::lock_guard<stdx::mutex> cacheLock(_mutex); + AllowedIndexEntryMap::iterator i = _allowedIndexEntryMap.find(key); + // Replace existing entry. + if (i != _allowedIndexEntryMap.end()) { AllowedIndexEntry* entry = i->second; - _allowedIndexEntryMap.erase(i); delete entry; } + _allowedIndexEntryMap[key] = entry; +} - void QuerySettings::clearAllowedIndices() { - stdx::lock_guard<stdx::mutex> cacheLock(_mutex); - _clear(); +void QuerySettings::removeAllowedIndices(const PlanCacheKey& key) { + stdx::lock_guard<stdx::mutex> cacheLock(_mutex); + AllowedIndexEntryMap::iterator i = _allowedIndexEntryMap.find(key); + + // Nothing to do if key does not exist in query settings. + if (i == _allowedIndexEntryMap.end()) { + return; } - void QuerySettings::_clear() { - for (AllowedIndexEntryMap::const_iterator i = _allowedIndexEntryMap.begin(); i != _allowedIndexEntryMap.end(); ++i) { - AllowedIndexEntry* entry = i->second; - delete entry; - } - _allowedIndexEntryMap.clear(); + // Free up resources and delete entry. + AllowedIndexEntry* entry = i->second; + _allowedIndexEntryMap.erase(i); + delete entry; +} + +void QuerySettings::clearAllowedIndices() { + stdx::lock_guard<stdx::mutex> cacheLock(_mutex); + _clear(); +} + +void QuerySettings::_clear() { + for (AllowedIndexEntryMap::const_iterator i = _allowedIndexEntryMap.begin(); + i != _allowedIndexEntryMap.end(); + ++i) { + AllowedIndexEntry* entry = i->second; + delete entry; } + _allowedIndexEntryMap.clear(); +} } // namespace mongo |