summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2022-03-01 11:01:22 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-01 12:08:24 +0000
commit0908dbec2f7e5d0dd0bfdf9369c5691aa75627fe (patch)
tree964062c8a20a21c03799c98614181ca9ff77247f /src/mongo/db
parent07d0be8c575c796065fdc18d05723bd92f66c8f2 (diff)
downloadmongo-0908dbec2f7e5d0dd0bfdf9369c5691aa75627fe.tar.gz
SERVER-64057 Move the shard/database version parsing to the endpoint
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/s/collection_metadata_filtering_test.cpp7
-rw-r--r--src/mongo/db/s/collection_sharding_runtime_test.cpp7
-rw-r--r--src/mongo/db/s/op_observer_sharding_test.cpp6
-rw-r--r--src/mongo/db/s/operation_sharding_state.cpp24
-rw-r--r--src/mongo/db/s/operation_sharding_state.h16
-rw-r--r--src/mongo/db/s/resharding/resharding_donor_recipient_common_test.h8
-rw-r--r--src/mongo/db/s/sharding_write_router_bm.cpp15
-rw-r--r--src/mongo/db/service_entry_point_common.cpp15
8 files changed, 24 insertions, 74 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.
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index 0c7b8d10f26..84d99a67405 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -1551,8 +1551,6 @@ void ExecCommandDatabase::_initiateCommand() {
// Once API params and txn state are set on opCtx, enforce the "requireApiVersion" setting.
enforceRequireAPIVersion(opCtx, command);
- auto& oss = OperationShardingState::get(opCtx);
-
if (!opCtx->getClient()->isInDirectClient() &&
readConcernArgs.getLevel() != repl::ReadConcernLevel::kAvailableReadConcern &&
(iAmPrimary || (readConcernArgs.hasLevel() || readConcernArgs.getArgsAfterClusterTime()))) {
@@ -1567,7 +1565,18 @@ void ExecCommandDatabase::_initiateCommand() {
? bucketNss
: _invocation->ns();
- oss.initializeClientRoutingVersionsFromCommand(namespaceForSharding, request.body);
+ boost::optional<ChunkVersion> shardVersion;
+ if (auto shardVersionElem = request.body[ChunkVersion::kShardVersionField]) {
+ shardVersion = ChunkVersion::fromBSONPositionalOrNewerFormat(shardVersionElem);
+ }
+
+ boost::optional<DatabaseVersion> databaseVersion;
+ if (auto databaseVersionElem = request.body[DatabaseVersion::kDatabaseVersionField]) {
+ databaseVersion = DatabaseVersion(databaseVersionElem.Obj());
+ }
+
+ OperationShardingState::get(opCtx).initializeClientRoutingVersions(
+ namespaceForSharding, shardVersion, databaseVersion);
}
_scoped = _execContext->behaviors->scopedOperationCompletionShardingActions(opCtx);