diff options
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r-- | src/mongo/db/s/collection_metadata_filtering_test.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_runtime_test.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/s/op_observer_sharding_test.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/s/operation_sharding_state.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/s/operation_sharding_state.h | 16 | ||||
-rw-r--r-- | src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h | 8 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_write_router_bm.cpp | 15 |
7 files changed, 12 insertions, 71 deletions
diff --git a/src/mongo/db/s/collection_metadata_filtering_test.cpp b/src/mongo/db/s/collection_metadata_filtering_test.cpp index f87803ec350..2190a56ce8f 100644 --- a/src/mongo/db/s/collection_metadata_filtering_test.cpp +++ b/src/mongo/db/s/collection_metadata_filtering_test.cpp @@ -125,11 +125,8 @@ protected: _manager = std::make_shared<MetadataManager>( getServiceContext(), kNss, executor(), CollectionMetadata(cm, ShardId("0"))); - const auto version = cm.getVersion(ShardId("0")); - BSONObjBuilder builder; - version.serializeToBSON(ChunkVersion::kShardVersionField, &builder); - auto& oss = OperationShardingState::get(operationContext()); - oss.initializeClientRoutingVersionsFromCommand(kNss, builder.obj()); + OperationShardingState::get(operationContext()) + .initializeClientRoutingVersions(kNss, cm.getVersion(ShardId("0")), boost::none); } std::shared_ptr<MetadataManager> _manager; diff --git a/src/mongo/db/s/collection_sharding_runtime_test.cpp b/src/mongo/db/s/collection_sharding_runtime_test.cpp index 00fdf7872bd..41442237766 100644 --- a/src/mongo/db/s/collection_sharding_runtime_test.cpp +++ b/src/mongo/db/s/collection_sharding_runtime_test.cpp @@ -78,11 +78,8 @@ protected: boost::none); if (!OperationShardingState::isOperationVersioned(opCtx)) { - const auto version = cm.getVersion(ShardId("0")); - BSONObjBuilder builder; - version.serializeToBSON(ChunkVersion::kShardVersionField, &builder); - auto& oss = OperationShardingState::get(opCtx); - oss.initializeClientRoutingVersionsFromCommand(kTestNss, builder.obj()); + OperationShardingState::get(opCtx).initializeClientRoutingVersions( + kTestNss, cm.getVersion(ShardId("0")), boost::none); } return CollectionMetadata(std::move(cm), ShardId("0")); diff --git a/src/mongo/db/s/op_observer_sharding_test.cpp b/src/mongo/db/s/op_observer_sharding_test.cpp index 3a64f193175..735b9e87212 100644 --- a/src/mongo/db/s/op_observer_sharding_test.cpp +++ b/src/mongo/db/s/op_observer_sharding_test.cpp @@ -48,10 +48,8 @@ void setCollectionFilteringMetadata(OperationContext* opCtx, CollectionMetadata CollectionShardingRuntime::get(opCtx, kTestNss) ->setFilteringMetadata(opCtx, std::move(metadata)); - BSONObjBuilder builder; - version.serializeToBSON(ChunkVersion::kShardVersionField, &builder); - auto& oss = OperationShardingState::get(opCtx); - oss.initializeClientRoutingVersionsFromCommand(kTestNss, builder.obj()); + OperationShardingState::get(opCtx).initializeClientRoutingVersions( + kTestNss, version, boost::none); } class DocumentKeyStateTest : public ShardServerTestFixture { diff --git a/src/mongo/db/s/operation_sharding_state.cpp b/src/mongo/db/s/operation_sharding_state.cpp index 39177eb6e2d..9a782d5eb6f 100644 --- a/src/mongo/db/s/operation_sharding_state.cpp +++ b/src/mongo/db/s/operation_sharding_state.cpp @@ -43,8 +43,6 @@ const Milliseconds kMaxWaitForMigrationCriticalSection = Minutes(5); // Max time to wait for the movePrimary critical section to complete 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; @@ -62,28 +60,6 @@ bool OperationShardingState::isOperationVersioned(OperationContext* opCtx) { return !oss._shardVersions.empty(); } -void OperationShardingState::initializeClientRoutingVersionsFromCommand(NamespaceString nss, - const BSONObj& cmdObj) { - boost::optional<ChunkVersion> shardVersion; - boost::optional<DatabaseVersion> dbVersion; - const auto shardVersionElem = cmdObj.getField(ChunkVersion::kShardVersionField); - if (!shardVersionElem.eoo()) { - shardVersion = ChunkVersion::fromBSONPositionalOrNewerFormat(shardVersionElem); - } - - const auto dbVersionElem = cmdObj.getField(kDbVersionField); - if (!dbVersionElem.eoo()) { - uassert(ErrorCodes::BadValue, - str::stream() << "expected databaseVersion element to be an object, got " - << dbVersionElem, - dbVersionElem.type() == BSONType::Object); - - dbVersion = DatabaseVersion(dbVersionElem.Obj()); - } - - initializeClientRoutingVersions(nss, shardVersion, dbVersion); -} - void OperationShardingState::initializeClientRoutingVersions( NamespaceString nss, const boost::optional<ChunkVersion>& shardVersion, diff --git a/src/mongo/db/s/operation_sharding_state.h b/src/mongo/db/s/operation_sharding_state.h index c4a63ba3a0b..2a39b630658 100644 --- a/src/mongo/db/s/operation_sharding_state.h +++ b/src/mongo/db/s/operation_sharding_state.h @@ -86,22 +86,6 @@ public: }; /** - * Parses shardVersion and databaseVersion from 'cmdObj' and stores the results in this object - * along with the given namespace that is associated with the versions. Does nothing if no - * shardVersion or databaseVersion is attached to the command. - * - * Expects 'cmdObj' to have format - * { ..., - * shardVersion: [<version>, <epoch>], - * databaseVersion: { uuid: <UUID>, version: <int> }, - * ...} - * - * This initialization may only be performed once for the lifetime of the object, which - * coincides with the lifetime of the client's request. - */ - void initializeClientRoutingVersionsFromCommand(NamespaceString nss, const BSONObj& cmdObj); - - /** * Stores the given shardVersion and databaseVersion for the given namespace. Note: The shard * version for the given namespace stored in the OperationShardingState can be overwritten if it * has not been checked yet. diff --git a/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h b/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h index d212413bcee..ff5d2ffa67b 100644 --- a/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h +++ b/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h @@ -128,12 +128,8 @@ protected: boost::none); if (!OperationShardingState::isOperationVersioned(opCtx)) { - const auto version = cm.getVersion(kThisShard.getShardId()); - BSONObjBuilder builder; - version.serializeToBSON(ChunkVersion::kShardVersionField, &builder); - - auto& oss = OperationShardingState::get(opCtx); - oss.initializeClientRoutingVersionsFromCommand(nss, builder.obj()); + OperationShardingState::get(opCtx).initializeClientRoutingVersions( + nss, cm.getVersion(kThisShard.getShardId()), boost::none); } return CollectionMetadata(std::move(cm), kThisShard.getShardId()); diff --git a/src/mongo/db/s/sharding_write_router_bm.cpp b/src/mongo/db/s/sharding_write_router_bm.cpp index 6980358d793..4fe0fe6c1e1 100644 --- a/src/mongo/db/s/sharding_write_router_bm.cpp +++ b/src/mongo/db/s/sharding_write_router_bm.cpp @@ -145,21 +145,14 @@ std::unique_ptr<CatalogCacheMock> createCatalogCacheMock(OperationContext* opCtx const auto [chunks, chunkManager] = createChunks(nShards, nChunks, shards); - // Necessary to make usages of 'CollectionShardingState::get(opCtx, nss);' work + ShardingState::get(opCtx->getServiceContext())->setInitialized(originatorShard, clusterId); + CollectionShardingStateFactory::set( opCtx->getServiceContext(), std::make_unique<CollectionShardingStateFactoryShard>(opCtx->getServiceContext())); - // necessary to make ShardingState::get(_serviceContext)->enabled() return true - ShardingState::get(opCtx->getServiceContext())->setInitialized(originatorShard, clusterId); - - BSONObjBuilder builder; - chunkManager.getVersion(originatorShard) - .serializeToBSON(ChunkVersion::kShardVersionField, &builder); - // necessary to set the _shardVersions and _databaseVersions to true. Which is needed to get - // `getCollectionDescription` to work - OperationShardingState::get(opCtx).initializeClientRoutingVersionsFromCommand(kNss, - builder.obj()); + OperationShardingState::get(opCtx).initializeClientRoutingVersions( + kNss, chunkManager.getVersion(originatorShard), boost::none); // Configuring the filtering metadata such that calls to getCollectionDescription return what we // want. Specifically the reshardingFields are what we use. Its specified by the chunkManager. |