summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2018-11-17 06:35:04 -0500
committerBenety Goh <benety@mongodb.com>2018-11-17 06:35:04 -0500
commit5f077776ba56885494fd1baa343c1bab43095d0a (patch)
treeebd3c3497aa93fe0f5a65a2083b743188c4d75f3 /src/mongo/db/catalog
parente8bb6820e6b5b897478be86d806c968b20b30041 (diff)
downloadmongo-5f077776ba56885494fd1baa343c1bab43095d0a.tar.gz
SERVER-38166 unshim CollectionInfoCache
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r--src/mongo/db/catalog/SConscript12
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp7
-rw-r--r--src/mongo/db/catalog/collection_impl.h6
-rw-r--r--src/mongo/db/catalog/collection_info_cache.cpp43
-rw-r--r--src/mongo/db/catalog/collection_info_cache.h107
-rw-r--r--src/mongo/db/catalog/collection_info_cache_impl.cpp7
-rw-r--r--src/mongo/db/catalog/collection_info_cache_impl.h3
7 files changed, 20 insertions, 165 deletions
diff --git a/src/mongo/db/catalog/SConscript b/src/mongo/db/catalog/SConscript
index 2060764be5a..7195387ad6c 100644
--- a/src/mongo/db/catalog/SConscript
+++ b/src/mongo/db/catalog/SConscript
@@ -206,23 +206,12 @@ env.Library(
)
env.Library(
- target='collection_info_cache',
- source=[
- 'collection_info_cache.cpp',
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/base',
- ],
-)
-
-env.Library(
target='multi_index_block',
source=[
'multi_index_block_impl.cpp',
],
LIBDEPS=[
'collection',
- 'collection_info_cache',
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/audit',
'$BUILD_DIR/mongo/db/background',
@@ -315,7 +304,6 @@ env.Library(
],
LIBDEPS=[
'collection',
- 'collection_info_cache',
'collection_options',
'database',
'database_holder',
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index 992707c4f73..2cc3f2ee975 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -44,6 +44,7 @@
#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/background.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
+#include "mongo/db/catalog/collection_info_cache_impl.h"
#include "mongo/db/catalog/collection_options.h"
#include "mongo/db/catalog/database_catalog_entry.h"
#include "mongo/db/catalog/document_validation.h"
@@ -187,7 +188,7 @@ CollectionImpl::CollectionImpl(Collection* _this_init,
_recordStore(recordStore),
_dbce(dbce),
_needCappedLock(supportsDocLocking() && _recordStore->isCapped() && _ns.db() != "local"),
- _infoCache(_this_init, _ns),
+ _infoCache(std::make_unique<CollectionInfoCacheImpl>(_this_init, _ns)),
_indexCatalog(std::make_unique<IndexCatalogImpl>(_this_init,
getCatalogEntry()->getMaxAllowedIndexes())),
_collator(parseCollation(opCtx, _ns, _details->getCollectionOptions(opCtx).collation)),
@@ -209,7 +210,7 @@ void CollectionImpl::init(OperationContext* opCtx) {
if (isCapped())
_recordStore->setCappedCallback(this);
- _infoCache.init(opCtx);
+ _infoCache->init(opCtx);
}
CollectionImpl::~CollectionImpl() {
@@ -1323,7 +1324,7 @@ std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> CollectionImpl::makePlanExe
void CollectionImpl::setNs(NamespaceString nss) {
_ns = std::move(nss);
_indexCatalog->setNs(_ns);
- _infoCache.setNs(_ns);
+ _infoCache->setNs(_ns);
_recordStore->setNs(_ns);
// Until the query layer is prepared for cursors to survive renames, all cursors are killed when
diff --git a/src/mongo/db/catalog/collection_impl.h b/src/mongo/db/catalog/collection_impl.h
index e33f77d91c9..9005a2c263a 100644
--- a/src/mongo/db/catalog/collection_impl.h
+++ b/src/mongo/db/catalog/collection_impl.h
@@ -69,11 +69,11 @@ public:
}
CollectionInfoCache* infoCache() final {
- return &_infoCache;
+ return _infoCache.get();
}
const CollectionInfoCache* infoCache() const final {
- return &_infoCache;
+ return _infoCache.get();
}
const NamespaceString& ns() const final {
@@ -403,7 +403,7 @@ private:
RecordStore* const _recordStore;
DatabaseCatalogEntry* const _dbce;
const bool _needCappedLock;
- CollectionInfoCache _infoCache;
+ std::unique_ptr<CollectionInfoCache> _infoCache;
std::unique_ptr<IndexCatalog> _indexCatalog;
diff --git a/src/mongo/db/catalog/collection_info_cache.cpp b/src/mongo/db/catalog/collection_info_cache.cpp
deleted file mode 100644
index de692a5b646..00000000000
--- a/src/mongo/db/catalog/collection_info_cache.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/catalog/collection_info_cache.h"
-
-namespace mongo {
-CollectionInfoCache::Impl::~Impl() = default;
-
-MONGO_DEFINE_SHIM(CollectionInfoCache::makeImpl);
-
-void CollectionInfoCache::TUHook::hook() noexcept {}
-} // namespace mongo
diff --git a/src/mongo/db/catalog/collection_info_cache.h b/src/mongo/db/catalog/collection_info_cache.h
index 2426b16490d..6da36f5c9aa 100644
--- a/src/mongo/db/catalog/collection_info_cache.h
+++ b/src/mongo/db/catalog/collection_info_cache.h
@@ -30,12 +30,10 @@
#pragma once
-#include "mongo/base/shim.h"
#include "mongo/db/collection_index_usage_tracker.h"
#include "mongo/db/query/plan_cache.h"
#include "mongo/db/query/query_settings.h"
#include "mongo/db/update_index_data.h"
-#include "mongo/stdx/functional.h"
namespace mongo {
class Collection;
@@ -48,71 +46,27 @@ class OperationContext;
*/
class CollectionInfoCache {
public:
- class Impl {
- public:
- virtual ~Impl() = 0;
-
- virtual PlanCache* getPlanCache() const = 0;
-
- virtual QuerySettings* getQuerySettings() const = 0;
-
- virtual const UpdateIndexData& getIndexKeys(OperationContext* opCtx) const = 0;
-
- virtual CollectionIndexUsageMap getIndexUsageStats() const = 0;
-
- virtual void init(OperationContext* opCtx) = 0;
-
- virtual void addedIndex(OperationContext* opCtx, const IndexDescriptor* desc) = 0;
-
- virtual void droppedIndex(OperationContext* opCtx, StringData indexName) = 0;
-
- virtual void clearQueryCache() = 0;
-
- virtual void notifyOfQuery(OperationContext* opCtx,
- const std::set<std::string>& indexesUsed) = 0;
-
- virtual void setNs(NamespaceString ns) = 0;
- };
-
-
-public:
- static MONGO_DECLARE_SHIM((Collection * collection,
- const NamespaceString& ns,
- PrivateTo<CollectionInfoCache>)
- ->std::unique_ptr<Impl>) makeImpl;
-
- explicit inline CollectionInfoCache(Collection* const collection, const NamespaceString& ns)
- : _pimpl(makeImpl(collection, ns, PrivateCall<CollectionInfoCache>{})) {}
-
- inline ~CollectionInfoCache() = default;
+ virtual ~CollectionInfoCache() = default;
/**
* Builds internal cache state based on the current state of the Collection's IndexCatalog.
*/
- inline void init(OperationContext* const opCtx) {
- return this->_impl().init(opCtx);
- }
+ virtual void init(OperationContext* const opCtx) = 0;
/**
* Get the PlanCache for this collection.
*/
- inline PlanCache* getPlanCache() const {
- return this->_impl().getPlanCache();
- }
+ virtual PlanCache* getPlanCache() const = 0;
/**
* Get the QuerySettings for this collection.
*/
- inline QuerySettings* getQuerySettings() const {
- return this->_impl().getQuerySettings();
- }
+ virtual QuerySettings* getQuerySettings() const = 0;
/* get set of index keys for this namespace. handy to quickly check if a given
field is indexed (Note it might be a secondary component of a compound index.)
*/
- inline const UpdateIndexData& getIndexKeys(OperationContext* const opCtx) const {
- return this->_impl().getIndexKeys(opCtx);
- }
+ virtual const UpdateIndexData& getIndexKeys(OperationContext* const opCtx) const = 0;
/**
* Returns cached index usage statistics for this collection. The map returned will contain
@@ -121,9 +75,7 @@ public:
*
* Note for performance that this method returns a copy of a StringMap.
*/
- inline CollectionIndexUsageMap getIndexUsageStats() const {
- return this->_impl().getIndexUsageStats();
- }
+ virtual CollectionIndexUsageMap getIndexUsageStats() const = 0;
/**
* Register a newly-created index with the cache. Must be called whenever an index is
@@ -131,9 +83,7 @@ public:
*
* Must be called under exclusive collection lock.
*/
- inline void addedIndex(OperationContext* const opCtx, const IndexDescriptor* const desc) {
- return this->_impl().addedIndex(opCtx, desc);
- }
+ virtual void addedIndex(OperationContext* const opCtx, const IndexDescriptor* const desc) = 0;
/**
* Deregister a newly-dropped index with the cache. Must be called whenever an index is
@@ -141,53 +91,20 @@ public:
*
* Must be called under exclusive collection lock.
*/
- inline void droppedIndex(OperationContext* const opCtx, const StringData indexName) {
- return this->_impl().droppedIndex(opCtx, indexName);
- }
+ virtual void droppedIndex(OperationContext* const opCtx, const StringData indexName) = 0;
/**
* Removes all cached query plans.
*/
- inline void clearQueryCache() {
- return this->_impl().clearQueryCache();
- }
+ virtual void clearQueryCache() = 0;
/**
* Signal to the cache that a query operation has completed. 'indexesUsed' should list the
* set of indexes used by the winning plan, if any.
*/
- inline void notifyOfQuery(OperationContext* const opCtx,
- const std::set<std::string>& indexesUsed) {
- return this->_impl().notifyOfQuery(opCtx, indexesUsed);
- }
-
- inline void setNs(NamespaceString ns) {
- this->_impl().setNs(std::move(ns));
- }
-
- std::unique_ptr<Impl> _pimpl;
-
- // This structure exists to give us a customization point to decide how to force users of this
- // class to depend upon the corresponding `collection_info_cache.cpp` Translation Unit (TU).
- // All public forwarding functions call `_impl(), and `_impl` creates an instance of this
- // structure.
- struct TUHook {
- static void hook() noexcept;
-
- explicit inline TUHook() noexcept {
- if (kDebugBuild)
- this->hook();
- }
- };
-
- inline const Impl& _impl() const {
- TUHook{};
- return *this->_pimpl;
- }
+ virtual void notifyOfQuery(OperationContext* const opCtx,
+ const std::set<std::string>& indexesUsed) = 0;
- inline Impl& _impl() {
- TUHook{};
- return *this->_pimpl;
- }
+ virtual void setNs(NamespaceString ns) = 0;
};
} // namespace mongo
diff --git a/src/mongo/db/catalog/collection_info_cache_impl.cpp b/src/mongo/db/catalog/collection_info_cache_impl.cpp
index 55a1d838642..0b02a29896d 100644
--- a/src/mongo/db/catalog/collection_info_cache_impl.cpp
+++ b/src/mongo/db/catalog/collection_info_cache_impl.cpp
@@ -34,7 +34,6 @@
#include "mongo/db/catalog/collection_info_cache_impl.h"
-#include "mongo/base/init.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/concurrency/d_concurrency.h"
@@ -49,15 +48,9 @@
#include "mongo/db/ttl_collection_cache.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/clock_source.h"
-#include "mongo/util/debug_util.h"
#include "mongo/util/log.h"
namespace mongo {
-MONGO_REGISTER_SHIM(CollectionInfoCache::makeImpl)
-(Collection* const collection, const NamespaceString& ns, PrivateTo<CollectionInfoCache>)
- ->std::unique_ptr<CollectionInfoCache::Impl> {
- return std::make_unique<CollectionInfoCacheImpl>(collection, ns);
-}
CollectionInfoCacheImpl::CollectionInfoCacheImpl(Collection* collection, const NamespaceString& ns)
: _collection(collection),
diff --git a/src/mongo/db/catalog/collection_info_cache_impl.h b/src/mongo/db/catalog/collection_info_cache_impl.h
index 6900ba9c091..8b446564c75 100644
--- a/src/mongo/db/catalog/collection_info_cache_impl.h
+++ b/src/mongo/db/catalog/collection_info_cache_impl.h
@@ -32,7 +32,6 @@
#include "mongo/db/catalog/collection_info_cache.h"
-#include "mongo/base/shim.h"
#include "mongo/db/collection_index_usage_tracker.h"
#include "mongo/db/query/plan_cache.h"
#include "mongo/db/query/query_settings.h"
@@ -48,7 +47,7 @@ class OperationContext;
* this is for storing things that you want to cache about a single collection
* life cycle is managed for you from inside Collection
*/
-class CollectionInfoCacheImpl : public CollectionInfoCache::Impl {
+class CollectionInfoCacheImpl : public CollectionInfoCache {
public:
explicit CollectionInfoCacheImpl(Collection* collection, const NamespaceString& ns);