diff options
author | Louis Williams <louis.williams@mongodb.com> | 2020-05-26 09:48:38 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-26 14:06:39 +0000 |
commit | 0e4178afe88237ead101b11fcb19864d9d5a903c (patch) | |
tree | c60ebdc794638b05f675c8406f053092c5b69dfe | |
parent | 2992a78c15fbd1db49f0eec86a2b0ffbc63954e0 (diff) | |
download | mongo-0e4178afe88237ead101b11fcb19864d9d5a903c.tar.gz |
SERVER-39140 Remove BackgroundOperation
39 files changed, 29 insertions, 431 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 0af7144915e..ee67d55007a 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -360,7 +360,6 @@ mongod = env.Program( 'base', 'db/auth/auth_op_observer', 'db/auth/authmongod', - 'db/background', 'db/bson/dotted_path_support', 'db/catalog/catalog_impl', 'db/catalog/collection_options', diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 21758122562..a21e77b47cc 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -836,17 +836,6 @@ env.Library( ) env.Library( - target="background", - source=[ - "background.cpp", - ], - LIBDEPS=[ - "$BUILD_DIR/mongo/base", - '$BUILD_DIR/mongo/db/service_context', - ], -) - -env.Library( target="index_builds_coordinator_mongod", source=[ "index_builds_coordinator_mongod.cpp", @@ -1026,7 +1015,6 @@ env.Library( LIBDEPS=[ '$BUILD_DIR/mongo/db/catalog/collection', 'rw_concern_d', - 'background', 'logical_clock', ], LIBDEPS_PRIVATE=[ @@ -1134,7 +1122,6 @@ env.Library( '$BUILD_DIR/mongo/util/elapsed_tracker', '$BUILD_DIR/third_party/s2/s2', 'audit', - 'background', 'bson/dotted_path_support', 'catalog/collection', 'catalog/collection_query_info', diff --git a/src/mongo/db/background.cpp b/src/mongo/db/background.cpp deleted file mode 100644 index 05acf78fb46..00000000000 --- a/src/mongo/db/background.cpp +++ /dev/null @@ -1,222 +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. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/db/background.h" - -#include <iostream> -#include <string> - -#include "mongo/db/operation_context.h" -#include "mongo/platform/mutex.h" -#include "mongo/stdx/condition_variable.h" -#include "mongo/stdx/thread.h" -#include "mongo/util/assert_util.h" -#include "mongo/util/str.h" -#include "mongo/util/string_map.h" - -namespace mongo { - -namespace { - -class BgInfo { - BgInfo(const BgInfo&) = delete; - BgInfo& operator=(const BgInfo&) = delete; - -public: - BgInfo() : _opsInProgCount(0), _opRemovalsCount(0) {} - - void recordBegin(); - int recordEnd(); - void awaitNoBgOps(stdx::unique_lock<Latch>& lk); - - int getOpsInProgCount() const { - return _opsInProgCount; - } - - void waitForAnOpRemoval(stdx::unique_lock<Latch>& lk, OperationContext* opCtx); - -private: - int _opsInProgCount; - stdx::condition_variable _noOpsInProg; - int _opRemovalsCount; - stdx::condition_variable _waitForOpRemoval; -}; - -typedef StringMap<std::shared_ptr<BgInfo>> BgInfoMap; -typedef BgInfoMap::const_iterator BgInfoMapIterator; - -// Static data for this file is never destroyed. -Mutex& m = *(new Mutex()); -BgInfoMap& dbsInProg = *(new BgInfoMap()); -BgInfoMap& nsInProg = *(new BgInfoMap()); - -void BgInfo::recordBegin() { - ++_opsInProgCount; -} - -int BgInfo::recordEnd() { - dassert(_opsInProgCount > 0); - --_opsInProgCount; - ++_opRemovalsCount; - _waitForOpRemoval.notify_all(); - if (0 == _opsInProgCount) { - _noOpsInProg.notify_all(); - } - return _opsInProgCount; -} - -void BgInfo::awaitNoBgOps(stdx::unique_lock<Latch>& lk) { - while (_opsInProgCount > 0) - _noOpsInProg.wait(lk); -} - -void BgInfo::waitForAnOpRemoval(stdx::unique_lock<Latch>& lk, OperationContext* opCtx) { - int startOpRemovalsCount = _opRemovalsCount; - - // Wait for an index build to finish. - opCtx->waitForConditionOrInterrupt( - _waitForOpRemoval, lk, [&] { return startOpRemovalsCount != _opRemovalsCount; }); -} - -void recordBeginAndInsert(BgInfoMap& bgiMap, StringData key) { - std::shared_ptr<BgInfo>& bgInfo = bgiMap[key]; - if (!bgInfo) - bgInfo.reset(new BgInfo); - bgInfo->recordBegin(); -} - -void recordEndAndRemove(BgInfoMap& bgiMap, StringData key) { - BgInfoMapIterator iter = bgiMap.find(key); - fassert(17431, iter != bgiMap.end()); - if (0 == iter->second->recordEnd()) { - bgiMap.erase(iter); - } -} - -void awaitNoBgOps(stdx::unique_lock<Latch>& lk, BgInfoMap* bgiMap, StringData key) { - if (auto iter = bgiMap->find(key); iter != bgiMap->end() && iter->second) { - auto ptr = iter->second; // hold a reference while waiting - ptr->awaitNoBgOps(lk); - } -} - -} // namespace - -void BackgroundOperation::waitUntilAnIndexBuildFinishes(OperationContext* opCtx, StringData ns) { - stdx::unique_lock<Latch> lk(m); - if (auto iter = nsInProg.find(ns); iter != nsInProg.end() && iter->second) { - auto ptr = iter->second; // hold a reference while waiting - ptr->waitForAnOpRemoval(lk, opCtx); - } -} - -bool BackgroundOperation::inProgForDb(StringData db) { - stdx::lock_guard<Latch> lk(m); - return dbsInProg.find(db) != dbsInProg.end(); -} - -int BackgroundOperation::numInProgForDb(StringData db) { - stdx::lock_guard<Latch> lk(m); - if (auto iter = dbsInProg.find(db); iter != dbsInProg.end() && iter->second) - return iter->second->getOpsInProgCount(); - return 0; -} - -bool BackgroundOperation::inProgForNs(StringData ns) { - stdx::lock_guard<Latch> lk(m); - return nsInProg.find(ns) != nsInProg.end(); -} - -void BackgroundOperation::assertNoBgOpInProg() { - for (auto& db : dbsInProg) { - uassert(ErrorCodes::BackgroundOperationInProgressForDatabase, - str::stream() - << "cannot perform operation: a background operation is currently running for " - "database " - << db.first, - !inProgForDb(db.first)); - } -} - -void BackgroundOperation::assertNoBgOpInProgForDb(StringData db) { - uassert(ErrorCodes::BackgroundOperationInProgressForDatabase, - str::stream() - << "cannot perform operation: a background operation is currently running for " - "database " - << db, - !inProgForDb(db)); -} - -void BackgroundOperation::assertNoBgOpInProgForNs(StringData ns) { - uassert(ErrorCodes::BackgroundOperationInProgressForNamespace, - str::stream() - << "cannot perform operation: a background operation is currently running for " - "collection " - << ns, - !inProgForNs(ns)); -} - -void BackgroundOperation::awaitNoBgOpInProgForDb(StringData db) { - stdx::unique_lock<Latch> lk(m); - awaitNoBgOps(lk, &dbsInProg, db); -} - -void BackgroundOperation::awaitNoBgOpInProgForNs(StringData ns) { - stdx::unique_lock<Latch> lk(m); - awaitNoBgOps(lk, &nsInProg, ns); -} - -BackgroundOperation::BackgroundOperation(StringData ns) : _ns(ns) { - stdx::lock_guard<Latch> lk(m); - recordBeginAndInsert(dbsInProg, _ns.db()); - recordBeginAndInsert(nsInProg, _ns.ns()); -} - -BackgroundOperation::~BackgroundOperation() { - stdx::lock_guard<Latch> lk(m); - recordEndAndRemove(dbsInProg, _ns.db()); - recordEndAndRemove(nsInProg, _ns.ns()); -} - -void BackgroundOperation::dump(std::ostream& ss) { - stdx::lock_guard<Latch> lk(m); - if (nsInProg.size()) { - ss << "\n<b>Background Jobs in Progress</b>\n"; - for (BgInfoMapIterator i = nsInProg.begin(); i != nsInProg.end(); ++i) - ss << " " << i->first << '\n'; - } - for (BgInfoMapIterator i = dbsInProg.begin(); i != dbsInProg.end(); ++i) { - if (i->second->getOpsInProgCount()) - ss << "database " << i->first << ": " << i->second->getOpsInProgCount() << '\n'; - } -} - -} // namespace mongo diff --git a/src/mongo/db/background.h b/src/mongo/db/background.h deleted file mode 100644 index d64430d93b0..00000000000 --- a/src/mongo/db/background.h +++ /dev/null @@ -1,101 +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. - */ - -/* background.h - - Concurrency coordination for administrative operations. -*/ - -#pragma once - -#include <iosfwd> -#include <map> -#include <set> -#include <vector> - -#include "mongo/base/string_data.h" -#include "mongo/db/namespace_string.h" - -namespace mongo { - -class OperationContext; - -/* these are administrative operations / jobs - for a namespace running in the background, and that if in progress, - you aren't allowed to do other NamespaceDetails major manipulations - (such as dropping ns or db) even in the foreground and must - instead uassert. - - It's assumed this is not for super-high RPS things, so we don't do - anything special in the implementation here to be fast. -*/ -class BackgroundOperation { - BackgroundOperation(const BackgroundOperation&) = delete; - BackgroundOperation& operator=(const BackgroundOperation&) = delete; - -public: - static bool inProgForDb(StringData db); - static int numInProgForDb(StringData db); - static bool inProgForNs(StringData ns); - static void assertNoBgOpInProg(); - static void assertNoBgOpInProgForDb(StringData db); - static void assertNoBgOpInProgForNs(StringData ns); - static void awaitNoBgOpInProgForDb(StringData db); - static void awaitNoBgOpInProgForNs(StringData ns); - static void dump(std::ostream&); - - static bool inProgForNs(const NamespaceString& ns) { - return inProgForNs(ns.ns()); - } - static void assertNoBgOpInProgForNs(const NamespaceString& ns) { - assertNoBgOpInProgForNs(ns.ns()); - } - static void awaitNoBgOpInProgForNs(const NamespaceString& ns) { - awaitNoBgOpInProgForNs(ns.ns()); - } - - /** - * Waits until an index build on collection 'ns' finishes. If there are no index builds in - * progress, returns immediately. - * - * Note: a collection lock should not be held when calling this, as that would block index - * builds from finishing and this function ever returning. - */ - static void waitUntilAnIndexBuildFinishes(OperationContext* opCtx, StringData ns); - - /* check for in progress before instantiating */ - BackgroundOperation(StringData ns); - - virtual ~BackgroundOperation(); - -private: - NamespaceString _ns; -}; - -} // namespace mongo diff --git a/src/mongo/db/catalog/SConscript b/src/mongo/db/catalog/SConscript index d0e60f796af..6aae6707afe 100644 --- a/src/mongo/db/catalog/SConscript +++ b/src/mongo/db/catalog/SConscript @@ -243,7 +243,6 @@ env.Library( LIBDEPS=[ '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/db/audit', - '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/concurrency/write_conflict_exception', '$BUILD_DIR/mongo/db/curop', '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface', @@ -343,7 +342,6 @@ env.Library( 'index_catalog_entry', 'index_key_validate', '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/collection_index_usage_tracker', '$BUILD_DIR/mongo/db/concurrency/lock_manager', '$BUILD_DIR/mongo/db/curop', @@ -423,7 +421,6 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/db_raii', '$BUILD_DIR/mongo/db/index_builds_coordinator_interface', '$BUILD_DIR/mongo/db/query_exec', diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp index f966f0c9cb5..0cd1de8b507 100644 --- a/src/mongo/db/catalog/capped_utils.cpp +++ b/src/mongo/db/catalog/capped_utils.cpp @@ -34,7 +34,6 @@ #include "mongo/db/catalog/capped_utils.h" #include "mongo/base/error_codes.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/create_collection.h" #include "mongo/db/catalog/document_validation.h" #include "mongo/db/catalog/drop_collection.h" @@ -92,7 +91,6 @@ Status emptyCapped(OperationContext* opCtx, const NamespaceString& collectionNam << "Cannot truncate a live oplog while replicating: " << collectionName); } - BackgroundOperation::assertNoBgOpInProgForNs(collectionName.ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(collection->uuid()); WriteUnitOfWork wuow(opCtx); @@ -252,7 +250,6 @@ void convertToCapped(OperationContext* opCtx, const NamespaceString& ns, long lo uassert( ErrorCodes::NamespaceNotFound, str::stream() << "database " << dbname << " not found", db); - BackgroundOperation::assertNoBgOpInProgForNs(ns); if (Collection* coll = autoColl.getCollection()) { IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(coll->uuid()); } diff --git a/src/mongo/db/catalog/catalog_control.cpp b/src/mongo/db/catalog/catalog_control.cpp index e08cc9f4a63..02393d4929b 100644 --- a/src/mongo/db/catalog/catalog_control.cpp +++ b/src/mongo/db/catalog/catalog_control.cpp @@ -35,7 +35,6 @@ #include "mongo/db/catalog/catalog_control.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/database.h" @@ -51,7 +50,6 @@ namespace catalog { MinVisibleTimestampMap closeCatalog(OperationContext* opCtx) { invariant(opCtx->lockState()->isW()); - BackgroundOperation::assertNoBgOpInProg(); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgress(); MinVisibleTimestampMap minVisibleTimestampMap; diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 60e3a9204f7..86812cf5c0b 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -37,7 +37,6 @@ #include <memory> #include "mongo/bson/simple_bsonelement_comparator.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/client.h" @@ -327,7 +326,6 @@ Status _collModInternal(OperationContext* opCtx, // This can kill all cursors so don't allow running it while a background operation is in // progress. - BackgroundOperation::assertNoBgOpInProgForNs(nss); if (coll) { IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(coll->uuid()); } diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp index 5409e608ce3..ef94cd112da 100644 --- a/src/mongo/db/catalog/collection_impl.cpp +++ b/src/mongo/db/catalog/collection_impl.cpp @@ -39,7 +39,6 @@ #include "mongo/bson/ordering.h" #include "mongo/bson/simple_bsonelement_comparator.h" #include "mongo/bson/simple_bsonobj_comparator.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog/document_validation.h" diff --git a/src/mongo/db/catalog/database_holder_impl.cpp b/src/mongo/db/catalog/database_holder_impl.cpp index ccd202e95ba..722ecf6f9ef 100644 --- a/src/mongo/db/catalog/database_holder_impl.cpp +++ b/src/mongo/db/catalog/database_holder_impl.cpp @@ -34,7 +34,6 @@ #include "mongo/db/catalog/database_holder_impl.h" #include "mongo/db/audit.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_impl.h" #include "mongo/db/catalog/database_impl.h" diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index fb277d08ecc..b81624c803c 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -41,7 +41,6 @@ #include "mongo/base/init.h" #include "mongo/db/audit.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_catalog_helper.h" #include "mongo/db/catalog/collection_impl.h" diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 2f96e840b0b..170c51557bb 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -33,7 +33,6 @@ #include "mongo/db/catalog/drop_collection.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/uncommitted_collections.h" #include "mongo/db/client.h" @@ -256,7 +255,6 @@ Status _dropCollection(OperationContext* opCtx, WriteUnitOfWork wunit(opCtx); int numIndexes = coll->getIndexCatalog()->numIndexesTotal(opCtx); - BackgroundOperation::assertNoBgOpInProgForNs(collectionName.ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(coll->uuid()); status = systemCollectionMode == DropCollectionSystemCollectionMode::kDisallowSystemCollectionDrops diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp index b9cbb79f558..fcfbc9bd472 100644 --- a/src/mongo/db/catalog/drop_database.cpp +++ b/src/mongo/db/catalog/drop_database.cpp @@ -35,7 +35,6 @@ #include <algorithm> -#include "mongo/db/background.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/client.h" @@ -97,7 +96,6 @@ void _finishDropDatabase(OperationContext* opCtx, auto dropPendingGuard = makeGuard([db, opCtx] { db->setDropPending(opCtx, false); }); if (!abortIndexBuilds) { - BackgroundOperation::assertNoBgOpInProgForDb(dbName); IndexBuildsCoordinator::get(opCtx)->assertNoBgOpInProgForDb(dbName); } @@ -269,7 +267,6 @@ Status _dropDatabase(OperationContext* opCtx, const std::string& dbName, bool ab } if (!abortIndexBuilds) { - BackgroundOperation::assertNoBgOpInProgForNs(nss.ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, nss)->uuid()); } diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp index 0ab54ebb284..c6edd5f9786 100644 --- a/src/mongo/db/catalog/drop_indexes.cpp +++ b/src/mongo/db/catalog/drop_indexes.cpp @@ -33,7 +33,6 @@ #include "mongo/db/catalog/drop_indexes.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -429,7 +428,6 @@ Status dropIndexes(OperationContext* opCtx, } else { // The index catalog requires that no active index builders are running when dropping // indexes. - BackgroundOperation::assertNoBgOpInProgForNs(collection->ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(collectionUUID); } @@ -477,7 +475,6 @@ Status dropIndexesForApplyOps(OperationContext* opCtx, "indexes"_attr = cmdObj[kIndexFieldName].toString(false)); } - BackgroundOperation::assertNoBgOpInProgForNs(nss); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( collection->uuid()); diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index ecc3ec7b40f..ba0ffc0b8bb 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -39,7 +39,6 @@ #include "mongo/bson/simple_bsonelement_comparator.h" #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/db/audit.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/index_build_block.h" #include "mongo/db/catalog/index_catalog_entry_impl.h" diff --git a/src/mongo/db/catalog/multi_index_block.cpp b/src/mongo/db/catalog/multi_index_block.cpp index f08446efb6a..190e61577a1 100644 --- a/src/mongo/db/catalog/multi_index_block.cpp +++ b/src/mongo/db/catalog/multi_index_block.cpp @@ -284,9 +284,6 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(OperationContext* opCtx, _indexes.push_back(std::move(index)); } - if (isBackgroundBuilding()) - _backgroundOperation.reset(new BackgroundOperation(ns)); - Status status = onInit(indexInfoObjs); if (!status.isOK()) { return status; @@ -351,7 +348,7 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx, } if (MONGO_unlikely(hangAfterSettingUpIndexBuild.shouldFail())) { - // Hang the build after the BackgroundOperation and curOP info is set up. + // Hang the build after the curOP info is set up. LOGV2(20387, "Hanging index build due to failpoint 'hangAfterSettingUpIndexBuild'"); hangAfterSettingUpIndexBuild.pauseWhileSet(); } diff --git a/src/mongo/db/catalog/multi_index_block.h b/src/mongo/db/catalog/multi_index_block.h index 9a17a6c1c58..e6fa117711d 100644 --- a/src/mongo/db/catalog/multi_index_block.h +++ b/src/mongo/db/catalog/multi_index_block.h @@ -40,7 +40,6 @@ #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/collection_options.h" #include "mongo/db/catalog/index_build_block.h" #include "mongo/db/catalog/index_catalog.h" @@ -290,8 +289,6 @@ private: std::vector<IndexToBuild> _indexes; - std::unique_ptr<BackgroundOperation> _backgroundOperation; - IndexBuildMethod _method = IndexBuildMethod::kHybrid; bool _ignoreUnique = false; diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index ac0d9bcdd2d..3d376abe74d 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -33,7 +33,6 @@ #include "mongo/db/catalog/rename_collection.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/document_validation.h" @@ -121,7 +120,6 @@ Status checkSourceAndTargetNamespaces(OperationContext* opCtx, str::stream() << "Source collection " << source.ns() << " does not exist"); } - BackgroundOperation::assertNoBgOpInProgForNs(source.ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(sourceColl->uuid()); Collection* targetColl = @@ -241,7 +239,6 @@ Status renameCollectionAndDropTarget(OperationContext* opCtx, invariant(renameOpTimeFromApplyOps.isNull()); } - BackgroundOperation::assertNoBgOpInProgForNs(targetColl->ns().ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( targetColl->uuid()); @@ -509,7 +506,6 @@ Status renameBetweenDBs(OperationContext* opCtx, return {ErrorCodes::IllegalOperation, "Cannot rename collections between a replicated and an unreplicated database"}; - BackgroundOperation::assertNoBgOpInProgForNs(source.ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(sourceColl->uuid()); auto targetDB = DatabaseHolder::get(opCtx)->getDb(opCtx, target.db()); diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index c5faad444fe..2dbc05c7bd9 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -284,7 +284,6 @@ env.Library( ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/catalog/catalog_helpers', '$BUILD_DIR/mongo/db/catalog/collection_catalog_helper', '$BUILD_DIR/mongo/db/catalog/collection_query_info', @@ -418,7 +417,6 @@ env.Library( '$BUILD_DIR/mongo/db/auth/sasl_options', '$BUILD_DIR/mongo/db/auth/user', '$BUILD_DIR/mongo/db/auth/user_document_parser', - '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/catalog/catalog_control', '$BUILD_DIR/mongo/db/catalog/catalog_helpers', '$BUILD_DIR/mongo/db/catalog/collection_catalog_helper', diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 9cefe29e593..353a5fe51c3 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -30,7 +30,6 @@ #include "mongo/platform/basic.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/capped_utils.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index b3e00efef07..cb21eccb014 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -33,7 +33,6 @@ #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/privilege.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_compact.h" #include "mongo/db/catalog/database.h" diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 66a2121380a..ef1072969f9 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -36,7 +36,6 @@ #include "mongo/base/string_data.h" #include "mongo/db/auth/authorization_session.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/create_collection.h" #include "mongo/db/catalog/database.h" @@ -463,13 +462,9 @@ BSONObj runCreateIndexesOnNewCollection(OperationContext* opCtx, bool runCreateIndexesWithCoordinator(OperationContext* opCtx, const std::string& dbname, const BSONObj& cmdObj, - std::string& errmsg, BSONObjBuilder& result) { const NamespaceString ns(CommandHelpers::parseNsCollectionRequired(dbname, cmdObj)); - // Disallows drops and renames on this namespace. - BackgroundOperation backgroundOp(ns.ns()); - uassertStatusOK(userAllowedWriteNS(ns)); // Disallow users from creating new indexes on config.transactions since the sessions code @@ -726,7 +721,7 @@ public: bool shouldLogMessageOnAlreadyBuildingError = true; while (true) { try { - return runCreateIndexesWithCoordinator(opCtx, dbname, cmdObj, errmsg, result); + return runCreateIndexesWithCoordinator(opCtx, dbname, cmdObj, result); } catch (const DBException& ex) { hangAfterIndexBuildAbort.pauseWhileSet(); // We can only wait for an existing index build to finish if we are able to release @@ -760,7 +755,7 @@ public: // This is a bit racy since we are not holding a lock across discovering an // in-progress build and starting to listen for completion. It is good enough, // however: we can only wait longer than needed, not less. - BackgroundOperation::waitUntilAnIndexBuildFinishes(opCtx, nss.ns()); + IndexBuildsCoordinator::get(opCtx)->waitUntilAnIndexBuildFinishes(opCtx); } } } diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp index 49df53c4224..e543e543de3 100644 --- a/src/mongo/db/commands/dbcommands.cpp +++ b/src/mongo/db/commands/dbcommands.cpp @@ -45,7 +45,6 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/auth/user_management_commands_parser.h" #include "mongo/db/auth/user_name.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/coll_mod.h" #include "mongo/db/catalog/create_collection.h" #include "mongo/db/catalog/database_holder.h" diff --git a/src/mongo/db/commands/dbcommands_d.cpp b/src/mongo/db/commands/dbcommands_d.cpp index 2405659d110..78eb49487c7 100644 --- a/src/mongo/db/commands/dbcommands_d.cpp +++ b/src/mongo/db/commands/dbcommands_d.cpp @@ -45,7 +45,6 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/auth/user_management_commands_parser.h" #include "mongo/db/auth/user_name.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/coll_mod.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/create_collection.h" diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index bb99ba3cf32..78e7413c00b 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -34,7 +34,6 @@ #include <string> #include <vector> -#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/drop_indexes.h" @@ -150,7 +149,6 @@ public: uasserted(ErrorCodes::NamespaceNotFound, "collection does not exist"); } - BackgroundOperation::assertNoBgOpInProgForNs(toReIndexNss.ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( collection->uuid()); diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index e478a6bca44..d5b87234cba 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -174,7 +174,6 @@ public: } } - BackgroundOperation::assertNoBgOpInProgForNs(fullNs.ns()); IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection( collection->uuid()); diff --git a/src/mongo/db/cursor_manager.cpp b/src/mongo/db/cursor_manager.cpp index 87b3a766fea..a02412fabe4 100644 --- a/src/mongo/db/cursor_manager.cpp +++ b/src/mongo/db/cursor_manager.cpp @@ -39,7 +39,6 @@ #include "mongo/base/init.h" #include "mongo/db/audit.h" #include "mongo/db/auth/authorization_session.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 7053ae4611d..f45430301f3 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -1380,8 +1380,14 @@ void IndexBuildsCoordinator::awaitNoBgOpInProgForDb(OperationContext* opCtx, Str _awaitNoBgOpInProgForDb(lk, opCtx, db); } -void IndexBuildsCoordinator::onReplicaSetReconfig() { - // TODO: not yet implemented. +void IndexBuildsCoordinator::waitUntilAnIndexBuildFinishes(OperationContext* opCtx) { + stdx::unique_lock<Latch> lk(_mutex); + if (_allIndexBuilds.empty()) { + return; + } + const auto generation = _indexBuildsCompletedGen; + opCtx->waitForConditionOrInterrupt( + _indexBuildsCondVar, lk, [&] { return _indexBuildsCompletedGen != generation; }); } void IndexBuildsCoordinator::createIndexes(OperationContext* opCtx, @@ -1568,6 +1574,7 @@ void IndexBuildsCoordinator::_unregisterIndexBuild( LOGV2(4656004, "Unregistering index build", "buildUUID"_attr = replIndexBuildState->buildUUID); _indexBuildsManager.unregisterIndexBuild(replIndexBuildState->buildUUID); + _indexBuildsCompletedGen++; _indexBuildsCondVar.notify_all(); } diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h index 02c2a5e337a..fa843e73a1c 100644 --- a/src/mongo/db/index_builds_coordinator.h +++ b/src/mongo/db/index_builds_coordinator.h @@ -303,11 +303,6 @@ public: const CommitQuorumOptions& newCommitQuorum) = 0; /** - * TODO: This is not yet implemented. - */ - void recoverIndexBuilds(); - - /** * Returns the number of index builds that are running on the specified database. */ int numInProgForDb(StringData db) const; @@ -359,13 +354,10 @@ public: void awaitNoBgOpInProgForDb(OperationContext* opCtx, StringData db); /** - * Called by the replication coordinator when a replica set reconfig occurs, which could affect - * any index build to make their commit quorum unachievable. - * - * Checks if the commit quorum is still satisfiable for each index build, if it is no longer - * satisfiable, then those index builds are aborted. + * Waits until an index build completes. If there are no index builds in progress, returns + * immediately. */ - void onReplicaSetReconfig(); + void waitUntilAnIndexBuildFinishes(OperationContext* opCtx); // // Helper functions for creating indexes that do not have to be managed by the @@ -734,6 +726,7 @@ protected: void _awaitNoBgOpInProgForDb(stdx::unique_lock<Latch>& lk, OperationContext* opCtx, StringData db); + // Protects the below state. mutable Mutex _mutex = MONGO_MAKE_LATCH("IndexBuildsCoordinator::_mutex"); @@ -743,6 +736,10 @@ protected: // Waiters are notified whenever one of the three maps above has something added or removed. stdx::condition_variable _indexBuildsCondVar; + // Generation counter of completed index builds. Used in conjuction with the condition variable + // to receive notifications when an index build completes. + uint32_t _indexBuildsCompletedGen; + // Handles actually building the indexes. IndexBuildsManager _indexBuildsManager; diff --git a/src/mongo/db/pipeline/SConscript b/src/mongo/db/pipeline/SConscript index e8b781486d1..8c53be9630b 100644 --- a/src/mongo/db/pipeline/SConscript +++ b/src/mongo/db/pipeline/SConscript @@ -275,7 +275,6 @@ pipelineEnv.Library( 'granularity_rounder', ], LIBDEPS_PRIVATE=[ - '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/commands/test_commands_enabled', '$BUILD_DIR/mongo/rpc/command_status', ] diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp index b7a4f3bd189..093ede06089 100644 --- a/src/mongo/db/pipeline/document_source_out.cpp +++ b/src/mongo/db/pipeline/document_source_out.cpp @@ -35,7 +35,6 @@ #include <fmt/format.h> -#include "mongo/db/background.h" #include "mongo/db/curop_failpoint_helpers.h" #include "mongo/db/ops/write_ops.h" #include "mongo/db/pipeline/document_path_support.h" diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index c662a63fef6..789eed1dc90 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -40,7 +40,6 @@ #include "mongo/base/string_data.h" #include "mongo/bson/bson_validate.h" #include "mongo/bson/bsonobjbuilder.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_validation.h" @@ -197,7 +196,6 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std: LOGV2(21029, "repairDatabase", "db"_attr = dbName); - BackgroundOperation::assertNoBgOpInProgForDb(dbName); opCtx->checkForInterrupt(); diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index 21dd50fe804..1d3d3e4a28f 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -47,7 +47,6 @@ env.Library( 'repl_settings', 'timestamp_block', '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/catalog/catalog_helpers', '$BUILD_DIR/mongo/db/catalog/database_holder', '$BUILD_DIR/mongo/db/catalog/index_build_oplog_entry', @@ -97,7 +96,6 @@ env.Library( 'oplog_interface_remote', 'repl_coordinator_interface', '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/concurrency/lock_manager', '$BUILD_DIR/mongo/db/db_raii', '$BUILD_DIR/mongo/db/dbhelpers', diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp index f234553415a..0027f545115 100644 --- a/src/mongo/db/repl/apply_ops.cpp +++ b/src/mongo/db/repl/apply_ops.cpp @@ -34,7 +34,6 @@ #include "mongo/db/repl/apply_ops.h" #include "mongo/bson/util/bson_extract.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 0d028f37d2a..7328e8058f9 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -45,7 +45,6 @@ #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/privilege.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/capped_utils.h" #include "mongo/db/catalog/coll_mod.h" #include "mongo/db/catalog/collection.h" @@ -1573,7 +1572,6 @@ Status applyCommand_inlock(OperationContext* opCtx, Lock::TempRelease release(opCtx->lockState()); - BackgroundOperation::awaitNoBgOpInProgForDb(nss.db()); IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(opCtx, nss.db()); opCtx->recoveryUnit()->abandonSnapshot(); opCtx->checkForInterrupt(); @@ -1617,7 +1615,6 @@ Status applyCommand_inlock(OperationContext* opCtx, "command"_attr = redact(o), "namespace"_attr = ns); } - BackgroundOperation::awaitNoBgOpInProgForNs(ns); IndexBuildsCoordinator::get(opCtx)->awaitNoIndexBuildInProgressForCollection( opCtx, swUUID.get()); diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 4b56ca6026e..d2011f8a1ef 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -3561,9 +3561,6 @@ void ReplicationCoordinatorImpl::_finishReplSetReconfig(OperationContext* opCtx, lk.unlock(); _performPostMemberStateUpdateAction(action); - - // Inform the index builds coordinator of the replica set reconfig. - IndexBuildsCoordinator::get(opCtx)->onReplicaSetReconfig(); } Status ReplicationCoordinatorImpl::awaitConfigCommitment(OperationContext* opCtx, diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp index 64c241cddcb..a08e0ef3dab 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp @@ -842,9 +842,6 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigFinish( lk.unlock(); _performPostMemberStateUpdateAction(action); - - // Inform the index builds coordinator of the replica set reconfig. - IndexBuildsCoordinator::get(opCtx.get())->onReplicaSetReconfig(); } void ReplicationCoordinatorImpl::_trackHeartbeatHandle_inlock( diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp index 94f66713b4c..9c13c0e0fe2 100644 --- a/src/mongo/db/repl/rollback_impl.cpp +++ b/src/mongo/db/repl/rollback_impl.cpp @@ -37,7 +37,6 @@ #include <fmt/format.h> #include "mongo/bson/util/bson_extract.h" -#include "mongo/db/background.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/commands.h" @@ -361,19 +360,15 @@ void RollbackImpl::_stopAndWaitForIndexBuilds(OperationContext* opCtx) { std::vector<StringData> dbNames(dbs.begin(), dbs.end()); LOGV2(21595, "Waiting for all background operations to complete before starting rollback"); for (auto db : dbNames) { - auto numInProg = BackgroundOperation::numInProgForDb(db); - auto numInProgInCoordinator = IndexBuildsCoordinator::get(opCtx)->numInProgForDb(db); - if (numInProg > 0 || numInProgInCoordinator > 0) { - LOGV2_DEBUG( - 21596, - 1, - "Waiting for {numBackgroundOperationsInProgress} " - "background operations to complete on database '{db}'", - "Waiting for background operations to complete", - "numBackgroundOperationsInProgress"_attr = - (numInProg > numInProgInCoordinator ? numInProg : numInProgInCoordinator), - "db"_attr = db); - BackgroundOperation::awaitNoBgOpInProgForDb(db); + auto numInProg = IndexBuildsCoordinator::get(opCtx)->numInProgForDb(db); + if (numInProg > 0) { + LOGV2_DEBUG(21596, + 1, + "Waiting for {numBackgroundOperationsInProgress} " + "background operations to complete on database '{db}'", + "Waiting for background operations to complete", + "numBackgroundOperationsInProgress"_attr = numInProg, + "db"_attr = db); IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(opCtx, db); } } diff --git a/src/mongo/db/repl/transaction_oplog_application.cpp b/src/mongo/db/repl/transaction_oplog_application.cpp index 8608926919c..c500deb93ac 100644 --- a/src/mongo/db/repl/transaction_oplog_application.cpp +++ b/src/mongo/db/repl/transaction_oplog_application.cpp @@ -33,7 +33,6 @@ #include "mongo/db/repl/transaction_oplog_application.h" -#include "mongo/db/background.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/commands/txn_cmds_gen.h" #include "mongo/db/concurrency/write_conflict_exception.h" |