diff options
author | David Storch <david.storch@10gen.com> | 2018-11-08 16:23:40 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2018-11-27 13:33:54 -0500 |
commit | a0f64a185b60422fe15b67a406c7b8e04c191937 (patch) | |
tree | 4284490a2d3be19a40c447e2299dac4e0101c4a7 /src/mongo/db/catalog | |
parent | 99ec5dabaf1286a5440da0bb561e32d3aa79466a (diff) | |
download | mongo-a0f64a185b60422fe15b67a406c7b8e04c191937.tar.gz |
SERVER-37447 Introduce RequiresIndexStage and use for IXSCAN.
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r-- | src/mongo/db/catalog/index_catalog.h | 10 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_entry.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_entry.h | 22 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_impl.cpp | 56 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_impl.h | 3 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_noop.h | 4 |
6 files changed, 73 insertions, 37 deletions
diff --git a/src/mongo/db/catalog/index_catalog.h b/src/mongo/db/catalog/index_catalog.h index eadb7a56733..386a344d65c 100644 --- a/src/mongo/db/catalog/index_catalog.h +++ b/src/mongo/db/catalog/index_catalog.h @@ -280,10 +280,18 @@ public: const IndexDescriptor* const oldDesc) = 0; /** - * Never returns nullptr. + * Returns a pointer to the index catalog entry associated with 'desc'. Throws if there is no + * such index. Never returns nullptr. */ virtual const IndexCatalogEntry* getEntry(const IndexDescriptor* const desc) const = 0; + /** + * Returns a pointer to the index catalog entry associated with 'desc', where the caller assumes + * shared ownership of the entry. Returns null if the entry does not exist. + */ + virtual std::shared_ptr<const IndexCatalogEntry> getEntryShared( + const IndexDescriptor*) const = 0; + virtual IndexAccessMethod* getIndex(const IndexDescriptor* const desc) = 0; virtual const IndexAccessMethod* getIndex(const IndexDescriptor* const desc) const = 0; diff --git a/src/mongo/db/catalog/index_catalog_entry.cpp b/src/mongo/db/catalog/index_catalog_entry.cpp index 0f5f8dda58d..997cb4a4ba8 100644 --- a/src/mongo/db/catalog/index_catalog_entry.cpp +++ b/src/mongo/db/catalog/index_catalog_entry.cpp @@ -63,6 +63,16 @@ IndexCatalogEntry* IndexCatalogEntryContainer::find(const IndexDescriptor* desc) return nullptr; } +std::shared_ptr<IndexCatalogEntry> IndexCatalogEntryContainer::findShared( + const IndexDescriptor* desc) const { + for (auto&& entry : _entries) { + if (entry->descriptor() == desc) { + return entry; + } + } + return {}; +} + IndexCatalogEntry* IndexCatalogEntryContainer::find(const std::string& name) { for (iterator i = begin(); i != end(); ++i) { IndexCatalogEntry* e = i->get(); @@ -72,11 +82,12 @@ IndexCatalogEntry* IndexCatalogEntryContainer::find(const std::string& name) { return nullptr; } -IndexCatalogEntry* IndexCatalogEntryContainer::release(const IndexDescriptor* desc) { +std::shared_ptr<IndexCatalogEntry> IndexCatalogEntryContainer::release( + const IndexDescriptor* desc) { for (auto i = _entries.begin(); i != _entries.end(); ++i) { if ((*i)->descriptor() != desc) continue; - IndexCatalogEntry* e = i->release(); + auto e = std::move(*i); _entries.erase(i); return e; } diff --git a/src/mongo/db/catalog/index_catalog_entry.h b/src/mongo/db/catalog/index_catalog_entry.h index eb54f065e7b..192788e3948 100644 --- a/src/mongo/db/catalog/index_catalog_entry.h +++ b/src/mongo/db/catalog/index_catalog_entry.h @@ -156,8 +156,8 @@ public: class IndexCatalogEntryContainer { public: - typedef std::vector<std::unique_ptr<IndexCatalogEntry>>::const_iterator const_iterator; - typedef std::vector<std::unique_ptr<IndexCatalogEntry>>::const_iterator iterator; + typedef std::vector<std::shared_ptr<IndexCatalogEntry>>::const_iterator const_iterator; + typedef std::vector<std::shared_ptr<IndexCatalogEntry>>::const_iterator iterator; const_iterator begin() const { return _entries.begin(); @@ -182,6 +182,11 @@ public: IndexCatalogEntry* find(const std::string& name); + /** + * Returns a pointer to the IndexCatalogEntry corresponding to 'desc', where the caller assumes + * shared ownership of the catalog object. Returns null if the entry does not exist. + */ + std::shared_ptr<IndexCatalogEntry> findShared(const IndexDescriptor* desc) const; unsigned size() const { return _entries.size(); @@ -192,20 +197,17 @@ public: /** * Removes from _entries and returns the matching entry or NULL if none matches. */ - IndexCatalogEntry* release(const IndexDescriptor* desc); + std::shared_ptr<IndexCatalogEntry> release(const IndexDescriptor* desc); bool remove(const IndexDescriptor* desc) { - IndexCatalogEntry* entry = release(desc); - delete entry; - return entry; + return static_cast<bool>(release(desc)); } - // pass ownership to EntryContainer - void add(IndexCatalogEntry* entry) { - _entries.push_back(std::unique_ptr<IndexCatalogEntry>{entry}); + void add(std::shared_ptr<IndexCatalogEntry>&& entry) { + _entries.push_back(std::move(entry)); } private: - std::vector<std::unique_ptr<IndexCatalogEntry>> _entries; + std::vector<std::shared_ptr<IndexCatalogEntry>> _entries; }; } // namespace mongo diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index 837ccfd7b4a..9a4aa990ab0 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -150,20 +150,20 @@ IndexCatalogEntry* IndexCatalogImpl::_setupInMemoryStructures( } auto* const descriptorPtr = descriptor.get(); - auto entry = stdx::make_unique<IndexCatalogEntryImpl>(opCtx, - _collection->ns().ns(), - _collection->getCatalogEntry(), - std::move(descriptor), - _collection->infoCache()); + auto entry = std::make_shared<IndexCatalogEntryImpl>(opCtx, + _collection->ns().ns(), + _collection->getCatalogEntry(), + std::move(descriptor), + _collection->infoCache()); std::unique_ptr<IndexAccessMethod> accessMethod( _collection->dbce()->getIndex(opCtx, _collection->getCatalogEntry(), entry.get())); entry->init(std::move(accessMethod)); IndexCatalogEntry* save = entry.get(); if (isReadyIndex) { - _readyIndexes.add(entry.release()); + _readyIndexes.add(std::move(entry)); } else { - _buildingIndexes.add(entry.release()); + _buildingIndexes.add(std::move(entry)); } if (!initFromDisk) { @@ -821,8 +821,8 @@ public: IndexRemoveChange(OperationContext* opCtx, Collection* collection, IndexCatalogEntryContainer* entries, - IndexCatalogEntry* entry) - : _opCtx(opCtx), _collection(collection), _entries(entries), _entry(entry) {} + std::shared_ptr<IndexCatalogEntry> entry) + : _opCtx(opCtx), _collection(collection), _entries(entries), _entry(std::move(entry)) {} void commit(boost::optional<Timestamp> commitTime) final { // Ban reading from this collection on committed reads on snapshots before now. @@ -834,20 +834,18 @@ public: commitTime = LogicalClock::getClusterTimeForReplicaSet(_opCtx).asTimestamp(); } _collection->setMinimumVisibleSnapshot(commitTime.get()); - - delete _entry; } void rollback() final { - _entries->add(_entry); _collection->infoCache()->addedIndex(_opCtx, _entry->descriptor()); + _entries->add(std::move(_entry)); } private: OperationContext* _opCtx; Collection* _collection; IndexCatalogEntryContainer* _entries; - IndexCatalogEntry* _entry; + std::shared_ptr<IndexCatalogEntry> _entry; }; } // namespace @@ -881,14 +879,16 @@ Status IndexCatalogImpl::_dropIndex(OperationContext* opCtx, IndexCatalogEntry* auto released = _readyIndexes.release(entry->descriptor()); if (released) { - invariant(released == entry); + invariant(released.get() == entry); opCtx->recoveryUnit()->registerChange( - new IndexRemoveChange(opCtx, _collection, &_readyIndexes, entry)); + new IndexRemoveChange(opCtx, _collection, &_readyIndexes, std::move(released))); } else { - invariant(_buildingIndexes.release(entry->descriptor()) == entry); + released = _buildingIndexes.release(entry->descriptor()); + invariant(released.get() == entry); opCtx->recoveryUnit()->registerChange( - new IndexRemoveChange(opCtx, _collection, &_buildingIndexes, entry)); + new IndexRemoveChange(opCtx, _collection, &_buildingIndexes, std::move(released))); } + _collection->infoCache()->droppedIndex(opCtx, indexName); entry = nullptr; _deleteIndexFromDisk(opCtx, indexName, indexNamespace); @@ -1100,6 +1100,14 @@ const IndexCatalogEntry* IndexCatalogImpl::getEntry(const IndexDescriptor* desc) return entry; } +std::shared_ptr<const IndexCatalogEntry> IndexCatalogImpl::getEntryShared( + const IndexDescriptor* indexDescriptor) const { + auto entry = _readyIndexes.findShared(indexDescriptor); + if (entry) { + return entry; + } + return _buildingIndexes.findShared(indexDescriptor); +} const IndexDescriptor* IndexCatalogImpl::refreshEntry(OperationContext* opCtx, const IndexDescriptor* oldDesc) { @@ -1119,10 +1127,10 @@ const IndexDescriptor* IndexCatalogImpl::refreshEntry(OperationContext* opCtx, // Delete the IndexCatalogEntry that owns this descriptor. After deletion, 'oldDesc' is // invalid and should not be dereferenced. - IndexCatalogEntry* oldEntry = _readyIndexes.release(oldDesc); + auto oldEntry = _readyIndexes.release(oldDesc); invariant(oldEntry); opCtx->recoveryUnit()->registerChange( - new IndexRemoveChange(opCtx, _collection, &_readyIndexes, oldEntry)); + new IndexRemoveChange(opCtx, _collection, &_readyIndexes, std::move(oldEntry))); // Ask the CollectionCatalogEntry for the new index spec. BSONObj spec = _collection->getCatalogEntry()->getIndexSpec(opCtx, indexName).getOwned(); @@ -1348,11 +1356,13 @@ void IndexCatalogImpl::prepareInsertDeleteOptions(OperationContext* opCtx, } void IndexCatalogImpl::indexBuildSuccess(OperationContext* opCtx, IndexCatalogEntry* index) { - invariant(_buildingIndexes.release(index->descriptor())); - _readyIndexes.add(index); + auto releasedEntry = _buildingIndexes.release(index->descriptor()); + invariant(releasedEntry.get() == index); + _readyIndexes.add(std::move(releasedEntry)); opCtx->recoveryUnit()->onRollback([this, index]() { - invariant(_readyIndexes.release(index->descriptor())); - _buildingIndexes.add(index); + auto releasedEntry = _readyIndexes.release(index->descriptor()); + invariant(releasedEntry.get() == index); + _buildingIndexes.add(std::move(releasedEntry)); }); } diff --git a/src/mongo/db/catalog/index_catalog_impl.h b/src/mongo/db/catalog/index_catalog_impl.h index f37e145c5b9..7c6c415241f 100644 --- a/src/mongo/db/catalog/index_catalog_impl.h +++ b/src/mongo/db/catalog/index_catalog_impl.h @@ -162,9 +162,10 @@ public: const IndexDescriptor* refreshEntry(OperationContext* opCtx, const IndexDescriptor* oldDesc) override; - // never returns NULL const IndexCatalogEntry* getEntry(const IndexDescriptor* desc) const override; + std::shared_ptr<const IndexCatalogEntry> getEntryShared(const IndexDescriptor*) const override; + IndexAccessMethod* getIndex(const IndexDescriptor* desc) override; const IndexAccessMethod* getIndex(const IndexDescriptor* desc) const override; diff --git a/src/mongo/db/catalog/index_catalog_noop.h b/src/mongo/db/catalog/index_catalog_noop.h index 29ad037e221..e645831063a 100644 --- a/src/mongo/db/catalog/index_catalog_noop.h +++ b/src/mongo/db/catalog/index_catalog_noop.h @@ -115,6 +115,10 @@ public: return nullptr; } + std::shared_ptr<const IndexCatalogEntry> getEntryShared(const IndexDescriptor*) const override { + return nullptr; + } + IndexAccessMethod* getIndex(const IndexDescriptor* const desc) override { return nullptr; } |