diff options
| author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2022-09-21 08:33:16 +0200 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-21 15:00:29 +0000 |
| commit | 5274f1afdb125e6415d13892d6f8a58a8dba66a3 (patch) | |
| tree | 0466a9e1543ae3626d0564a9e537d7178c753985 /src/mongo | |
| parent | 5272f5854d1954820e859ebbbaf0b030e80dc32c (diff) | |
| download | mongo-5274f1afdb125e6415d13892d6f8a58a8dba66a3.tar.gz | |
SERVER-69435 Cleanup includes and libraries
General cleanup in preparation for the larger incoming change
Diffstat (limited to 'src/mongo')
28 files changed, 88 insertions, 220 deletions
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 420eb2ef377..4749e7603a6 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -27,24 +27,19 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - #include <boost/optional.hpp> #include "mongo/base/status_with.h" #include "mongo/bson/bsonobj.h" #include "mongo/bson/bsonobjbuilder.h" -#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/document_validation.h" +#include "mongo/db/catalog_raii.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/commands/update_metrics.h" #include "mongo/db/concurrency/exception_util.h" #include "mongo/db/curop_failpoint_helpers.h" -#include "mongo/db/db_raii.h" #include "mongo/db/exec/update_stage.h" -#include "mongo/db/exec/working_set_common.h" #include "mongo/db/fle_crud.h" #include "mongo/db/matcher/extensions_callback_real.h" #include "mongo/db/namespace_string.h" @@ -65,7 +60,6 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/operation_sharding_state.h" -#include "mongo/db/server_options.h" #include "mongo/db/stats/counters.h" #include "mongo/db/stats/resource_consumption_metrics.h" #include "mongo/db/stats/top.h" @@ -76,11 +70,9 @@ #include "mongo/db/write_concern.h" #include "mongo/logv2/log.h" #include "mongo/util/log_and_backoff.h" -#include "mongo/util/scopeguard.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand - namespace mongo { namespace { @@ -222,13 +214,13 @@ write_ops::FindAndModifyCommandReply buildResponse(const PlanExecutor* exec, return result; } -void assertCanWrite_inlock(OperationContext* opCtx, const NamespaceString& nsString) { +void assertCanWrite_inlock(OperationContext* opCtx, const NamespaceString& nss) { uassert(ErrorCodes::NotWritablePrimary, str::stream() << "Not primary while running findAndModify command on collection " - << nsString.ns(), - repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, nsString)); + << nss.ns(), + repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, nss)); - CollectionShardingState::get(opCtx, nsString)->checkShardVersionOrThrow(opCtx); + CollectionShardingState::get(opCtx, nss)->checkShardVersionOrThrow(opCtx); } void recordStatsForTopCommand(OperationContext* opCtx) { @@ -559,28 +551,28 @@ void CmdFindAndModify::Invocation::explain(OperationContext* opCtx, ExplainOptions::Verbosity verbosity, rpc::ReplyBuilderInterface* result) { - const BSONObj& cmdObj = this->request().toBSON(BSONObj() /* commandPassthroughFields */); - validate(this->request()); + validate(request()); + const BSONObj& cmdObj = request().toBSON(BSONObj() /* commandPassthroughFields */); auto requestAndMsg = [&]() { - if (this->request().getEncryptionInformation().has_value() && - !this->request().getEncryptionInformation()->getCrudProcessed().get_value_or(false)) { - return processFLEFindAndModifyExplainMongod(opCtx, this->request()); + if (request().getEncryptionInformation() && + !request().getEncryptionInformation()->getCrudProcessed().value_or(false)) { + return processFLEFindAndModifyExplainMongod(opCtx, request()); } else { - return std::pair{this->request(), OpMsgRequest()}; + return std::pair{request(), OpMsgRequest()}; } }(); auto request = requestAndMsg.first; - const NamespaceString& nsString = request.getNamespace(); - uassertStatusOK(userAllowedWriteNS(opCtx, nsString)); + const NamespaceString& nss = request.getNamespace(); + uassertStatusOK(userAllowedWriteNS(opCtx, nss)); auto const curOp = CurOp::get(opCtx); OpDebug* const opDebug = &curOp->debug(); const std::string dbName = request.getDbName().toString(); if (request.getRemove().value_or(false)) { auto deleteRequest = DeleteRequest{}; - deleteRequest.setNsString(nsString); + deleteRequest.setNsString(nss); const bool isExplain = true; makeDeleteRequest(opCtx, request, isExplain, &deleteRequest); @@ -589,12 +581,12 @@ void CmdFindAndModify::Invocation::explain(OperationContext* opCtx, // Explain calls of the findAndModify command are read-only, but we take write // locks so that the timing information is more accurate. - AutoGetCollection collection(opCtx, nsString, MODE_IX); + AutoGetCollection collection(opCtx, nss, MODE_IX); uassert(ErrorCodes::NamespaceNotFound, str::stream() << "database " << dbName << " does not exist", collection.getDb()); - CollectionShardingState::get(opCtx, nsString)->checkShardVersionOrThrow(opCtx); + CollectionShardingState::get(opCtx, nss)->checkShardVersionOrThrow(opCtx); const auto exec = uassertStatusOK( getExecutorDelete(opDebug, &collection.getCollection(), &parsedDelete, verbosity)); @@ -604,7 +596,7 @@ void CmdFindAndModify::Invocation::explain(OperationContext* opCtx, exec.get(), collection.getCollection(), verbosity, BSONObj(), cmdObj, &bodyBuilder); } else { auto updateRequest = UpdateRequest(); - updateRequest.setNamespaceString(nsString); + updateRequest.setNamespaceString(nss); makeUpdateRequest(opCtx, request, verbosity, &updateRequest); const ExtensionsCallbackReal extensionsCallback(opCtx, &updateRequest.getNamespaceString()); @@ -613,12 +605,12 @@ void CmdFindAndModify::Invocation::explain(OperationContext* opCtx, // Explain calls of the findAndModify command are read-only, but we take write // locks so that the timing information is more accurate. - AutoGetCollection collection(opCtx, nsString, MODE_IX); + AutoGetCollection collection(opCtx, nss, MODE_IX); uassert(ErrorCodes::NamespaceNotFound, str::stream() << "database " << dbName << " does not exist", collection.getDb()); - CollectionShardingState::get(opCtx, nsString)->checkShardVersionOrThrow(opCtx); + CollectionShardingState::get(opCtx, nss)->checkShardVersionOrThrow(opCtx); const auto exec = uassertStatusOK( getExecutorUpdate(opDebug, &collection.getCollection(), &parsedUpdate, verbosity)); diff --git a/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp b/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp index 3508798eea7..63a92b848a5 100644 --- a/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp +++ b/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp @@ -27,32 +27,26 @@ * it in the license file. */ -#include "mongo/platform/basic.h" - -#include "mongo/db/commands/internal_rename_if_options_and_indexes_match_gen.h" - #include "mongo/db/auth/authorization_session.h" #include "mongo/db/catalog/catalog_helper.h" #include "mongo/db/catalog/rename_collection.h" #include "mongo/db/commands.h" +#include "mongo/db/commands/internal_rename_if_options_and_indexes_match_gen.h" #include "mongo/db/db_raii.h" #include "mongo/db/s/collection_sharding_state.h" -#include "mongo/db/s/database_sharding_state.h" #include "mongo/db/s/ddl_lock_manager.h" namespace mongo { -MONGO_FAIL_POINT_DEFINE(blockBeforeInternalRenameIfOptionsAndIndexesMatch); - namespace { +MONGO_FAIL_POINT_DEFINE(blockBeforeInternalRenameIfOptionsAndIndexesMatch); + bool isCollectionSharded(OperationContext* opCtx, const NamespaceString& nss) { AutoGetCollectionForRead lock(opCtx, nss); return opCtx->writesAreReplicated() && CollectionShardingState::get(opCtx, nss)->getCollectionDescription(opCtx).isSharded(); } -} // namespace - /** * Rename a collection while checking collection option and indexes. */ @@ -165,4 +159,6 @@ public: } } internalRenameIfOptionsAndIndexesMatchCmd; + +} // namespace } // namespace mongo diff --git a/src/mongo/db/exec/update_stage.cpp b/src/mongo/db/exec/update_stage.cpp index a4783813bd4..6625911054b 100644 --- a/src/mongo/db/exec/update_stage.cpp +++ b/src/mongo/db/exec/update_stage.cpp @@ -27,58 +27,35 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - #include "mongo/db/exec/update_stage.h" #include <algorithm> -#include <memory> #include "mongo/base/status_with.h" -#include "mongo/bson/bson_comparator_interface_base.h" #include "mongo/bson/mutable/algorithm.h" #include "mongo/db/catalog/document_validation.h" -#include "mongo/db/exec/scoped_timer.h" -#include "mongo/db/exec/shard_filterer_impl.h" -#include "mongo/db/exec/working_set_common.h" -#include "mongo/db/exec/write_stage_common.h" #include "mongo/db/internal_transactions_feature_flag_gen.h" -#include "mongo/db/op_observer/op_observer.h" #include "mongo/db/query/collection_query_info.h" -#include "mongo/db/query/explain.h" #include "mongo/db/query/plan_executor_impl.h" #include "mongo/db/repl/replication_coordinator.h" -#include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/operation_sharding_state.h" -#include "mongo/db/s/sharding_state.h" -#include "mongo/db/s/sharding_write_router.h" -#include "mongo/db/service_context.h" -#include "mongo/db/storage/duplicate_key_error_info.h" #include "mongo/db/update/path_support.h" -#include "mongo/db/update/storage_validation.h" #include "mongo/logv2/log.h" #include "mongo/s/grid.h" -#include "mongo/s/shard_key_pattern.h" #include "mongo/s/would_change_owning_shard_exception.h" #include "mongo/util/assert_util.h" #include "mongo/util/scopeguard.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kWrite - namespace mongo { -MONGO_FAIL_POINT_DEFINE(hangBeforeThrowWouldChangeOwningShard); - -using std::string; -using std::unique_ptr; -using std::vector; - namespace mb = mutablebson; namespace { +MONGO_FAIL_POINT_DEFINE(hangBeforeThrowWouldChangeOwningShard); + const char idFieldName[] = "_id"; const FieldRef idFieldRef(idFieldName); @@ -112,6 +89,7 @@ CollectionUpdateArgs::StoreDocOption getStoreDocMode(const UpdateRequest& update invariant(!updateRequest.shouldReturnAnyDocs()); return CollectionUpdateArgs::StoreDocOption::None; } + } // namespace // Public constructor. @@ -212,7 +190,7 @@ BSONObj UpdateStage::transformAndUpdate(const Snapshotted<BSONObj>& oldObj, dassert(cq); verify(cq->root()->matchesBSON(oldObj.value(), &matchDetails)); - string matchedField; + std::string matchedField; if (matchDetails.hasElemMatchKey()) matchedField = matchDetails.elemMatchKey(); @@ -252,9 +230,7 @@ BSONObj UpdateStage::transformAndUpdate(const Snapshotted<BSONObj>& oldObj, } if (docWasModified) { - // Prepare to write back the modified document - RecordId newRecordId; CollectionUpdateArgs args; @@ -680,9 +656,9 @@ void UpdateStage::doRestoreStateRequiresCollection() { _preWriteFilter.restoreState(); } -unique_ptr<PlanStageStats> UpdateStage::getStats() { +std::unique_ptr<PlanStageStats> UpdateStage::getStats() { _commonStats.isEOF = isEOF(); - unique_ptr<PlanStageStats> ret = std::make_unique<PlanStageStats>(_commonStats, STAGE_UPDATE); + auto ret = std::make_unique<PlanStageStats>(_commonStats, STAGE_UPDATE); ret->specific = std::make_unique<UpdateStats>(_specificStats); ret->children.emplace_back(child()->getStats()); return ret; @@ -697,7 +673,6 @@ void UpdateStage::prepareToRetryWSM(WorkingSetID idToRetry, WorkingSetID* out) { *out = WorkingSet::INVALID_ID; } - void UpdateStage::_checkRestrictionsOnUpdatingShardKeyAreNotViolated( const ScopedCollectionDescription& collDesc, const FieldRefSet& shardKeyPaths) { // We do not allow modifying either the current shard key value or new shard key value (if @@ -738,7 +713,6 @@ void UpdateStage::_checkRestrictionsOnUpdatingShardKeyAreNotViolated( } } - bool UpdateStage::wasReshardingKeyUpdated(const ShardingWriteRouter& shardingWriteRouter, const ScopedCollectionDescription& collDesc, const BSONObj& newObj, @@ -772,7 +746,7 @@ bool UpdateStage::checkUpdateChangesShardKeyFields(const boost::optional<BSONObj const Snapshotted<BSONObj>& oldObj) { ShardingWriteRouter shardingWriteRouter( opCtx(), collection()->ns(), Grid::get(opCtx())->catalogCache()); - auto css = shardingWriteRouter.getCollectionShardingState(); + auto* const css = shardingWriteRouter.getCss(); // css can be null when this is a config server. if (css == nullptr) { @@ -804,7 +778,7 @@ bool UpdateStage::wasExistingShardKeyUpdated(const ShardingWriteRouter& sharding const ScopedCollectionDescription& collDesc, const BSONObj& newObj, const Snapshotted<BSONObj>& oldObj) { - const auto css = shardingWriteRouter.getCollectionShardingState(); + auto* const css = shardingWriteRouter.getCss(); const ShardKeyPattern& shardKeyPattern = collDesc.getShardKeyPattern(); auto oldShardKey = shardKeyPattern.extractShardKeyFromDoc(oldObj.value()); diff --git a/src/mongo/db/exec/update_stage.h b/src/mongo/db/exec/update_stage.h index f6070310731..a8acea04acc 100644 --- a/src/mongo/db/exec/update_stage.h +++ b/src/mongo/db/exec/update_stage.h @@ -29,23 +29,17 @@ #pragma once - #include "mongo/db/catalog/collection.h" #include "mongo/db/exec/requires_collection_stage.h" #include "mongo/db/exec/write_stage_common.h" -#include "mongo/db/jsobj.h" -#include "mongo/db/ops/parsed_update.h" #include "mongo/db/ops/update_request.h" -#include "mongo/db/ops/update_result.h" -#include "mongo/db/s/scoped_collection_metadata.h" +#include "mongo/db/s/sharding_write_router.h" #include "mongo/db/update/update_driver.h" namespace mongo { -class OperationContext; class OpDebug; struct PlanSummaryStats; -class ShardingWriteRouter; struct UpdateStageParams { using DocumentCounter = std::function<size_t(const BSONObj&)>; diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp index 15eae67bdd8..80ccc91c559 100644 --- a/src/mongo/db/ops/write_ops_exec.cpp +++ b/src/mongo/db/ops/write_ops_exec.cpp @@ -27,13 +27,7 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - -#include <memory> - -#include "mongo/base/checked_cast.h" -#include "mongo/db/audit.h" +#include "mongo/db/ops/write_ops_exec.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/catalog/clustered_collection_util.h" #include "mongo/db/catalog/collection_operation_source.h" @@ -59,7 +53,6 @@ #include "mongo/db/ops/parsed_delete.h" #include "mongo/db/ops/parsed_update.h" #include "mongo/db/ops/update_request.h" -#include "mongo/db/ops/write_ops_exec.h" #include "mongo/db/ops/write_ops_gen.h" #include "mongo/db/ops/write_ops_retryability.h" #include "mongo/db/pipeline/expression_context.h" @@ -74,7 +67,6 @@ #include "mongo/db/repl/tenant_migration_decoration.h" #include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/operation_sharding_state.h" -#include "mongo/db/s/sharding_state.h" #include "mongo/db/stats/counters.h" #include "mongo/db/stats/server_write_concern_metrics.h" #include "mongo/db/stats/top.h" @@ -89,15 +81,12 @@ #include "mongo/db/update/update_oplog_entry_serialization.h" #include "mongo/db/write_concern.h" #include "mongo/logv2/log.h" -#include "mongo/rpc/get_status_from_command_result.h" -#include "mongo/s/would_change_owning_shard_exception.h" #include "mongo/util/fail_point.h" #include "mongo/util/log_and_backoff.h" #include "mongo/util/scopeguard.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kWrite - namespace mongo::write_ops_exec { // Convention in this file: generic helpers go in the anonymous namespace. Helpers that are for a @@ -225,13 +214,13 @@ private: repl::OpTime _opTimeAtLastOpStart; }; -void assertCanWrite_inlock(OperationContext* opCtx, const NamespaceString& ns) { +void assertCanWrite_inlock(OperationContext* opCtx, const NamespaceString& nss) { uassert(ErrorCodes::PrimarySteppedDown, - str::stream() << "Not primary while writing to " << ns.ns(), + str::stream() << "Not primary while writing to " << nss.ns(), repl::ReplicationCoordinator::get(opCtx->getServiceContext()) - ->canAcceptWritesFor(opCtx, ns)); + ->canAcceptWritesFor(opCtx, nss)); - CollectionShardingState::get(opCtx, ns)->checkShardVersionOrThrow(opCtx); + CollectionShardingState::get(opCtx, nss)->checkShardVersionOrThrow(opCtx); } void makeCollection(OperationContext* opCtx, const NamespaceString& ns) { diff --git a/src/mongo/db/query/shard_filterer_factory_impl.cpp b/src/mongo/db/query/shard_filterer_factory_impl.cpp index 0db775c411e..f3d7c1d5945 100644 --- a/src/mongo/db/query/shard_filterer_factory_impl.cpp +++ b/src/mongo/db/query/shard_filterer_factory_impl.cpp @@ -27,10 +27,9 @@ * it in the license file. */ -#include "mongo/platform/basic.h" +#include "mongo/db/query/shard_filterer_factory_impl.h" #include "mongo/db/exec/shard_filterer_impl.h" -#include "mongo/db/query/shard_filterer_factory_impl.h" #include "mongo/db/s/collection_sharding_state.h" namespace mongo { @@ -41,4 +40,5 @@ std::unique_ptr<ShardFilterer> ShardFiltererFactoryImpl::makeShardFilterer( return std::make_unique<ShardFiltererImpl>(css->getOwnershipFilter( opCtx, CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup)); } + } // namespace mongo diff --git a/src/mongo/db/query/shard_filterer_factory_impl.h b/src/mongo/db/query/shard_filterer_factory_impl.h index 957b8154dba..54040fcd856 100644 --- a/src/mongo/db/query/shard_filterer_factory_impl.h +++ b/src/mongo/db/query/shard_filterer_factory_impl.h @@ -27,8 +27,6 @@ * it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/db/catalog/collection.h" #include "mongo/db/query/shard_filterer_factory_interface.h" @@ -46,4 +44,5 @@ public: private: const CollectionPtr& _collection; }; + } // namespace mongo diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 30ddd62497d..3d001bf792a 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -285,12 +285,11 @@ env.Library( 'forwardable_operation_metadata.cpp', 'forwardable_operation_metadata.idl', ], - LIBDEPS=[ - '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/s/grid', - ], LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/db/auth/auth', + '$BUILD_DIR/mongo/db/server_base', '$BUILD_DIR/mongo/db/write_block_bypass', + '$BUILD_DIR/mongo/rpc/metadata_impersonated_user', ], ) diff --git a/src/mongo/db/s/active_migrations_registry.cpp b/src/mongo/db/s/active_migrations_registry.cpp index c8c0343eda0..227e0148478 100644 --- a/src/mongo/db/s/active_migrations_registry.cpp +++ b/src/mongo/db/s/active_migrations_registry.cpp @@ -27,9 +27,6 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - #include "mongo/db/s/active_migrations_registry.h" #include "mongo/db/catalog_raii.h" @@ -42,7 +39,6 @@ #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kShardingMigration - namespace mongo { namespace { diff --git a/src/mongo/db/s/cleanup_orphaned_cmd.cpp b/src/mongo/db/s/cleanup_orphaned_cmd.cpp index 431a5b8000d..e3f2e4779e0 100644 --- a/src/mongo/db/s/cleanup_orphaned_cmd.cpp +++ b/src/mongo/db/s/cleanup_orphaned_cmd.cpp @@ -27,22 +27,14 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - #include <boost/optional.hpp> -#include <string> #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/authorization_session.h" -#include "mongo/db/auth/privilege.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/commands.h" #include "mongo/db/field_parser.h" -#include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" -#include "mongo/db/range_arithmetic.h" -#include "mongo/db/s/chunk_move_write_concern_options.h" #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/db/s/migration_util.h" #include "mongo/db/s/shard_filtering_metadata_refresh.h" @@ -50,11 +42,9 @@ #include "mongo/db/s/sharding_state.h" #include "mongo/db/service_context.h" #include "mongo/logv2/log.h" -#include "mongo/s/request_types/migration_secondary_throttle_options.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand - namespace mongo { namespace { diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index 04f8280fd3c..f112f54ada8 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -27,26 +27,19 @@ * it in the license file. */ - #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/base/checked_cast.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/global_settings.h" -#include "mongo/db/repl/primary_only_service.h" #include "mongo/db/s/operation_sharding_state.h" -#include "mongo/db/s/resharding/resharding_donor_recipient_common.h" -#include "mongo/db/s/sharding_data_transform_metrics.h" #include "mongo/db/s/sharding_runtime_d_params_gen.h" #include "mongo/db/s/sharding_state.h" #include "mongo/logv2/log.h" -#include "mongo/s/sharding_feature_flags_gen.h" -#include "mongo/s/type_collection_common_types_gen.h" #include "mongo/util/duration.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - namespace mongo { namespace { diff --git a/src/mongo/db/s/collection_sharding_runtime.h b/src/mongo/db/s/collection_sharding_runtime.h index f09f6facc40..a66150f2544 100644 --- a/src/mongo/db/s/collection_sharding_runtime.h +++ b/src/mongo/db/s/collection_sharding_runtime.h @@ -30,12 +30,10 @@ #pragma once #include "mongo/bson/bsonobj.h" -#include "mongo/db/namespace_string.h" #include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/metadata_manager.h" #include "mongo/db/s/sharding_migration_critical_section.h" #include "mongo/db/s/sharding_state_lock.h" -#include "mongo/platform/atomic_word.h" #include "mongo/s/global_index_cache.h" #include "mongo/util/cancellation.h" #include "mongo/util/decorable.h" @@ -73,12 +71,16 @@ public: */ static CollectionShardingRuntime* get(CollectionShardingState* css); + const NamespaceString& nss() const override { + return _nss; + } + + ScopedCollectionDescription getCollectionDescription(OperationContext* opCtx) override; + ScopedCollectionFilter getOwnershipFilter(OperationContext* opCtx, OrphanCleanupPolicy orphanCleanupPolicy, bool supportNonVersionedOperations) override; - ScopedCollectionDescription getCollectionDescription(OperationContext* opCtx) override; - void checkShardVersionOrThrow(OperationContext* opCtx) override; void appendShardVersion(BSONObjBuilder* builder) override; diff --git a/src/mongo/db/s/collection_sharding_state.cpp b/src/mongo/db/s/collection_sharding_state.cpp index d3a14d0d005..17a9127e70f 100644 --- a/src/mongo/db/s/collection_sharding_state.cpp +++ b/src/mongo/db/s/collection_sharding_state.cpp @@ -27,19 +27,13 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - #include "mongo/db/s/collection_sharding_state.h" -#include "mongo/db/repl/read_concern_args.h" -#include "mongo/s/stale_exception.h" -#include "mongo/util/fail_point.h" +#include "mongo/logv2/log.h" #include "mongo/util/string_map.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - namespace mongo { namespace { diff --git a/src/mongo/db/s/collection_sharding_state.h b/src/mongo/db/s/collection_sharding_state.h index 575ccb85f2f..bc68c9417d1 100644 --- a/src/mongo/db/s/collection_sharding_state.h +++ b/src/mongo/db/s/collection_sharding_state.h @@ -31,8 +31,7 @@ #include <vector> -#include "mongo/db/logical_time.h" -#include "mongo/db/namespace_string.h" +#include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/s/scoped_collection_metadata.h" namespace mongo { @@ -97,6 +96,11 @@ public: static void appendInfoForServerStatus(OperationContext* opCtx, BSONObjBuilder* builder); /** + * Returns the namespace to which this CSS corresponds. + */ + virtual const NamespaceString& nss() const = 0; + + /** * If the shard currently doesn't know whether the collection is sharded or not, it will throw a * StaleConfig exception. * diff --git a/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp index 6251ba8d786..a8a0142b178 100644 --- a/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp +++ b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp @@ -27,14 +27,8 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - #include "mongo/db/s/collection_sharding_state_factory_standalone.h" -#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - - namespace mongo { namespace { @@ -54,14 +48,22 @@ const auto kUnshardedCollection = std::make_shared<UnshardedCollection>(); class CollectionShardingStateStandalone final : public CollectionShardingState { public: + CollectionShardingStateStandalone(const NamespaceString& nss) : _nss(nss) {} + + const NamespaceString& nss() const override { + return _nss; + } + ScopedCollectionDescription getCollectionDescription(OperationContext* opCtx) override { return {kUnshardedCollection}; } + ScopedCollectionFilter getOwnershipFilter(OperationContext*, OrphanCleanupPolicy orphanCleanupPolicy, bool supportNonVersionedOperations) override { return {kUnshardedCollection}; } + void checkShardVersionOrThrow(OperationContext*) override {} void appendShardVersion(BSONObjBuilder* builder) override {} @@ -69,6 +71,9 @@ public: size_t numberOfRangesScheduledForDeletion() const override { return 0; } + +private: + const NamespaceString& _nss; }; } // namespace @@ -80,8 +85,8 @@ CollectionShardingStateFactoryStandalone::CollectionShardingStateFactoryStandalo void CollectionShardingStateFactoryStandalone::join() {} std::unique_ptr<CollectionShardingState> CollectionShardingStateFactoryStandalone::make( - const NamespaceString&) { - return std::make_unique<CollectionShardingStateStandalone>(); + const NamespaceString& nss) { + return std::make_unique<CollectionShardingStateStandalone>(nss); } } // namespace mongo diff --git a/src/mongo/db/s/database_sharding_state.h b/src/mongo/db/s/database_sharding_state.h index 5018a873c9c..57a9c7c84f9 100644 --- a/src/mongo/db/s/database_sharding_state.h +++ b/src/mongo/db/s/database_sharding_state.h @@ -32,7 +32,6 @@ #include "mongo/bson/bsonobj.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/s/sharding_migration_critical_section.h" -#include "mongo/s/catalog/type_database_gen.h" namespace mongo { @@ -44,12 +43,12 @@ enum class DSSAcquisitionMode { kShared, kExclusive }; * Synchronizes access to this shard server's cached database version for Database. */ class DatabaseShardingState { - DatabaseShardingState(const DatabaseShardingState&) = delete; - DatabaseShardingState& operator=(const DatabaseShardingState&) = delete; - public: DatabaseShardingState(const DatabaseName& dbName); - ~DatabaseShardingState() = default; + virtual ~DatabaseShardingState() = default; + + DatabaseShardingState(const DatabaseShardingState&) = delete; + DatabaseShardingState& operator=(const DatabaseShardingState&) = delete; /** * Obtains the sharding state for the specified database along with a resource lock protecting @@ -163,10 +162,6 @@ private: CancellationSource cancellationSource; }; - // Object-wide ResourceMutex to protect changes to the DatabaseShardingState or objects held - // within. - Lock::ResourceMutex _stateChangeMutex{"DatabaseShardingState"}; - const DatabaseName _dbName; // Modifying the state below requires holding the DBLock in X mode; holding the DBLock in any diff --git a/src/mongo/db/s/forwardable_operation_metadata.cpp b/src/mongo/db/s/forwardable_operation_metadata.cpp index 458484deb7f..3b5ca272ca8 100644 --- a/src/mongo/db/s/forwardable_operation_metadata.cpp +++ b/src/mongo/db/s/forwardable_operation_metadata.cpp @@ -27,8 +27,6 @@ * it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/db/s/forwardable_operation_metadata.h" #include "mongo/db/auth/authorization_session.h" diff --git a/src/mongo/db/s/forwardable_operation_metadata.h b/src/mongo/db/s/forwardable_operation_metadata.h index 34c603c655c..4df938b0712 100644 --- a/src/mongo/db/s/forwardable_operation_metadata.h +++ b/src/mongo/db/s/forwardable_operation_metadata.h @@ -50,7 +50,6 @@ public: explicit ForwardableOperationMetadata(const BSONObj& obj); explicit ForwardableOperationMetadata(OperationContext* opCtx); - void setOn(OperationContext* opCtx) const; }; diff --git a/src/mongo/db/s/metadata_manager.cpp b/src/mongo/db/s/metadata_manager.cpp index 4c2ffcea0d9..96542f14ef2 100644 --- a/src/mongo/db/s/metadata_manager.cpp +++ b/src/mongo/db/s/metadata_manager.cpp @@ -27,15 +27,10 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - #include "mongo/db/s/metadata_manager.h" #include "mongo/base/string_data.h" -#include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/bson/util/builder.h" -#include "mongo/db/query/internal_plans.h" #include "mongo/db/range_arithmetic.h" #include "mongo/db/s/migration_util.h" #include "mongo/db/s/range_deleter_service.h" @@ -43,13 +38,9 @@ #include "mongo/db/s/sharding_runtime_d_params_gen.h" #include "mongo/logv2/log.h" #include "mongo/s/sharding_feature_flags_gen.h" -#include "mongo/util/assert_util.h" -#include "mongo/util/fail_point.h" -#include "mongo/util/time_support.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - namespace mongo { namespace { diff --git a/src/mongo/db/s/metadata_manager.h b/src/mongo/db/s/metadata_manager.h index dfef01234ba..5343e7cc123 100644 --- a/src/mongo/db/s/metadata_manager.h +++ b/src/mongo/db/s/metadata_manager.h @@ -30,14 +30,10 @@ #pragma once #include <list> -#include <memory> -#include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/db/logical_time.h" #include "mongo/db/namespace_string.h" -#include "mongo/db/range_arithmetic.h" #include "mongo/db/s/scoped_collection_metadata.h" -#include "mongo/db/service_context.h" #include "mongo/executor/task_executor.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/util/concurrency/with_lock.h" diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index 5dd023e176f..13ddda47064 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -27,12 +27,10 @@ * it in the license file. */ - #include "mongo/db/s/migration_source_manager.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/catalog_raii.h" -#include "mongo/db/op_observer/op_observer.h" #include "mongo/db/operation_context.h" #include "mongo/db/read_concern.h" #include "mongo/db/repl/replication_coordinator.h" @@ -50,25 +48,19 @@ #include "mongo/db/s/sharding_state_recovery.h" #include "mongo/db/s/sharding_statistics.h" #include "mongo/db/s/type_shard_collection.h" -#include "mongo/db/session/logical_session_cache.h" -#include "mongo/db/session/logical_session_id_helpers.h" #include "mongo/db/timeseries/bucket_catalog.h" #include "mongo/db/vector_clock.h" -#include "mongo/executor/task_executor.h" -#include "mongo/executor/task_executor_pool.h" #include "mongo/logv2/log.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog_cache_loader.h" #include "mongo/s/grid.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/util/duration.h" -#include "mongo/util/elapsed_tracker.h" #include "mongo/util/fail_point.h" #include "mongo/util/scopeguard.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kShardingMigration - namespace mongo { namespace { diff --git a/src/mongo/db/s/migration_source_manager.h b/src/mongo/db/s/migration_source_manager.h index ba4d79eeaa6..756d1828014 100644 --- a/src/mongo/db/s/migration_source_manager.h +++ b/src/mongo/db/s/migration_source_manager.h @@ -31,6 +31,7 @@ #include <boost/optional.hpp> +#include "mongo/client/connection_string.h" #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/db/s/migration_chunk_cloner_source.h" #include "mongo/db/s/migration_coordinator.h" diff --git a/src/mongo/db/s/op_observer_sharding_impl.cpp b/src/mongo/db/s/op_observer_sharding_impl.cpp index ce1c2e94d09..4d156d39084 100644 --- a/src/mongo/db/s/op_observer_sharding_impl.cpp +++ b/src/mongo/db/s/op_observer_sharding_impl.cpp @@ -27,24 +27,18 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - #include "mongo/db/s/op_observer_sharding_impl.h" -#include "mongo/db/catalog_raii.h" #include "mongo/db/repl/oplog_entry.h" #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/db/s/database_sharding_state.h" #include "mongo/db/s/migration_chunk_cloner_source_legacy.h" #include "mongo/db/s/migration_source_manager.h" -#include "mongo/db/s/resharding/resharding_util.h" #include "mongo/db/s/sharding_write_router.h" #include "mongo/logv2/log.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - namespace mongo { namespace { @@ -128,7 +122,7 @@ void OpObserverShardingImpl::shardObserveInsertOp(OperationContext* opCtx, if (nss == NamespaceString::kSessionTransactionsTableNamespace || fromMigrate) return; - auto css = shardingWriteRouter.getCollectionShardingState(); + auto* const css = shardingWriteRouter.getCss(); auto* const csr = CollectionShardingRuntime::get(css); csr->checkShardVersionOrThrow(opCtx); @@ -165,7 +159,7 @@ void OpObserverShardingImpl::shardObserveUpdateOp(OperationContext* opCtx, const ShardingWriteRouter& shardingWriteRouter, const repl::OpTime& prePostImageOpTime, const bool inMultiDocumentTransaction) { - auto css = shardingWriteRouter.getCollectionShardingState(); + auto* const css = shardingWriteRouter.getCss(); auto* const csr = CollectionShardingRuntime::get(css); csr->checkShardVersionOrThrow(opCtx); @@ -201,7 +195,7 @@ void OpObserverShardingImpl::shardObserveDeleteOp(OperationContext* opCtx, const ShardingWriteRouter& shardingWriteRouter, const repl::OpTime& preImageOpTime, const bool inMultiDocumentTransaction) { - auto css = shardingWriteRouter.getCollectionShardingState(); + auto* const css = shardingWriteRouter.getCss(); auto* const csr = CollectionShardingRuntime::get(css); csr->checkShardVersionOrThrow(opCtx); diff --git a/src/mongo/db/s/sharding_write_router.cpp b/src/mongo/db/s/sharding_write_router.cpp index b1c5c701ae0..bb372f85572 100644 --- a/src/mongo/db/s/sharding_write_router.cpp +++ b/src/mongo/db/s/sharding_write_router.cpp @@ -29,11 +29,6 @@ #include "mongo/db/s/sharding_write_router.h" -#include "mongo/db/catalog/collection_catalog.h" -#include "mongo/db/s/sharding_state.h" -#include "mongo/s/catalog_cache.h" -#include "mongo/s/grid.h" - namespace mongo { ShardingWriteRouter::ShardingWriteRouter(OperationContext* opCtx, @@ -64,10 +59,6 @@ ShardingWriteRouter::ShardingWriteRouter(OperationContext* opCtx, } } -CollectionShardingState* ShardingWriteRouter::getCollectionShardingState() const { - return _css; -} - boost::optional<ShardId> ShardingWriteRouter::getReshardingDestinedRecipient( const BSONObj& fullDocument) const { if (!_reshardKeyPattern) { diff --git a/src/mongo/db/s/sharding_write_router.h b/src/mongo/db/s/sharding_write_router.h index 219e31859b0..ad4e05c78fa 100644 --- a/src/mongo/db/s/sharding_write_router.h +++ b/src/mongo/db/s/sharding_write_router.h @@ -30,22 +30,21 @@ #pragma once #include "mongo/db/s/collection_sharding_state.h" +#include "mongo/s/catalog_cache.h" + namespace mongo { -class BSONObj; -class CatalogCache; -class ChunkManager; -class OperationContext; -class ShardId; class ShardingWriteRouter { public: ShardingWriteRouter(OperationContext* opCtx, const NamespaceString& nss, CatalogCache* catalogCache); - boost::optional<ShardId> getReshardingDestinedRecipient(const BSONObj& fullDocument) const; + CollectionShardingState* getCss() const { + return _css; + } - CollectionShardingState* getCollectionShardingState() const; + boost::optional<ShardId> getReshardingDestinedRecipient(const BSONObj& fullDocument) const; private: CollectionShardingState* _css{nullptr}; diff --git a/src/mongo/db/s/split_vector.cpp b/src/mongo/db/s/split_vector.cpp index 742617b5fb0..fc467a2ebdb 100644 --- a/src/mongo/db/s/split_vector.cpp +++ b/src/mongo/db/s/split_vector.cpp @@ -27,33 +27,24 @@ * it in the license file. */ - -#include "mongo/platform/basic.h" - #include "mongo/db/s/split_vector.h" -#include "mongo/base/status_with.h" #include "mongo/db/bson/dotted_path_support.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/dbhelpers.h" -#include "mongo/db/exec/working_set_common.h" -#include "mongo/db/index/index_descriptor.h" #include "mongo/db/keypattern.h" -#include "mongo/db/namespace_string.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/query/plan_executor.h" -#include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/db/s/shard_key_index_util.h" #include "mongo/logv2/log.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - namespace mongo { namespace { const int kMaxObjectPerChunk{250000}; -const int estimatedAdditionalBytesPerItemInBSONArray{2}; +const int kEstimatedAdditionalBytesPerItemInBSONArray{2}; BSONObj prettyKey(const BSONObj& keyPattern, const BSONObj& key) { return key.replaceFieldNames(keyPattern).clientReadable(); @@ -90,9 +81,6 @@ std::vector<BSONObj> splitVector(OperationContext* opCtx, { AutoGetCollection collection(opCtx, nss, MODE_IS); - - CollectionShardingState::get(opCtx, nss)->checkShardVersionOrThrow(opCtx); - uassert(ErrorCodes::NamespaceNotFound, "ns not found", collection); // Allow multiKey based on the invariant that shard keys must be single-valued. Therefore, @@ -252,7 +240,7 @@ std::vector<BSONObj> splitVector(OperationContext* opCtx, tooFrequentKeys.insert(currKey.getOwned()); } else { auto additionalKeySize = - currKey.objsize() + estimatedAdditionalBytesPerItemInBSONArray; + currKey.objsize() + kEstimatedAdditionalBytesPerItemInBSONArray; if (splitVectorResponseSize + additionalKeySize > BSONObjMaxUserSize) { if (splitKeys.empty()) { // Keep trying until we get at least one split point that isn't diff --git a/src/mongo/db/s/split_vector.h b/src/mongo/db/s/split_vector.h index f7b28c8e648..3b94c40e353 100644 --- a/src/mongo/db/s/split_vector.h +++ b/src/mongo/db/s/split_vector.h @@ -32,13 +32,12 @@ #include <boost/optional.hpp> #include <vector> +#include "mongo/db/namespace_string.h" + namespace mongo { class BSONObj; -class NamespaceString; class OperationContext; -template <typename T> -class StatusWith; /** * Given a chunk, determines whether it can be split and returns the split points if so. This diff --git a/src/mongo/s/chunk_manager.h b/src/mongo/s/chunk_manager.h index 595ad25cfff..004a6a966f6 100644 --- a/src/mongo/s/chunk_manager.h +++ b/src/mongo/s/chunk_manager.h @@ -33,7 +33,6 @@ #include <string> #include <vector> -#include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" #include "mongo/db/query/collation/collator_interface.h" #include "mongo/s/chunk.h" @@ -43,7 +42,6 @@ #include "mongo/s/shard_version.h" #include "mongo/s/type_collection_common_types_gen.h" #include "mongo/stdx/unordered_map.h" -#include "mongo/util/concurrency/ticketholder.h" #include "mongo/util/read_through_cache.h" namespace mongo { |
