diff options
author | Benety Goh <benety@mongodb.com> | 2018-12-10 14:14:27 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2018-12-10 14:14:48 -0500 |
commit | ba216692a2c1779dcf631f1e676ec9297aaf22e2 (patch) | |
tree | 600b56a6d79b13ab4c507c604a81e4e158823fc1 /src/mongo/db | |
parent | 1bef15e88938c69a96903a92ac20a4416e559a73 (diff) | |
download | mongo-ba216692a2c1779dcf631f1e676ec9297aaf22e2.tar.gz |
SERVER-38330 merge MultiIndexBlock and MultiIndexBlockImpl
Diffstat (limited to 'src/mongo/db')
24 files changed, 223 insertions, 373 deletions
diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp index 7971f96c29a..a7d13797fea 100644 --- a/src/mongo/db/catalog/collection_compact.cpp +++ b/src/mongo/db/catalog/collection_compact.cpp @@ -35,7 +35,6 @@ #include "mongo/db/catalog/document_validation.h" #include "mongo/db/catalog/index_key_validate.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/index/index_access_method.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/operation_context.h" @@ -129,7 +128,7 @@ StatusWith<CompactStats> compactCollection(OperationContext* opCtx, CompactStats stats; - MultiIndexBlockImpl indexer(opCtx, collection); + MultiIndexBlock indexer(opCtx, collection); indexer.allowInterruption(); indexer.ignoreUniqueConstraint(); // in compact we should be doing no checking diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp index b44c2c13c8f..0ba47b4d800 100644 --- a/src/mongo/db/catalog/database_test.cpp +++ b/src/mongo/db/catalog/database_test.cpp @@ -35,7 +35,6 @@ #include "mongo/bson/util/builder.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" @@ -300,7 +299,7 @@ void _testDropCollectionThrowsExceptionIfThereAreIndexesInProgress(OperationCont wuow.commit(); } - MultiIndexBlockImpl indexer(opCtx, collection); + MultiIndexBlock indexer(opCtx, collection); ON_BLOCK_EXIT([&indexer, opCtx] { WriteUnitOfWork wuow(opCtx); ASSERT_OK(indexer.commit()); diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp index 15138cae0df..e6d2b402861 100644 --- a/src/mongo/db/catalog/index_builds_manager.cpp +++ b/src/mongo/db/catalog/index_builds_manager.cpp @@ -34,8 +34,6 @@ #include "mongo/db/catalog/index_builds_manager.h" #include "mongo/db/catalog/collection.h" -#include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" #include "mongo/util/log.h" @@ -151,8 +149,7 @@ void IndexBuildsManager::_registerIndexBuild(OperationContext* opCtx, UUID buildUUID) { stdx::unique_lock<stdx::mutex> lk(_mutex); - std::shared_ptr<MultiIndexBlockImpl> mib = - std::make_shared<MultiIndexBlockImpl>(opCtx, collection); + std::shared_ptr<MultiIndexBlock> mib = std::make_shared<MultiIndexBlock>(opCtx, collection); invariant(_builders.insert(std::make_pair(buildUUID, mib)).second); } diff --git a/src/mongo/db/catalog/index_builds_manager.h b/src/mongo/db/catalog/index_builds_manager.h index fed73c8fe85..eb388b84d6c 100644 --- a/src/mongo/db/catalog/index_builds_manager.h +++ b/src/mongo/db/catalog/index_builds_manager.h @@ -34,13 +34,13 @@ #include <vector> #include "mongo/base/disallow_copying.h" +#include "mongo/db/catalog/multi_index_block.h" #include "mongo/db/namespace_string.h" #include "mongo/stdx/mutex.h" namespace mongo { class Collection; -class MultiIndexBlock; class OperationContext; class ServiceContext; diff --git a/src/mongo/db/catalog/index_builds_manager_test.cpp b/src/mongo/db/catalog/index_builds_manager_test.cpp index 90f78e013c7..30d6aa5dc94 100644 --- a/src/mongo/db/catalog/index_builds_manager_test.cpp +++ b/src/mongo/db/catalog/index_builds_manager_test.cpp @@ -32,8 +32,6 @@ #include "mongo/db/catalog/index_builds_manager.h" #include "mongo/db/catalog/catalog_test_fixture.h" -#include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" diff --git a/src/mongo/db/catalog/multi_index_block.h b/src/mongo/db/catalog/multi_index_block.h index 70283a83fa5..7edd3af8331 100644 --- a/src/mongo/db/catalog/multi_index_block.h +++ b/src/mongo/db/catalog/multi_index_block.h @@ -30,6 +30,7 @@ #pragma once +#include <iosfwd> #include <memory> #include <set> #include <string> @@ -37,16 +38,19 @@ #include "mongo/base/disallow_copying.h" #include "mongo/base/status.h" +#include "mongo/base/status_with.h" #include "mongo/base/string_data.h" +#include "mongo/bson/bsonobj.h" +#include "mongo/db/background.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/index/index_access_method.h" #include "mongo/db/record_id.h" #include "mongo/stdx/functional.h" +#include "mongo/stdx/mutex.h" namespace mongo { -class BackgroundOperation; -class BSONObj; class Collection; +class MatchExpression; class OperationContext; /** @@ -61,9 +65,11 @@ class OperationContext; * (as it is itself essentially a form of rollback, you don't want to "rollback the rollback"). */ class MultiIndexBlock { + MONGO_DISALLOW_COPYING(MultiIndexBlock); + public: - MultiIndexBlock() = default; - virtual ~MultiIndexBlock() = default; + MultiIndexBlock(OperationContext* opCtx, Collection* collection); + ~MultiIndexBlock(); /** * By default we ignore the 'background' flag in specs when building an index. If this is @@ -73,13 +79,13 @@ public: * indexes in the background, but there is a performance benefit to building all in the * foreground. */ - virtual void allowBackgroundBuilding() = 0; + void allowBackgroundBuilding(); /** * Call this before init() to allow the index build to be interrupted. * This only affects builds using the insertAllDocumentsInCollection helper. */ - virtual void allowInterruption() = 0; + void allowInterruption(); /** * By default we enforce the 'unique' flag in specs when building an index by failing. @@ -88,13 +94,13 @@ public: * * If this is called, any dupsOut sets passed in will never be filled. */ - virtual void ignoreUniqueConstraint() = 0; + void ignoreUniqueConstraint(); /** * Removes pre-existing indexes from 'specs'. If this isn't done, init() may fail with * IndexAlreadyExists. */ - virtual void removeExistingIndexes(std::vector<BSONObj>* const specs) const = 0; + void removeExistingIndexes(std::vector<BSONObj>* const specs) const; /** * Prepares the index(es) for building and returns the canonicalized form of the requested index @@ -104,9 +110,9 @@ public: * * Requires holding an exclusive database lock. */ - virtual StatusWith<std::vector<BSONObj>> init(const std::vector<BSONObj>& specs) = 0; + StatusWith<std::vector<BSONObj>> init(const std::vector<BSONObj>& specs); - virtual StatusWith<std::vector<BSONObj>> init(const BSONObj& spec) = 0; + StatusWith<std::vector<BSONObj>> init(const BSONObj& spec); /** * Inserts all documents in the Collection into the indexes and logs with timing info. @@ -120,7 +126,7 @@ public: * * Should not be called inside of a WriteUnitOfWork. */ - virtual Status insertAllDocumentsInCollection() = 0; + Status insertAllDocumentsInCollection(); /** * Call this after init() for each document in the collection. Any duplicate keys inserted will @@ -130,9 +136,9 @@ public: * * Should be called inside of a WriteUnitOfWork. */ - virtual Status insert(const BSONObj& wholeDocument, - const RecordId& loc, - std::vector<BSONObj>* const dupKeysInserted = nullptr) = 0; + Status insert(const BSONObj& wholeDocument, + const RecordId& loc, + std::vector<BSONObj>* const dupKeysInserted = nullptr); /** * Call this after the last insert(). This gives the index builder a chance to do any @@ -151,9 +157,9 @@ public: * * Should not be called inside of a WriteUnitOfWork. */ - virtual Status dumpInsertsFromBulk() = 0; - virtual Status dumpInsertsFromBulk(std::set<RecordId>* const dupRecords) = 0; - virtual Status dumpInsertsFromBulk(std::vector<BSONObj>* const dupKeysInserted) = 0; + Status dumpInsertsFromBulk(); + Status dumpInsertsFromBulk(std::set<RecordId>* const dupRecords); + Status dumpInsertsFromBulk(std::vector<BSONObj>* const dupKeysInserted); /** * For background indexes using an IndexBuildInterceptor to capture inserts during a build, @@ -164,7 +170,7 @@ public: * * Must not be in a WriteUnitOfWork. */ - virtual Status drainBackgroundWritesIfNeeded() = 0; + Status drainBackgroundWritesIfNeeded(); /** * Marks the index ready for use. Should only be called as the last method after @@ -177,15 +183,15 @@ public: * * Requires holding an exclusive database lock. */ - virtual Status commit() = 0; - virtual Status commit(stdx::function<void(const BSONObj& spec)> onCreateFn) = 0; + Status commit(); + Status commit(stdx::function<void(const BSONObj& spec)> onCreateFn); /** * Returns true if this index builder was added to the index catalog successfully. * In addition to having commit() return without errors, the enclosing WUOW has to be committed * for the indexes to show up in the index catalog. */ - virtual bool isCommitted() const = 0; + bool isCommitted() const; /** * Signals the index build to abort. @@ -203,7 +209,7 @@ public: * * May be called from any thread. */ - virtual void abort(StringData reason) = 0; + void abort(StringData reason); /** * May be called at any time after construction but before a successful commit(). Suppresses @@ -221,9 +227,87 @@ public: * * Must be called from owning thread. */ - virtual void abortWithoutCleanup() = 0; + void abortWithoutCleanup(); + + bool getBuildInBackground() const; + + /** + * State transitions: + * + * Uninitialized --> Running --> Committed + * | | ^ + * | | | + * \--------------+------> Aborted + * + * It is possible for abort() to skip intermediate states. For example, calling abort() when the + * index build has not been initialized will transition from Uninitialized directly to Aborted. + * + * In the case where we are in the midst of committing the WUOW for a successful commit() call, + * we may transition temporarily to Aborted before finally ending at Committed. See comments for + * MultiIndexBlock::abort(). + * + * For testing only. Callers should not have to query the state of the MultiIndexBlock directly. + */ + enum class State { kUninitialized, kRunning, kCommitted, kAborted }; + State getState_forTest() const; + +private: + struct IndexToBuild { + std::unique_ptr<IndexCatalog::IndexBuildBlockInterface> block; + + IndexAccessMethod* real = NULL; // owned elsewhere + const MatchExpression* filterExpression; // might be NULL, owned elsewhere + std::unique_ptr<IndexAccessMethod::BulkBuilder> bulk; + + InsertDeleteOptions options; + }; + + Status _dumpInsertsFromBulk(std::set<RecordId>* dupRecords, + std::vector<BSONObj>* dupKeysInserted); + + /** + * Returns the current state. + */ + State _getState() const; - virtual bool getBuildInBackground() const = 0; + /** + * Updates the current state to a non-Aborted state. + */ + void _setState(State newState); + + /** + * Updates the current state to Aborted with the given reason. + */ + void _setStateToAbortedIfNotCommitted(StringData reason); + + /** + * Updates CurOp's 'opDescription' field with the current state of this index build. + */ + void _updateCurOpOpDescription(bool isBuildingPhaseComplete) const; + + std::vector<IndexToBuild> _indexes; + + std::unique_ptr<BackgroundOperation> _backgroundOperation; + + // Pointers not owned here and must outlive 'this' + Collection* _collection; + OperationContext* _opCtx; + + bool _buildInBackground = false; + bool _allowInterruption = false; + bool _ignoreUnique = false; + + bool _needToCleanup = true; + + // Protects member variables of this class declared below. + mutable stdx::mutex _mutex; + + State _state = State::kUninitialized; + std::string _abortReason; }; +// For unit tests that need to check MultiIndexBlock states. +// The ASSERT_*() macros use this function to print the value of 'state' when the predicate fails. +std::ostream& operator<<(std::ostream& os, const MultiIndexBlock::State& state); + } // namespace mongo diff --git a/src/mongo/db/catalog/multi_index_block_impl.cpp b/src/mongo/db/catalog/multi_index_block_impl.cpp index aadf09f9bec..b6e05a07c16 100644 --- a/src/mongo/db/catalog/multi_index_block_impl.cpp +++ b/src/mongo/db/catalog/multi_index_block_impl.cpp @@ -32,20 +32,17 @@ #include "mongo/platform/basic.h" -#include "mongo/db/catalog/multi_index_block_impl.h" +#include "mongo/db/catalog/multi_index_block.h" #include <ostream> #include "mongo/base/error_codes.h" -#include "mongo/base/init.h" #include "mongo/db/audit.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/client.h" -#include "mongo/db/clientcursor.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/curop.h" -#include "mongo/db/exec/working_set_common.h" +#include "mongo/db/index/index_build_interceptor.h" #include "mongo/db/index/multikey_paths.h" #include "mongo/db/multi_key_path_tracker.h" #include "mongo/db/op_observer.h" @@ -53,13 +50,12 @@ #include "mongo/db/repl/repl_set_config.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/server_parameters.h" +#include "mongo/db/storage/write_unit_of_work.h" #include "mongo/logger/redaction.h" -#include "mongo/stdx/memory.h" -#include "mongo/stdx/mutex.h" +#include "mongo/util/assert_util.h" #include "mongo/util/fail_point.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" -#include "mongo/util/processinfo.h" #include "mongo/util/progress_meter.h" #include "mongo/util/quick_exit.h" #include "mongo/util/scopeguard.h" @@ -78,10 +74,6 @@ const StringData kCommitReadyMembersFieldName = "commitReadyMembers"_sd; MONGO_EXPORT_SERVER_PARAMETER(useReadOnceCursorsForIndexBuilds, bool, true); -using std::unique_ptr; -using std::string; -using std::endl; - MONGO_FAIL_POINT_DEFINE(crashAfterStartingIndexBuild); MONGO_FAIL_POINT_DEFINE(hangAfterStartingIndexBuild); MONGO_FAIL_POINT_DEFINE(hangAfterStartingIndexBuildUnlocked); @@ -113,49 +105,10 @@ public: } exportedMaxIndexBuildMemoryUsageParameter; -/** - * On rollback sets MultiIndexBlockImpl::_needToCleanup to true. - */ -class MultiIndexBlockImpl::SetNeedToCleanupOnRollback : public RecoveryUnit::Change { -public: - explicit SetNeedToCleanupOnRollback(MultiIndexBlockImpl* indexer) : _indexer(indexer) {} - - virtual void commit(boost::optional<Timestamp>) {} - virtual void rollback() { - _indexer->_needToCleanup = true; - } - -private: - MultiIndexBlockImpl* const _indexer; -}; - -/** - * On rollback in init(), cleans up _indexes so that ~MultiIndexBlock doesn't try to clean - * up _indexes manually (since the changes were already rolled back). - * Due to this, it is thus legal to call init() again after it fails. - */ -class MultiIndexBlockImpl::CleanupIndexesVectorOnRollback : public RecoveryUnit::Change { -public: - explicit CleanupIndexesVectorOnRollback(MultiIndexBlockImpl* indexer) : _indexer(indexer) {} - - virtual void commit(boost::optional<Timestamp>) {} - virtual void rollback() { - _indexer->_indexes.clear(); - } +MultiIndexBlock::MultiIndexBlock(OperationContext* opCtx, Collection* collection) + : _collection(collection), _opCtx(opCtx) {} -private: - MultiIndexBlockImpl* const _indexer; -}; - -MultiIndexBlockImpl::MultiIndexBlockImpl(OperationContext* opCtx, Collection* collection) - : _collection(collection), - _opCtx(opCtx), - _buildInBackground(false), - _allowInterruption(false), - _ignoreUnique(false), - _needToCleanup(true) {} - -MultiIndexBlockImpl::~MultiIndexBlockImpl() { +MultiIndexBlock::~MultiIndexBlock() { if (!_needToCleanup && !_indexes.empty()) { _collection->infoCache()->clearQueryCache(); } @@ -205,7 +158,19 @@ MultiIndexBlockImpl::~MultiIndexBlockImpl() { } } -void MultiIndexBlockImpl::removeExistingIndexes(std::vector<BSONObj>* specs) const { +void MultiIndexBlock::allowBackgroundBuilding() { + _buildInBackground = true; +} + +void MultiIndexBlock::allowInterruption() { + _allowInterruption = true; +} + +void MultiIndexBlock::ignoreUniqueConstraint() { + _ignoreUnique = true; +} + +void MultiIndexBlock::removeExistingIndexes(std::vector<BSONObj>* specs) const { for (size_t i = 0; i < specs->size(); i++) { Status status = _collection->getIndexCatalog()->prepareSpecForCreate(_opCtx, (*specs)[i]).getStatus(); @@ -217,12 +182,12 @@ void MultiIndexBlockImpl::removeExistingIndexes(std::vector<BSONObj>* specs) con } } -StatusWith<std::vector<BSONObj>> MultiIndexBlockImpl::init(const BSONObj& spec) { +StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(const BSONObj& spec) { const auto indexes = std::vector<BSONObj>(1, spec); return init(indexes); } -StatusWith<std::vector<BSONObj>> MultiIndexBlockImpl::init(const std::vector<BSONObj>& indexSpecs) { +StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(const std::vector<BSONObj>& indexSpecs) { if (State::kAborted == _getState()) { return {ErrorCodes::IndexBuildAborted, str::stream() << "Index build aborted: " << _abortReason @@ -241,9 +206,13 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlockImpl::init(const std::vector<BSO WriteUnitOfWork wunit(_opCtx); invariant(_indexes.empty()); - _opCtx->recoveryUnit()->registerChange(new CleanupIndexesVectorOnRollback(this)); - const string& ns = _collection->ns().ns(); + // On rollback in init(), cleans up _indexes so that ~MultiIndexBlock doesn't try to clean up + // _indexes manually (since the changes were already rolled back). + // Due to this, it is thus legal to call init() again after it fails. + _opCtx->recoveryUnit()->onRollback([this]() { _indexes.clear(); }); + + const auto& ns = _collection->ns().ns(); const auto idxCat = _collection->getIndexCatalog(); invariant(idxCat); @@ -361,7 +330,7 @@ void failPointHangDuringBuild(FailPoint* fp, StringData where, const BSONObj& do } } -Status MultiIndexBlockImpl::insertAllDocumentsInCollection() { +Status MultiIndexBlock::insertAllDocumentsInCollection() { invariant(_opCtx->lockState()->isNoop() || !_opCtx->lockState()->inAWriteUnitOfWork()); // Refrain from persisting any multikey updates as a result from building the index. Instead, @@ -514,9 +483,9 @@ Status MultiIndexBlockImpl::insertAllDocumentsInCollection() { return Status::OK(); } -Status MultiIndexBlockImpl::insert(const BSONObj& doc, - const RecordId& loc, - std::vector<BSONObj>* const dupKeysInserted) { +Status MultiIndexBlock::insert(const BSONObj& doc, + const RecordId& loc, + std::vector<BSONObj>* const dupKeysInserted) { if (State::kAborted == _getState()) { return {ErrorCodes::IndexBuildAborted, str::stream() << "Index build aborted: " << _abortReason @@ -552,20 +521,20 @@ Status MultiIndexBlockImpl::insert(const BSONObj& doc, return Status::OK(); } -Status MultiIndexBlockImpl::dumpInsertsFromBulk() { +Status MultiIndexBlock::dumpInsertsFromBulk() { return _dumpInsertsFromBulk(nullptr, nullptr); } -Status MultiIndexBlockImpl::dumpInsertsFromBulk(std::set<RecordId>* dupRecords) { +Status MultiIndexBlock::dumpInsertsFromBulk(std::set<RecordId>* dupRecords) { return _dumpInsertsFromBulk(dupRecords, nullptr); } -Status MultiIndexBlockImpl::dumpInsertsFromBulk(std::vector<BSONObj>* dupKeysInserted) { +Status MultiIndexBlock::dumpInsertsFromBulk(std::vector<BSONObj>* dupKeysInserted) { return _dumpInsertsFromBulk(nullptr, dupKeysInserted); } -Status MultiIndexBlockImpl::_dumpInsertsFromBulk(std::set<RecordId>* dupRecords, - std::vector<BSONObj>* dupKeysInserted) { +Status MultiIndexBlock::_dumpInsertsFromBulk(std::set<RecordId>* dupRecords, + std::vector<BSONObj>* dupKeysInserted) { if (State::kAborted == _getState()) { return {ErrorCodes::IndexBuildAborted, str::stream() << "Index build aborted: " << _abortReason @@ -597,7 +566,7 @@ Status MultiIndexBlockImpl::_dumpInsertsFromBulk(std::set<RecordId>* dupRecords, return Status::OK(); } -Status MultiIndexBlockImpl::drainBackgroundWritesIfNeeded() { +Status MultiIndexBlock::drainBackgroundWritesIfNeeded() { if (State::kAborted == _getState()) { return {ErrorCodes::IndexBuildAborted, str::stream() << "Index build aborted: " << _abortReason @@ -634,17 +603,17 @@ Status MultiIndexBlockImpl::drainBackgroundWritesIfNeeded() { } -void MultiIndexBlockImpl::abortWithoutCleanup() { +void MultiIndexBlock::abortWithoutCleanup() { _setStateToAbortedIfNotCommitted("aborted without cleanup"_sd); _indexes.clear(); _needToCleanup = false; } -Status MultiIndexBlockImpl::commit() { +Status MultiIndexBlock::commit() { return commit({}); } -Status MultiIndexBlockImpl::commit(stdx::function<void(const BSONObj& spec)> onCreateFn) { +Status MultiIndexBlock::commit(stdx::function<void(const BSONObj& spec)> onCreateFn) { if (State::kAborted == _getState()) { return {ErrorCodes::IndexBuildAborted, str::stream() << "Index build aborted: " << _abortReason @@ -703,39 +672,45 @@ Status MultiIndexBlockImpl::commit(stdx::function<void(const BSONObj& spec)> onC // before the WUOW is committed. If the WUOW commits, the final state of this index builder will // be Committed. Otherwise, the index builder state will remain as Aborted and further attempts // to commit this index build will fail. - _opCtx->recoveryUnit()->registerChange(new SetNeedToCleanupOnRollback(this)); _opCtx->recoveryUnit()->onCommit( - [this](boost::optional<Timestamp> commitTime) { this->_setState(State::kCommitted); }); + [this](boost::optional<Timestamp> commitTime) { _setState(State::kCommitted); }); + + // On rollback sets MultiIndexBlock::_needToCleanup to true. + _opCtx->recoveryUnit()->onRollback([this]() { _needToCleanup = true; }); _needToCleanup = false; return Status::OK(); } -bool MultiIndexBlockImpl::isCommitted() const { +bool MultiIndexBlock::isCommitted() const { return State::kCommitted == _getState(); } -void MultiIndexBlockImpl::abort(StringData reason) { +void MultiIndexBlock::abort(StringData reason) { _setStateToAbortedIfNotCommitted(reason); } -MultiIndexBlockImpl::State MultiIndexBlockImpl::getState_forTest() const { +bool MultiIndexBlock::getBuildInBackground() const { + return _buildInBackground; +} + +MultiIndexBlock::State MultiIndexBlock::getState_forTest() const { return _getState(); } -MultiIndexBlockImpl::State MultiIndexBlockImpl::_getState() const { +MultiIndexBlock::State MultiIndexBlock::_getState() const { stdx::lock_guard<stdx::mutex> lock(_mutex); return _state; } -void MultiIndexBlockImpl::_setState(State newState) { +void MultiIndexBlock::_setState(State newState) { invariant(State::kAborted != newState); stdx::lock_guard<stdx::mutex> lock(_mutex); _state = newState; } -void MultiIndexBlockImpl::_setStateToAbortedIfNotCommitted(StringData reason) { +void MultiIndexBlock::_setStateToAbortedIfNotCommitted(StringData reason) { stdx::lock_guard<stdx::mutex> lock(_mutex); if (State::kCommitted == _state) { return; @@ -744,7 +719,7 @@ void MultiIndexBlockImpl::_setStateToAbortedIfNotCommitted(StringData reason) { _abortReason = reason.toString(); } -void MultiIndexBlockImpl::_updateCurOpOpDescription(bool isBuildingPhaseComplete) const { +void MultiIndexBlock::_updateCurOpOpDescription(bool isBuildingPhaseComplete) const { BSONObjBuilder builder; // TODO(SERVER-37980): Replace with index build UUID. @@ -779,15 +754,15 @@ void MultiIndexBlockImpl::_updateCurOpOpDescription(bool isBuildingPhaseComplete curOp->ensureStarted(); } -std::ostream& operator<<(std::ostream& os, const MultiIndexBlockImpl::State& state) { +std::ostream& operator<<(std::ostream& os, const MultiIndexBlock::State& state) { switch (state) { - case MultiIndexBlockImpl::State::kUninitialized: + case MultiIndexBlock::State::kUninitialized: return os << "Uninitialized"; - case MultiIndexBlockImpl::State::kRunning: + case MultiIndexBlock::State::kRunning: return os << "Running"; - case MultiIndexBlockImpl::State::kCommitted: + case MultiIndexBlock::State::kCommitted: return os << "Committed"; - case MultiIndexBlockImpl::State::kAborted: + case MultiIndexBlock::State::kAborted: return os << "Aborted"; } MONGO_UNREACHABLE; diff --git a/src/mongo/db/catalog/multi_index_block_impl.h b/src/mongo/db/catalog/multi_index_block_impl.h deleted file mode 100644 index d8f729b49b5..00000000000 --- a/src/mongo/db/catalog/multi_index_block_impl.h +++ /dev/null @@ -1,190 +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. - */ - -#pragma once - -#include "mongo/db/catalog/multi_index_block.h" - -#include <iosfwd> -#include <memory> -#include <set> -#include <string> -#include <vector> - -#include "mongo/base/disallow_copying.h" -#include "mongo/base/status.h" -#include "mongo/db/catalog/index_catalog.h" -#include "mongo/db/catalog/index_catalog_impl.h" -#include "mongo/db/index/index_access_method.h" -#include "mongo/db/record_id.h" -#include "mongo/stdx/mutex.h" - -namespace mongo { - -class BackgroundOperation; -class BSONObj; -class Collection; -class OperationContext; - -class MultiIndexBlockImpl : public MultiIndexBlock { - MONGO_DISALLOW_COPYING(MultiIndexBlockImpl); - -public: - MultiIndexBlockImpl(OperationContext* opCtx, Collection* collection); - ~MultiIndexBlockImpl() override; - - void allowBackgroundBuilding() override { - _buildInBackground = true; - } - - void allowInterruption() override { - _allowInterruption = true; - } - - void ignoreUniqueConstraint() override { - _ignoreUnique = true; - } - - void removeExistingIndexes(std::vector<BSONObj>* specs) const override; - - StatusWith<std::vector<BSONObj>> init(const std::vector<BSONObj>& specs) override; - StatusWith<std::vector<BSONObj>> init(const BSONObj& spec) override; - - Status insertAllDocumentsInCollection() override; - - Status insert(const BSONObj& doc, - const RecordId& loc, - std::vector<BSONObj>* const dupKeysInserted = nullptr) override; - - Status dumpInsertsFromBulk() override; - Status dumpInsertsFromBulk(std::set<RecordId>* dupRecords) override; - Status dumpInsertsFromBulk(std::vector<BSONObj>* dupKeysInserted) override; - - /** - * See MultiIndexBlock::drainBackgroundWritesIfNeeded() - */ - Status drainBackgroundWritesIfNeeded() override; - - Status commit() override; - Status commit(stdx::function<void(const BSONObj& spec)> onCreateFn) override; - - bool isCommitted() const override; - - void abort(StringData reason) override; - - void abortWithoutCleanup() override; - - bool getBuildInBackground() const override { - return _buildInBackground; - } - - /** - * State transitions: - * - * Uninitialized --> Running --> Committed - * | | ^ - * | | | - * \--------------+------> Aborted - * - * It is possible for abort() to skip intermediate states. For example, calling abort() when the - * index build has not been initialized will transition from Uninitialized directly to Aborted. - * - * In the case where we are in the midst of committing the WUOW for a successful commit() call, - * we may transition temporarily to Aborted before finally ending at Committed. See comments for - * MultiIndexBlock::abort(). - * - * Not part of MultiIndexBlock interface. Callers should not have to query the state of the - * MultiIndexBlock directly. - */ - enum class State { kUninitialized, kRunning, kCommitted, kAborted }; - State getState_forTest() const; - -private: - class SetNeedToCleanupOnRollback; - class CleanupIndexesVectorOnRollback; - - struct IndexToBuild { - std::unique_ptr<IndexCatalog::IndexBuildBlockInterface> block; - - IndexAccessMethod* real = NULL; // owned elsewhere - const MatchExpression* filterExpression; // might be NULL, owned elsewhere - std::unique_ptr<IndexAccessMethod::BulkBuilder> bulk; - - InsertDeleteOptions options; - }; - - Status _dumpInsertsFromBulk(std::set<RecordId>* dupRecords, - std::vector<BSONObj>* dupKeysInserted); - - /** - * Returns the current state. - */ - State _getState() const; - - /** - * Updates the current state to a non-Aborted state. - */ - void _setState(State newState); - - /** - * Updates the current state to Aborted with the given reason. - */ - void _setStateToAbortedIfNotCommitted(StringData reason); - - /** - * Updates CurOp's 'opDescription' field with the current state of this index build. - */ - void _updateCurOpOpDescription(bool isBuildingPhaseComplete) const; - - std::vector<IndexToBuild> _indexes; - - std::unique_ptr<BackgroundOperation> _backgroundOperation; - - // Pointers not owned here and must outlive 'this' - Collection* _collection; - OperationContext* _opCtx; - - bool _buildInBackground; - bool _allowInterruption; - bool _ignoreUnique; - - bool _needToCleanup; - - // Protects member variables of this class declared below. - mutable stdx::mutex _mutex; - - State _state = State::kUninitialized; - std::string _abortReason; -}; - -// For unit tests that need to check MultiIndexBlock states. -// The ASSERT_*() macros use this function to print the value of 'state' when the predicate fails. -std::ostream& operator<<(std::ostream& os, const MultiIndexBlockImpl::State& state); - -} // namespace mongo diff --git a/src/mongo/db/catalog/multi_index_block_test.cpp b/src/mongo/db/catalog/multi_index_block_test.cpp index 5a7323991e0..86eb8c52098 100644 --- a/src/mongo/db/catalog/multi_index_block_test.cpp +++ b/src/mongo/db/catalog/multi_index_block_test.cpp @@ -28,9 +28,12 @@ * it in the license file. */ +#include "mongo/platform/basic.h" + +#include "mongo/db/catalog/multi_index_block.h" + #include "mongo/db/catalog/collection_mock.h" #include "mongo/db/catalog/index_catalog_noop.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/jsobj.h" #include "mongo/db/repl/replication_coordinator_mock.h" #include "mongo/db/service_context_test_fixture.h" @@ -54,12 +57,12 @@ private: protected: OperationContext* getOpCtx() const; Collection* getCollection() const; - MultiIndexBlockImpl* getIndexer() const; + MultiIndexBlock* getIndexer() const; private: ServiceContext::UniqueOperationContext _opCtx; std::unique_ptr<Collection> _collection; - std::unique_ptr<MultiIndexBlockImpl> _indexer; + std::unique_ptr<MultiIndexBlock> _indexer; }; void MultiIndexBlockTest::setUp() { @@ -76,7 +79,7 @@ void MultiIndexBlockTest::setUp() { std::make_unique<CollectionMock>(nss, std::make_unique<IndexCatalogNoop>()); _collection = std::make_unique<Collection>(std::move(collectionMock)); - _indexer = std::make_unique<MultiIndexBlockImpl>(_opCtx.get(), _collection.get()); + _indexer = std::make_unique<MultiIndexBlock>(_opCtx.get(), _collection.get()); } void MultiIndexBlockTest::tearDown() { @@ -100,17 +103,17 @@ Collection* MultiIndexBlockTest::getCollection() const { return _collection.get(); } -MultiIndexBlockImpl* MultiIndexBlockTest::getIndexer() const { +MultiIndexBlock* MultiIndexBlockTest::getIndexer() const { return _indexer.get(); } TEST_F(MultiIndexBlockTest, CommitWithoutInsertingDocuments) { auto indexer = getIndexer(); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kUninitialized, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kUninitialized, indexer->getState_forTest()); auto specs = unittest::assertGet(indexer->init(std::vector<BSONObj>())); ASSERT_EQUALS(0U, specs.size()); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kRunning, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kRunning, indexer->getState_forTest()); ASSERT_OK(indexer->dumpInsertsFromBulk()); @@ -121,16 +124,16 @@ TEST_F(MultiIndexBlockTest, CommitWithoutInsertingDocuments) { wunit.commit(); } ASSERT(indexer->isCommitted()); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kCommitted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kCommitted, indexer->getState_forTest()); } TEST_F(MultiIndexBlockTest, CommitAfterInsertingSingleDocument) { auto indexer = getIndexer(); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kUninitialized, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kUninitialized, indexer->getState_forTest()); auto specs = unittest::assertGet(indexer->init(std::vector<BSONObj>())); ASSERT_EQUALS(0U, specs.size()); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kRunning, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kRunning, indexer->getState_forTest()); ASSERT_OK(indexer->insert({}, {}, nullptr)); ASSERT_OK(indexer->dumpInsertsFromBulk()); @@ -154,80 +157,80 @@ TEST_F(MultiIndexBlockTest, AbortWithoutCleanupAfterInsertingSingleDocument) { ASSERT_EQUALS(0U, specs.size()); ASSERT_OK(indexer->insert({}, {}, nullptr)); indexer->abortWithoutCleanup(); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kAborted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kAborted, indexer->getState_forTest()); ASSERT_FALSE(indexer->isCommitted()); } TEST_F(MultiIndexBlockTest, InitFailsAfterAbort) { auto indexer = getIndexer(); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kUninitialized, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kUninitialized, indexer->getState_forTest()); indexer->abort("test"_sd); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kAborted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kAborted, indexer->getState_forTest()); ASSERT_EQUALS(ErrorCodes::IndexBuildAborted, indexer->init(std::vector<BSONObj>()).getStatus()); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kAborted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kAborted, indexer->getState_forTest()); ASSERT_FALSE(indexer->isCommitted()); } TEST_F(MultiIndexBlockTest, InsertingSingleDocumentFailsAfterAbort) { auto indexer = getIndexer(); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kUninitialized, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kUninitialized, indexer->getState_forTest()); auto specs = unittest::assertGet(indexer->init(std::vector<BSONObj>())); ASSERT_EQUALS(0U, specs.size()); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kRunning, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kRunning, indexer->getState_forTest()); indexer->abort("test"_sd); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kAborted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kAborted, indexer->getState_forTest()); ASSERT_EQUALS(ErrorCodes::IndexBuildAborted, indexer->insert(BSON("_id" << 123 << "a" << 456), {}, nullptr)); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kAborted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kAborted, indexer->getState_forTest()); ASSERT_FALSE(indexer->isCommitted()); } TEST_F(MultiIndexBlockTest, dumpInsertsFromBulkFailsAfterAbort) { auto indexer = getIndexer(); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kUninitialized, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kUninitialized, indexer->getState_forTest()); auto specs = unittest::assertGet(indexer->init(std::vector<BSONObj>())); ASSERT_EQUALS(0U, specs.size()); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kRunning, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kRunning, indexer->getState_forTest()); ASSERT_OK(indexer->insert(BSON("_id" << 123 << "a" << 456), {}, nullptr)); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kRunning, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kRunning, indexer->getState_forTest()); indexer->abort("test"_sd); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kAborted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kAborted, indexer->getState_forTest()); ASSERT_EQUALS(ErrorCodes::IndexBuildAborted, indexer->dumpInsertsFromBulk()); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kAborted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kAborted, indexer->getState_forTest()); ASSERT_FALSE(indexer->isCommitted()); } TEST_F(MultiIndexBlockTest, CommitFailsAfterAbort) { auto indexer = getIndexer(); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kUninitialized, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kUninitialized, indexer->getState_forTest()); auto specs = unittest::assertGet(indexer->init(std::vector<BSONObj>())); ASSERT_EQUALS(0U, specs.size()); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kRunning, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kRunning, indexer->getState_forTest()); ASSERT_OK(indexer->insert(BSON("_id" << 123 << "a" << 456), {}, nullptr)); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kRunning, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kRunning, indexer->getState_forTest()); ASSERT_OK(indexer->dumpInsertsFromBulk()); indexer->abort("test"_sd); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kAborted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kAborted, indexer->getState_forTest()); ASSERT_EQUALS(ErrorCodes::IndexBuildAborted, indexer->commit()); - ASSERT_EQUALS(MultiIndexBlockImpl::State::kAborted, indexer->getState_forTest()); + ASSERT_EQUALS(MultiIndexBlock::State::kAborted, indexer->getState_forTest()); ASSERT_FALSE(indexer->isCommitted()); } diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index c6c8c128e4c..b25c15617df 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -41,7 +41,6 @@ #include "mongo/db/catalog/drop_collection.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -431,7 +430,7 @@ Status renameCollectionCommon(OperationContext* opCtx, // Copy the index descriptions from the source collection, adjusting the ns field. { - MultiIndexBlockImpl indexer(opCtx, tmpColl); + MultiIndexBlock indexer(opCtx, tmpColl); indexer.allowInterruption(); std::vector<BSONObj> indexesToCopy; diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp index 3280f7836c2..3048d874df1 100644 --- a/src/mongo/db/catalog/rename_collection_test.cpp +++ b/src/mongo/db/catalog/rename_collection_test.cpp @@ -38,7 +38,6 @@ #include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/catalog/rename_collection.h" #include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/client.h" @@ -417,7 +416,7 @@ void _createIndex(OperationContext* opCtx, << "ns" << nss.ns()); - MultiIndexBlockImpl indexer(opCtx, collection); + MultiIndexBlock indexer(opCtx, collection); ASSERT_OK(indexer.init(indexInfoObj).getStatus()); WriteUnitOfWork wuow(opCtx); ASSERT_OK(indexer.commit()); diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index cdc3703dcc4..350eb309f7e 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -45,7 +45,6 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/commands.h" #include "mongo/db/commands/list_collections_filter.h" #include "mongo/db/commands/rename_collection.h" @@ -394,7 +393,7 @@ void Cloner::copyIndexes(OperationContext* opCtx, // from creation to completion without yielding to ensure the index and the collection // matches. It also wouldn't work on non-empty collections so we would need both // implementations anyway as long as that is supported. - MultiIndexBlockImpl indexer(opCtx, collection); + MultiIndexBlock indexer(opCtx, collection); indexer.allowInterruption(); indexer.removeExistingIndexes(&indexesToBuild); diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index ea461d2a5c3..9dcf9ebd467 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -42,7 +42,6 @@ #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/index_key_validate.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/client.h" #include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" @@ -360,7 +359,7 @@ public: dbProfilingLevel); - MultiIndexBlockImpl indexer(opCtx, collection); + MultiIndexBlock indexer(opCtx, collection); indexer.allowBackgroundBuilding(); indexer.allowInterruption(); diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 006e2b399ac..8d01d7f5004 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -45,7 +45,6 @@ #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/index_key_validate.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -203,7 +202,7 @@ public: WriteUnitOfWork wunit(opCtx); collection->getIndexCatalog()->dropAllIndexes(opCtx, true); - indexer = std::make_unique<MultiIndexBlockImpl>(opCtx, collection); + indexer = std::make_unique<MultiIndexBlock>(opCtx, collection); swIndexesToRebuild = indexer->init(all); uassertStatusOK(swIndexesToRebuild.getStatus()); diff --git a/src/mongo/db/index/duplicate_key_tracker_test.cpp b/src/mongo/db/index/duplicate_key_tracker_test.cpp index b1abac80d95..f96ff4831c8 100644 --- a/src/mongo/db/index/duplicate_key_tracker_test.cpp +++ b/src/mongo/db/index/duplicate_key_tracker_test.cpp @@ -31,7 +31,7 @@ #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/database_catalog_entry.h" -#include "mongo/db/catalog/multi_index_block_impl.h" +#include "mongo/db/catalog/multi_index_block.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/curop.h" @@ -148,7 +148,7 @@ TEST_F(DuplicateKeyTrackerTest, IndexBuild) { AutoGetCollection autoColl(opCtx(), collNs, MODE_X); auto coll = autoColl.getCollection(); - MultiIndexBlockImpl indexer(opCtx(), coll); + MultiIndexBlock indexer(opCtx(), coll); // Don't use the bulk builder, which does not insert directly into the IAM for the index. indexer.allowBackgroundBuilding(); // Allow duplicates. @@ -259,7 +259,7 @@ TEST_F(DuplicateKeyTrackerTest, BulkIndexBuild) { AutoGetCollection autoColl(opCtx(), collNs, MODE_X); auto coll = autoColl.getCollection(); - MultiIndexBlockImpl indexer(opCtx(), coll); + MultiIndexBlock indexer(opCtx(), coll); // Allow duplicates. indexer.ignoreUniqueConstraint(); diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp index 3335b0a421d..5861f08ffe6 100644 --- a/src/mongo/db/index_builder.cpp +++ b/src/mongo/db/index_builder.cpp @@ -38,7 +38,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" -#include "mongo/db/catalog/multi_index_block_impl.h" +#include "mongo/db/catalog/multi_index_block.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/curop.h" @@ -236,7 +236,7 @@ Status IndexBuilder::_build(OperationContext* opCtx, curOp->setOpDescription_inlock(opDescObj); } - MultiIndexBlockImpl indexer(opCtx, coll); + MultiIndexBlock indexer(opCtx, coll); indexer.allowInterruption(); if (allowBackgroundBuilding) indexer.allowBackgroundBuilding(); diff --git a/src/mongo/db/index_builds_coordinator_mongod_test.cpp b/src/mongo/db/index_builds_coordinator_mongod_test.cpp index 841d1618ee5..98c5c59a31a 100644 --- a/src/mongo/db/index_builds_coordinator_mongod_test.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod_test.cpp @@ -32,8 +32,6 @@ #include "mongo/db/index_builds_coordinator_mongod.h" #include "mongo/db/catalog/catalog_test_fixture.h" -#include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" diff --git a/src/mongo/db/index_rebuilder.cpp b/src/mongo/db/index_rebuilder.cpp index 9478ad0a8c4..bb634c36e22 100644 --- a/src/mongo/db/index_rebuilder.cpp +++ b/src/mongo/db/index_rebuilder.cpp @@ -42,7 +42,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_catalog_entry.h" -#include "mongo/db/catalog/multi_index_block_impl.h" +#include "mongo/db/catalog/multi_index_block.h" #include "mongo/db/client.h" #include "mongo/db/db_raii.h" #include "mongo/db/service_context.h" @@ -82,7 +82,7 @@ void checkNS(OperationContext* opCtx, const std::list<std::string>& nsToCheck) { } - MultiIndexBlockImpl indexer(opCtx, collection); + MultiIndexBlock indexer(opCtx, collection); { WriteUnitOfWork wunit(opCtx); diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index 6a0ededa2c0..07547484a79 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -49,7 +49,6 @@ #include "mongo/db/catalog/document_validation.h" #include "mongo/db/catalog/index_key_validate.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/catalog/namespace_uuid_cache.h" #include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -148,7 +147,7 @@ Status rebuildIndexesOnCollection(OperationContext* opCtx, const auto uuid = cce->getCollectionOptions(opCtx).uuid; collection.reset(new Collection(opCtx, ns, uuid, cce, dbce->getRecordStore(ns), dbce)); - indexer = std::make_unique<MultiIndexBlockImpl>(opCtx, collection.get()); + indexer = std::make_unique<MultiIndexBlock>(opCtx, collection.get()); Status status = indexer->init(indexSpecs).getStatus(); if (!status.isOK()) { // The WUOW will handle cleanup, so the indexer shouldn't do its own. diff --git a/src/mongo/db/repl/collection_bulk_loader_impl.cpp b/src/mongo/db/repl/collection_bulk_loader_impl.cpp index 4dd31ed31a9..4082c9ef522 100644 --- a/src/mongo/db/repl/collection_bulk_loader_impl.cpp +++ b/src/mongo/db/repl/collection_bulk_loader_impl.cpp @@ -37,8 +37,6 @@ #include "mongo/bson/bsonobj.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/catalog/collection.h" -#include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -62,10 +60,9 @@ CollectionBulkLoaderImpl::CollectionBulkLoaderImpl(ServiceContext::UniqueClient& _opCtx{std::move(opCtx)}, _autoColl{std::move(autoColl)}, _nss{_autoColl->getCollection()->ns()}, - _idIndexBlock( - std::make_unique<MultiIndexBlockImpl>(_opCtx.get(), _autoColl->getCollection())), + _idIndexBlock(std::make_unique<MultiIndexBlock>(_opCtx.get(), _autoColl->getCollection())), _secondaryIndexesBlock( - std::make_unique<MultiIndexBlockImpl>(_opCtx.get(), _autoColl->getCollection())), + std::make_unique<MultiIndexBlock>(_opCtx.get(), _autoColl->getCollection())), _idIndexSpec(idIndexSpec.getOwned()) { invariant(_opCtx); diff --git a/src/mongo/db/repl/rs_rollback_test.cpp b/src/mongo/db/repl/rs_rollback_test.cpp index 146e453a77d..48aba20fc05 100644 --- a/src/mongo/db/repl/rs_rollback_test.cpp +++ b/src/mongo/db/repl/rs_rollback_test.cpp @@ -40,7 +40,6 @@ #include "mongo/db/catalog/drop_indexes.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" @@ -177,7 +176,7 @@ int createIndexForColl(OperationContext* opCtx, NamespaceString nss, BSONObj indexSpec) { Lock::DBLock dbLock(opCtx, nss.db(), MODE_X); - MultiIndexBlockImpl indexer(opCtx, coll); + MultiIndexBlock indexer(opCtx, coll); ASSERT_OK(indexer.init(indexSpec).getStatus()); WriteUnitOfWork wunit(opCtx); ASSERT_OK(indexer.commit()); diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp index a02d85e0b1c..87c762aeebe 100644 --- a/src/mongo/db/repl/storage_interface_impl_test.cpp +++ b/src/mongo/db/repl/storage_interface_impl_test.cpp @@ -40,7 +40,6 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/document_validation.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -138,7 +137,7 @@ int createIndexForColl(OperationContext* opCtx, NamespaceString nss, BSONObj ind AutoGetCollection autoColl(opCtx, nss, MODE_X); auto coll = autoColl.getCollection(); - MultiIndexBlockImpl indexer(opCtx, coll); + MultiIndexBlock indexer(opCtx, coll); ASSERT_OK(indexer.init(indexSpec).getStatus()); WriteUnitOfWork wunit(opCtx); diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp index aca0f74e0ef..b5fa35e7b14 100644 --- a/src/mongo/db/s/migration_destination_manager.cpp +++ b/src/mongo/db/s/migration_destination_manager.cpp @@ -41,7 +41,6 @@ #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/document_validation.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/namespace_string.h" @@ -641,7 +640,7 @@ void MigrationDestinationManager::cloneCollectionIndexesAndOptions(OperationCont collection = db->getCollection(opCtx, nss); } - MultiIndexBlockImpl indexer(opCtx, collection); + MultiIndexBlock indexer(opCtx, collection); indexer.removeExistingIndexes(&donorIndexSpecs); if (!donorIndexSpecs.empty()) { diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp index 07f8b198d0e..1b7676b0596 100644 --- a/src/mongo/db/system_index.cpp +++ b/src/mongo/db/system_index.cpp @@ -42,7 +42,6 @@ #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/index_key_validate.h" #include "mongo/db/catalog/multi_index_block.h" -#include "mongo/db/catalog/multi_index_block_impl.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/curop.h" @@ -125,7 +124,7 @@ void generateSystemIndexForExistingCollection(OperationContext* opCtx, log() << "No authorization index detected on " << ns << " collection. Attempting to recover by creating an index with spec: " << indexSpec; - MultiIndexBlockImpl indexer(opCtx, collection); + MultiIndexBlock indexer(opCtx, collection); writeConflictRetry(opCtx, "authorization index regeneration", ns.ns(), [&] { fassert(40453, indexer.init(indexSpec)); |