diff options
author | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2018-11-12 16:21:17 -0500 |
---|---|---|
committer | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2018-11-12 22:18:53 -0500 |
commit | a5ce10b0982c7a0378ba92f1c7d3e02d49d0b18a (patch) | |
tree | 6113b3c963340471b4ab926d57d94b25077b31dc /src/mongo/db/catalog/index_catalog.cpp | |
parent | 1a6ca6d1399d56656e3edd0f92fdc494cf491178 (diff) | |
download | mongo-a5ce10b0982c7a0378ba92f1c7d3e02d49d0b18a.tar.gz |
SERVER-37263: Write updates to background building indexes into a temp table.
- IndexIterator returns IndexCatalogEntry*
- Split out ready from building indexes in the IndexCatalog.
Diffstat (limited to 'src/mongo/db/catalog/index_catalog.cpp')
-rw-r--r-- | src/mongo/db/catalog/index_catalog.cpp | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp index ab704d555e4..7f68b7ef77c 100644 --- a/src/mongo/db/catalog/index_catalog.cpp +++ b/src/mongo/db/catalog/index_catalog.cpp @@ -37,69 +37,66 @@ namespace mongo { +using IndexIterator = IndexCatalog::IndexIterator; +using ReadyIndexesIterator = IndexCatalog::ReadyIndexesIterator; +using AllIndexesIterator = IndexCatalog::AllIndexesIterator; -IndexCatalog::IndexIterator::IndexIterator(OperationContext* opCtx, - IndexCatalogEntryContainer::const_iterator beginIterator, - IndexCatalogEntryContainer::const_iterator endIterator, - bool includeUnfinishedIndexes) - : _includeUnfinishedIndexes(includeUnfinishedIndexes), - _opCtx(opCtx), - _iterator(beginIterator), - _endIterator(endIterator), - _start(true), - _prev(nullptr), - _next(nullptr) {} - -bool IndexCatalog::IndexIterator::more() { +bool IndexIterator::more() { if (_start) { - _advance(); + _next = _advance(); _start = false; } return _next != nullptr; } -IndexDescriptor* IndexCatalog::IndexIterator::next() { +IndexCatalogEntry* IndexIterator::next() { if (!more()) return nullptr; _prev = _next; - _advance(); - return _prev->descriptor(); -} - -IndexAccessMethod* IndexCatalog::IndexIterator::accessMethod(const IndexDescriptor* desc) { - invariant(desc == _prev->descriptor()); - return _prev->accessMethod(); -} - -IndexCatalogEntry* IndexCatalog::IndexIterator::catalogEntry(const IndexDescriptor* desc) { - invariant(desc == _prev->descriptor()); + _next = _advance(); return _prev; } -void IndexCatalog::IndexIterator::_advance() { - _next = nullptr; +ReadyIndexesIterator::ReadyIndexesIterator(OperationContext* const opCtx, + IndexCatalogEntryContainer::const_iterator beginIterator, + IndexCatalogEntryContainer::const_iterator endIterator) + : _opCtx(opCtx), _iterator(beginIterator), _endIterator(endIterator) {} +IndexCatalogEntry* ReadyIndexesIterator::_advance() { while (_iterator != _endIterator) { IndexCatalogEntry* entry = _iterator->get(); ++_iterator; - if (!_includeUnfinishedIndexes) { - if (auto minSnapshot = entry->getMinimumVisibleSnapshot()) { - if (auto mySnapshot = _opCtx->recoveryUnit()->getPointInTimeReadTimestamp()) { - if (mySnapshot < minSnapshot) { - // This index isn't finished in my snapshot. - continue; - } + if (auto minSnapshot = entry->getMinimumVisibleSnapshot()) { + if (auto mySnapshot = _opCtx->recoveryUnit()->getPointInTimeReadTimestamp()) { + if (mySnapshot < minSnapshot) { + // This index isn't finished in my snapshot. + continue; } } - - if (!entry->isReady(_opCtx)) - continue; } - _next = entry; - return; + return entry; } + + return nullptr; +} + +AllIndexesIterator::AllIndexesIterator( + OperationContext* const opCtx, std::unique_ptr<std::vector<IndexCatalogEntry*>> ownedContainer) + : _opCtx(opCtx), _ownedContainer(std::move(ownedContainer)) { + // Explicitly order calls onto the ownedContainer with respect to its move. + _iterator = _ownedContainer->begin(); + _endIterator = _ownedContainer->end(); } +IndexCatalogEntry* AllIndexesIterator::_advance() { + if (_iterator == _endIterator) { + return nullptr; + } + + IndexCatalogEntry* entry = *_iterator; + ++_iterator; + return entry; +} } // namespace mongo |