diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-08-21 10:50:04 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2019-02-27 10:51:15 -0500 |
commit | b049257fbd1d215388cffaf7544f6741dbce5b45 (patch) | |
tree | 90e385d3c5af33c64f2dc8b590447c606c58f611 /src/mongo/db/s | |
parent | 6df5463e57c068a653f27fa44daaa619453d602f (diff) | |
download | mongo-b049257fbd1d215388cffaf7544f6741dbce5b45.tar.gz |
SERVER-39495 Move ShardingState::needCollectionMetadata under OperationShardingState
ShardingState logically contains answers to questions about whether the
current instance is node in a sharded cluster, whereas
OperationShardingState is responsible for the 'shardedness' of the
commands.
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r-- | src/mongo/db/s/cleanup_orphaned_cmd.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/s/operation_sharding_state.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/s/operation_sharding_state.h | 7 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_state.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_state.h | 6 |
5 files changed, 19 insertions, 28 deletions
diff --git a/src/mongo/db/s/cleanup_orphaned_cmd.cpp b/src/mongo/db/s/cleanup_orphaned_cmd.cpp index b959633557a..28eab0d23bb 100644 --- a/src/mongo/db/s/cleanup_orphaned_cmd.cpp +++ b/src/mongo/db/s/cleanup_orphaned_cmd.cpp @@ -79,13 +79,7 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx, { AutoGetCollection autoColl(opCtx, ns, MODE_IX); auto* const css = CollectionShardingRuntime::get(opCtx, ns); - const auto optMetadata = css->getCurrentMetadataIfKnown(); - uassert(ErrorCodes::ConflictingOperationInProgress, - str::stream() << "Unable to establish sharding status for collection " << ns.ns(), - optMetadata); - - const auto& metadata = *optMetadata; - + const auto metadata = css->getCurrentMetadata(); if (!metadata->isSharded()) { LOG(0) << "skipping orphaned data cleanup for " << ns.ns() << ", collection is not sharded"; diff --git a/src/mongo/db/s/operation_sharding_state.cpp b/src/mongo/db/s/operation_sharding_state.cpp index 49ed69f6107..3284b5e825c 100644 --- a/src/mongo/db/s/operation_sharding_state.cpp +++ b/src/mongo/db/s/operation_sharding_state.cpp @@ -32,9 +32,9 @@ #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/operation_context.h" +#include "mongo/db/s/sharded_connection_info.h" namespace mongo { - namespace { const OperationContext::Decoration<OperationShardingState> shardingMetadataDecoration = @@ -48,6 +48,7 @@ const Milliseconds kMaxWaitForMovePrimaryCriticalSection = Minutes(5); // The name of the field in which the client attaches its database version. constexpr auto kDbVersionField = "databaseVersion"_sd; + } // namespace OperationShardingState::OperationShardingState() = default; @@ -60,6 +61,14 @@ OperationShardingState& OperationShardingState::get(OperationContext* opCtx) { return shardingMetadataDecoration(opCtx); } +bool OperationShardingState::isOperationVersioned(OperationContext* opCtx) { + const auto client = opCtx->getClient(); + + // Shard version information received from mongos may either be attached to the Client or + // directly to the OperationContext + return ShardedConnectionInfo::get(client, false) || get(opCtx).hasShardVersion(); +} + void OperationShardingState::setAllowImplicitCollectionCreation( const BSONElement& allowImplicitCollectionCreationElem) { if (!allowImplicitCollectionCreationElem.eoo()) { diff --git a/src/mongo/db/s/operation_sharding_state.h b/src/mongo/db/s/operation_sharding_state.h index 03c71c86fba..4358d6c9a21 100644 --- a/src/mongo/db/s/operation_sharding_state.h +++ b/src/mongo/db/s/operation_sharding_state.h @@ -63,6 +63,13 @@ public: static OperationShardingState& get(OperationContext* opCtx); /** + * Returns true if the the current operation was sent by the caller with shard version + * information attached, meaning that it must perform shard version checking and orphan + * filtering. + */ + static bool isOperationVersioned(OperationContext* opCtx); + + /** * Requests on a sharded collection that are broadcast without a shardVersion should not cause * the collection to be created on a shard that does not know about the collection already, * since the collection options will not be propagated. Such requests specify to disallow diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp index 0148c843dac..b9c7e634a53 100644 --- a/src/mongo/db/s/sharding_state.cpp +++ b/src/mongo/db/s/sharding_state.cpp @@ -33,8 +33,7 @@ #include "mongo/db/s/sharding_state.h" -#include "mongo/db/s/operation_sharding_state.h" -#include "mongo/db/s/sharded_connection_info.h" +#include "mongo/db/operation_context.h" #include "mongo/db/server_options.h" #include "mongo/util/log.h" @@ -116,18 +115,6 @@ OID ShardingState::clusterId() { return _clusterId; } -bool ShardingState::needCollectionMetadata(OperationContext* opCtx, const std::string& ns) { - if (!enabled()) - return false; - - Client* client = opCtx->getClient(); - - // Shard version information received from mongos may either by attached to the Client or - // directly to the OperationContext. - return ShardedConnectionInfo::get(client, false) || - OperationShardingState::get(opCtx).hasShardVersion(); -} - void ShardingState::clearForTests() { _initializationState.store(static_cast<uint32_t>(InitializationState::kNew)); } diff --git a/src/mongo/db/s/sharding_state.h b/src/mongo/db/s/sharding_state.h index ca71f376e2f..1755d33293e 100644 --- a/src/mongo/db/s/sharding_state.h +++ b/src/mongo/db/s/sharding_state.h @@ -105,12 +105,6 @@ public: OID clusterId(); /** - * Returns true if this node is a shard and if the currently runnint operation must engage the - * sharding subsystem (i.e., perform version checking, orphan filtering, etc). - */ - bool needCollectionMetadata(OperationContext* opCtx, const std::string& ns); - - /** * For testing only. This is a workaround for the fact that it is not possible to get a clean * ServiceContext in between test executions. Because of this, tests which require that they get * started with a clean (uninitialized) ShardingState must invoke this in their tearDown method. |