diff options
Diffstat (limited to 'src/mongo/db')
24 files changed, 80 insertions, 65 deletions
diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index 8f54e8fd9be..12d4f6693c8 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -374,7 +374,9 @@ IndexBuildsCoordinatorMongod::_startIndexBuild(OperationContext* opCtx, std::move(impersonatedClientAttrs.roleNames)); } - ScopedSetShardRole scopedSetShardRole(opCtx.get(), nss, shardVersion, dbVersion); + boost::optional<ChunkVersion> chunkVersion = + shardVersion ? boost::make_optional((ChunkVersion)*shardVersion) : boost::none; + ScopedSetShardRole scopedSetShardRole(opCtx.get(), nss, chunkVersion, dbVersion); { stdx::unique_lock<Client> lk(*opCtx->getClient()); diff --git a/src/mongo/db/pipeline/document_source_merge.cpp b/src/mongo/db/pipeline/document_source_merge.cpp index ae413052ddf..2e200076bb9 100644 --- a/src/mongo/db/pipeline/document_source_merge.cpp +++ b/src/mongo/db/pipeline/document_source_merge.cpp @@ -460,7 +460,12 @@ boost::intrusive_ptr<DocumentSource> DocumentSourceMerge::createFromBson( auto fieldPaths = convertToFieldPaths(mergeSpec.getOn()); auto [mergeOnFields, targetCollectionVersion] = expCtx->mongoProcessInterface->ensureFieldsUniqueOrResolveDocumentKey( - expCtx, std::move(fieldPaths), mergeSpec.getTargetCollectionVersion(), targetNss); + expCtx, + std::move(fieldPaths), + mergeSpec.getTargetCollectionVersion() + ? boost::make_optional((ChunkVersion)*mergeSpec.getTargetCollectionVersion()) + : boost::none, + targetNss); return DocumentSourceMerge::create(std::move(targetNss), expCtx, @@ -529,7 +534,9 @@ Value DocumentSourceMerge::serialize(boost::optional<ExplainOptions::Verbosity> } return mergeOnFields; }()); - spec.setTargetCollectionVersion(_targetCollectionVersion); + spec.setTargetCollectionVersion( + _targetCollectionVersion ? boost::make_optional(ShardVersion(*_targetCollectionVersion)) + : boost::none); return Value(Document{{getSourceName(), spec.toBSON()}}); } diff --git a/src/mongo/db/pipeline/document_source_merge.idl b/src/mongo/db/pipeline/document_source_merge.idl index 4def6572ddb..5b4d268f75b 100644 --- a/src/mongo/db/pipeline/document_source_merge.idl +++ b/src/mongo/db/pipeline/document_source_merge.idl @@ -33,12 +33,12 @@ global: cpp_includes: - "mongo/db/namespace_string.h" - "mongo/db/pipeline/document_source_merge_spec.h" + - "mongo/s/shard_version.h" imports: - "mongo/db/pipeline/document_source_merge_modes.idl" - "mongo/idl/basic_types.idl" - - "mongo/s/chunk_version.idl" - + - "mongo/s/sharding_types.idl" types: MergeTargetNss: bson_serialization_type: any @@ -112,9 +112,9 @@ structs: do not match. targetCollectionVersion: - type: ChunkVersion + type: shard_version optional: true - description: If set, the collection's ChunkVersion found when parsed on mongos. Can + description: If set, the collection's ShardVersion found when parsed on mongos. Can be used to check if a collection has since been dropped and re-created, in which case the shard key may have changed, or had its shard key refined. This also can be used to detect if the collection has gone diff --git a/src/mongo/db/pipeline/process_interface/common_process_interface.cpp b/src/mongo/db/pipeline/process_interface/common_process_interface.cpp index 57e4c15f3cc..0987e83a6ee 100644 --- a/src/mongo/db/pipeline/process_interface/common_process_interface.cpp +++ b/src/mongo/db/pipeline/process_interface/common_process_interface.cpp @@ -186,13 +186,13 @@ bool CommonProcessInterface::keyPatternNamesExactPaths(const BSONObj& keyPattern return nFieldsMatched == uniqueKeyPaths.size(); } -boost::optional<ChunkVersion> CommonProcessInterface::refreshAndGetCollectionVersion( +boost::optional<ShardVersion> CommonProcessInterface::refreshAndGetCollectionVersion( const boost::intrusive_ptr<ExpressionContext>& expCtx, const NamespaceString& nss) const { const auto cm = uassertStatusOK(Grid::get(expCtx->opCtx) ->catalogCache() ->getCollectionRoutingInfoWithRefresh(expCtx->opCtx, nss)); - return cm.isSharded() ? boost::make_optional(cm.getVersion()) : boost::none; + return cm.isSharded() ? boost::make_optional(ShardVersion(cm.getVersion())) : boost::none; } std::vector<FieldPath> CommonProcessInterface::_shardKeyToDocumentKeyFields( diff --git a/src/mongo/db/pipeline/process_interface/common_process_interface.h b/src/mongo/db/pipeline/process_interface/common_process_interface.h index 513edd5a6f4..efaf292f796 100644 --- a/src/mongo/db/pipeline/process_interface/common_process_interface.h +++ b/src/mongo/db/pipeline/process_interface/common_process_interface.h @@ -66,7 +66,7 @@ public: virtual void updateClientOperationTime(OperationContext* opCtx) const final; - boost::optional<ChunkVersion> refreshAndGetCollectionVersion( + boost::optional<ShardVersion> refreshAndGetCollectionVersion( const boost::intrusive_ptr<ExpressionContext>& expCtx, const NamespaceString& nss) const override; diff --git a/src/mongo/db/pipeline/process_interface/mongo_process_interface.h b/src/mongo/db/pipeline/process_interface/mongo_process_interface.h index 0e36e13613f..9e2f0e96926 100644 --- a/src/mongo/db/pipeline/process_interface/mongo_process_interface.h +++ b/src/mongo/db/pipeline/process_interface/mongo_process_interface.h @@ -58,6 +58,7 @@ #include "mongo/db/storage/temporary_record_store.h" #include "mongo/executor/task_executor.h" #include "mongo/s/chunk_version.h" +#include "mongo/s/shard_version.h" namespace mongo { @@ -433,7 +434,7 @@ public: * request to be sent to the config servers. If another thread has already requested a refresh, * it will instead wait for that response. */ - virtual boost::optional<ChunkVersion> refreshAndGetCollectionVersion( + virtual boost::optional<ShardVersion> refreshAndGetCollectionVersion( const boost::intrusive_ptr<ExpressionContext>& expCtx, const NamespaceString& nss) const = 0; diff --git a/src/mongo/db/pipeline/process_interface/mongos_process_interface.cpp b/src/mongo/db/pipeline/process_interface/mongos_process_interface.cpp index c3dcee83248..117fa156d71 100644 --- a/src/mongo/db/pipeline/process_interface/mongos_process_interface.cpp +++ b/src/mongo/db/pipeline/process_interface/mongos_process_interface.cpp @@ -358,7 +358,9 @@ MongosProcessInterface::ensureFieldsUniqueOrResolveDocumentKey( // collection was dropped a long time ago. Because of this, we are okay with piggy-backing // off another thread's request to refresh the cache, simply waiting for that request to // return instead of forcing another refresh. - targetCollectionVersion = refreshAndGetCollectionVersion(expCtx, outputNs); + boost::optional<ShardVersion> targetVersion = refreshAndGetCollectionVersion(expCtx, outputNs); + targetCollectionVersion = + targetVersion ? boost::make_optional((ChunkVersion)*targetVersion) : boost::none; auto docKeyPaths = collectDocumentKeyFieldsActingAsRouter(expCtx->opCtx, outputNs); return {std::set<FieldPath>(std::make_move_iterator(docKeyPaths.begin()), diff --git a/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.h b/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.h index 138ba6f3b80..ac5000d84fd 100644 --- a/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.h +++ b/src/mongo/db/pipeline/process_interface/non_shardsvr_process_interface.h @@ -64,7 +64,7 @@ public: return nullptr; } - boost::optional<ChunkVersion> refreshAndGetCollectionVersion( + boost::optional<ShardVersion> refreshAndGetCollectionVersion( const boost::intrusive_ptr<ExpressionContext>& expCtx, const NamespaceString& nss) const final { return boost::none; // Nothing is sharded here. diff --git a/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h b/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h index f406cdfb726..7b96bb53ed0 100644 --- a/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h +++ b/src/mongo/db/pipeline/process_interface/stub_mongo_process_interface.h @@ -249,7 +249,7 @@ public: return true; } - boost::optional<ChunkVersion> refreshAndGetCollectionVersion( + boost::optional<ShardVersion> refreshAndGetCollectionVersion( const boost::intrusive_ptr<ExpressionContext>& expCtx, const NamespaceString& nss) const override { return boost::none; diff --git a/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.h b/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.h index bc955e99c07..537548850e5 100644 --- a/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.h +++ b/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.h @@ -291,7 +291,7 @@ public: .append(kEpoch, _version.epoch()) .append(kTimestamp, _version.getTimestamp()); - _version.serializeToBSON(ChunkVersion::kShardVersionField, &commandBuilder); + _version.serialize(ChunkVersion::kChunkVersionField, &commandBuilder); return commandBuilder.obj(); } @@ -366,7 +366,7 @@ public: .append(kMaxValue, _upperBoundKey) .append(kEstimatedValue, _estimatedValue); - _version.serializeToBSON(ChunkVersion::kShardVersionField, &commandBuilder); + _version.serialize(ChunkVersion::kChunkVersionField, &commandBuilder); return commandBuilder.obj(); } diff --git a/src/mongo/db/s/balancer/migration_test_fixture.cpp b/src/mongo/db/s/balancer/migration_test_fixture.cpp index d3bac026844..c5805470cfd 100644 --- a/src/mongo/db/s/balancer/migration_test_fixture.cpp +++ b/src/mongo/db/s/balancer/migration_test_fixture.cpp @@ -126,7 +126,7 @@ void MigrationTestFixture::setUpMigration(const NamespaceString& ns, builder.append(MigrationType::max(), chunk.getMax()); builder.append(MigrationType::toShard(), toShard.toString()); builder.append(MigrationType::fromShard(), chunk.getShard().toString()); - chunk.getVersion().serializeToBSON("chunkVersion", &builder); + chunk.getVersion().serialize("chunkVersion", &builder); builder.append(MigrationType::forceJumbo(), "doNotForceJumbo"); MigrationType migrationType = assertGet(MigrationType::fromBSON(builder.obj())); diff --git a/src/mongo/db/s/balancer/type_migration.cpp b/src/mongo/db/s/balancer/type_migration.cpp index 4da7deb522f..bbf703c0d13 100644 --- a/src/mongo/db/s/balancer/type_migration.cpp +++ b/src/mongo/db/s/balancer/type_migration.cpp @@ -174,7 +174,7 @@ BSONObj MigrationType::toBSON() const { builder.append(fromShard.name(), _fromShard.toString()); builder.append(toShard.name(), _toShard.toString()); - _chunkVersion.serializeToBSON(chunkVersion.name(), &builder); + _chunkVersion.serialize(chunkVersion.name(), &builder); builder.append(waitForDelete.name(), _waitForDelete); builder.append(forceJumbo.name(), _forceJumbo); diff --git a/src/mongo/db/s/balancer/type_migration_test.cpp b/src/mongo/db/s/balancer/type_migration_test.cpp index d8d7f695fad..f195b4e91a8 100644 --- a/src/mongo/db/s/balancer/type_migration_test.cpp +++ b/src/mongo/db/s/balancer/type_migration_test.cpp @@ -54,7 +54,7 @@ TEST(MigrationTypeTest, FromAndToBSONWithoutOptionalFields) { builder.append(MigrationType::max(), kMax); builder.append(MigrationType::fromShard(), kFromShard.toString()); builder.append(MigrationType::toShard(), kToShard.toString()); - version.serializeToBSON("chunkVersion", &builder); + version.serialize("chunkVersion", &builder); builder.append(MigrationType::waitForDelete(), kWaitForDelete); builder.append(MigrationType::forceJumbo(), ForceJumbo_serializer(ForceJumbo::kDoNotForce)); @@ -76,7 +76,7 @@ TEST(MigrationTypeTest, FromAndToBSONWitOptionalFields) { builder.append(MigrationType::max(), kMax); builder.append(MigrationType::fromShard(), kFromShard.toString()); builder.append(MigrationType::toShard(), kToShard.toString()); - version.serializeToBSON("chunkVersion", &builder); + version.serialize("chunkVersion", &builder); builder.append(MigrationType::waitForDelete(), kWaitForDelete); builder.append(MigrationType::forceJumbo(), ForceJumbo_serializer(ForceJumbo::kDoNotForce)); builder.append(MigrationType::maxChunkSizeBytes(), 512 * 1024 * 1024); @@ -97,7 +97,7 @@ TEST(MigrationTypeTest, MissingRequiredNamespaceField) { builder.append(MigrationType::max(), kMax); builder.append(MigrationType::fromShard(), kFromShard.toString()); builder.append(MigrationType::toShard(), kToShard.toString()); - version.serializeToBSON("chunkVersion", &builder); + version.serialize("chunkVersion", &builder); BSONObj obj = builder.obj(); @@ -114,7 +114,7 @@ TEST(MigrationTypeTest, MissingRequiredMinField) { builder.append(MigrationType::max(), kMax); builder.append(MigrationType::fromShard(), kFromShard.toString()); builder.append(MigrationType::toShard(), kToShard.toString()); - version.serializeToBSON("chunkVersion", &builder); + version.serialize("chunkVersion", &builder); BSONObj obj = builder.obj(); @@ -131,7 +131,7 @@ TEST(MigrationTypeTest, MissingRequiredMaxField) { builder.append(MigrationType::min(), kMin); builder.append(MigrationType::fromShard(), kFromShard.toString()); builder.append(MigrationType::toShard(), kToShard.toString()); - version.serializeToBSON("chunkVersion", &builder); + version.serialize("chunkVersion", &builder); BSONObj obj = builder.obj(); @@ -148,7 +148,7 @@ TEST(MigrationTypeTest, MissingRequiredFromShardField) { builder.append(MigrationType::min(), kMin); builder.append(MigrationType::max(), kMax); builder.append(MigrationType::toShard(), kToShard.toString()); - version.serializeToBSON("chunkVersion", &builder); + version.serialize("chunkVersion", &builder); BSONObj obj = builder.obj(); @@ -165,7 +165,7 @@ TEST(MigrationTypeTest, MissingRequiredToShardField) { builder.append(MigrationType::min(), kMin); builder.append(MigrationType::max(), kMax); builder.append(MigrationType::fromShard(), kFromShard.toString()); - version.serializeToBSON("chunkVersion", &builder); + version.serialize("chunkVersion", &builder); BSONObj obj = builder.obj(); diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index 18521003da0..de24504c1dd 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -63,7 +63,7 @@ private: const auto kUnshardedCollection = std::make_shared<UnshardedCollection>(); -boost::optional<ChunkVersion> getOperationReceivedVersion(OperationContext* opCtx, +boost::optional<ShardVersion> getOperationReceivedVersion(OperationContext* opCtx, const NamespaceString& nss) { // If there is a version attached to the OperationContext, use it as the received version. if (OperationShardingState::isComingFromRouter(opCtx)) { @@ -103,7 +103,7 @@ ScopedCollectionFilter CollectionShardingRuntime::getOwnershipFilter( OperationContext* opCtx, OrphanCleanupPolicy orphanCleanupPolicy, bool supportNonVersionedOperations) { - boost::optional<ChunkVersion> optReceivedShardVersion = boost::none; + boost::optional<ShardVersion> optReceivedShardVersion = boost::none; if (!supportNonVersionedOperations) { optReceivedShardVersion = getOperationReceivedVersion(opCtx, _nss); // No operations should be calling getOwnershipFilter without a shard version @@ -143,7 +143,8 @@ ScopedCollectionDescription CollectionShardingRuntime::getCollectionDescription( const auto receivedShardVersion{oss.getShardVersion(_nss)}; uassert( StaleConfigInfo(_nss, - receivedShardVersion ? *receivedShardVersion : ChunkVersion::IGNORED(), + receivedShardVersion ? (ChunkVersion)*receivedShardVersion + : ChunkVersion::IGNORED(), boost::none /* wantedVersion */, ShardingState::get(_serviceContext)->shardId()), str::stream() << "sharding status of collection " << _nss.ns() @@ -352,7 +353,7 @@ CollectionShardingRuntime::_getMetadataWithVersionCheckAt( // Assume that the received shard version was IGNORED if the current operation wasn't versioned const auto& receivedShardVersion = - optReceivedShardVersion ? *optReceivedShardVersion : ChunkVersion::IGNORED(); + optReceivedShardVersion ? (ChunkVersion)*optReceivedShardVersion : ChunkVersion::IGNORED(); auto csrLock = CSRLock::lockShared(opCtx, this); diff --git a/src/mongo/db/s/commit_chunk_migration.idl b/src/mongo/db/s/commit_chunk_migration.idl index 6484623cd5c..981598e6573 100644 --- a/src/mongo/db/s/commit_chunk_migration.idl +++ b/src/mongo/db/s/commit_chunk_migration.idl @@ -43,7 +43,7 @@ structs: fields: shardVersion: type: ChunkVersion - description: "Collection version at the end of the migration." + description: "Placement information at the end of the migration." MigratedChunkType: description: "ChunkType describing a migrated chunk" @@ -77,9 +77,9 @@ commands: description: "ChunkType describing a migrated chunk" fromShardCollectionVersion: - type: ChunkVersion + type: ChunkVersion description: "{ shardVersionField: <version> }" validAfter: type: timestamp - description: "The time after which this chunk is at the new shard"
\ No newline at end of file + description: "The time after which this chunk is at the new shard" diff --git a/src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp b/src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp index 30ecefe11c8..66b4416a343 100644 --- a/src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp +++ b/src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp @@ -146,7 +146,7 @@ public: auto chunkVersionObj = uassertStatusOK(chunkVersionResponse); - return Response{ChunkVersion::parse(chunkVersionObj[ChunkVersion::kShardVersionField])}; + return Response{ChunkVersion::parse(chunkVersionObj[ChunkVersion::kChunkVersionField])}; } private: diff --git a/src/mongo/db/s/config/configsvr_merge_chunks_command.cpp b/src/mongo/db/s/config/configsvr_merge_chunks_command.cpp index db155fa6bea..430cb5c25b9 100644 --- a/src/mongo/db/s/config/configsvr_merge_chunks_command.cpp +++ b/src/mongo/db/s/config/configsvr_merge_chunks_command.cpp @@ -97,7 +97,7 @@ public: request().getShard(), request().getValidAfter())); return ConfigSvrMergeResponse{ - ChunkVersion::parse(shardAndCollVers[ChunkVersion::kShardVersionField])}; + ChunkVersion::parse(shardAndCollVers[ChunkVersion::kChunkVersionField])}; } private: diff --git a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp index 78af77db426..459fdef0061 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp @@ -83,7 +83,7 @@ void appendShortVersion(BufBuilder* out, const ChunkType& chunk) { bb.append(ChunkType::min(), chunk.getMin()); bb.append(ChunkType::max(), chunk.getMax()); if (chunk.isVersionSet()) { - chunk.getVersion().serializeToBSON(ChunkType::lastmod(), &bb); + chunk.getVersion().serialize(ChunkType::lastmod(), &bb); } bb.done(); } @@ -685,7 +685,7 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkSplit( BSONObjBuilder b(logDetail.subobjStart("before")); b.append(ChunkType::min(), range.getMin()); b.append(ChunkType::max(), range.getMax()); - collVersion.serializeToBSON(ChunkType::lastmod(), &b); + collVersion.serialize(ChunkType::lastmod(), &b); } if (splitChunkResult.newChunks->size() == 2) { @@ -719,8 +719,8 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkSplit( } BSONObjBuilder response; - splitChunkResult.currentMaxVersion.serializeToBSON(kCollectionVersionField, &response); - splitChunkResult.currentMaxVersion.serializeToBSON(ChunkVersion::kShardVersionField, &response); + splitChunkResult.currentMaxVersion.serialize(kCollectionVersionField, &response); + splitChunkResult.currentMaxVersion.serialize(ChunkVersion::kChunkVersionField, &response); return response.obj(); } @@ -908,9 +908,9 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunksMerge( << chunkRange.toString(), chunk.getRange() == chunkRange); BSONObjBuilder response; - collVersion.serializeToBSON(kCollectionVersionField, &response); + collVersion.serialize(kCollectionVersionField, &response); const auto currentShardVersion = getShardVersion(opCtx, coll, shardId, collVersion); - currentShardVersion.serializeToBSON(ChunkVersion::kShardVersionField, &response); + currentShardVersion.serialize(ChunkVersion::kChunkVersionField, &response); // Makes sure that the last thing we read in getCollectionVersion and getShardVersion gets // majority written before to return from this command, otherwise next RoutingInfo cache // refresh from the shard may not see those newest information. @@ -965,16 +965,16 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunksMerge( b.append(chunkToMerge.toConfigBSON()); } } - initialVersion.serializeToBSON("prevShardVersion", &logDetail); - mergeVersion.serializeToBSON("mergedVersion", &logDetail); + initialVersion.serialize("prevShardVersion", &logDetail); + mergeVersion.serialize("mergedVersion", &logDetail); logDetail.append("owningShard", shardId); ShardingLogging::get(opCtx)->logChange( opCtx, "merge", nss.ns(), logDetail.obj(), WriteConcernOptions()); BSONObjBuilder response; - mergeVersion.serializeToBSON(kCollectionVersionField, &response); - mergeVersion.serializeToBSON(ChunkVersion::kShardVersionField, &response); + mergeVersion.serialize(kCollectionVersionField, &response); + mergeVersion.serialize(ChunkVersion::kChunkVersionField, &response); return response.obj(); } @@ -1101,10 +1101,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration( if (currentChunk.getShard() == toShard) { // The commit was already done successfully BSONObjBuilder response; - currentCollectionVersion.serializeToBSON(kCollectionVersionField, &response); + currentCollectionVersion.serialize(kCollectionVersionField, &response); const auto currentShardVersion = getShardVersion(opCtx, coll, fromShard, currentCollectionVersion); - currentShardVersion.serializeToBSON(ChunkVersion::kShardVersionField, &response); + currentShardVersion.serialize(ChunkVersion::kChunkVersionField, &response); // Makes sure that the last thing we read in findChunkContainingRange, getShardVersion, and // getCollectionVersion gets majority written before to return from this command, otherwise // next RoutingInfo cache refresh from the shard may not see those newest information. @@ -1235,13 +1235,13 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration( BSONObjBuilder response; if (!newControlChunk) { // We migrated the last chunk from the donor shard. - newMigratedChunk->getVersion().serializeToBSON(kCollectionVersionField, &response); + newMigratedChunk->getVersion().serialize(kCollectionVersionField, &response); const ChunkVersion donorShardVersion( {currentCollectionVersion.epoch(), currentCollectionVersion.getTimestamp()}, {0, 0}); - donorShardVersion.serializeToBSON(ChunkVersion::kShardVersionField, &response); + donorShardVersion.serialize(ChunkVersion::kChunkVersionField, &response); } else { - newControlChunk->getVersion().serializeToBSON(kCollectionVersionField, &response); - newControlChunk->getVersion().serializeToBSON(ChunkVersion::kShardVersionField, &response); + newControlChunk->getVersion().serialize(kCollectionVersionField, &response); + newControlChunk->getVersion().serialize(ChunkVersion::kChunkVersionField, &response); } return response.obj(); } diff --git a/src/mongo/db/s/migration_coordinator_document.idl b/src/mongo/db/s/migration_coordinator_document.idl index 028cb194582..c9368dcedaa 100644 --- a/src/mongo/db/s/migration_coordinator_document.idl +++ b/src/mongo/db/s/migration_coordinator_document.idl @@ -95,7 +95,8 @@ structs: description: "The range being migrated." preMigrationChunkVersion: type: ChunkVersion - description: "The version, at the start of the migration, of the chunk being moved." + description: "The data placement, at the start of the migration, of the chunk being + moved." decision: type: Decision description: "Enumeration that defines whether the migration committed or aborted." diff --git a/src/mongo/db/s/operation_sharding_state.cpp b/src/mongo/db/s/operation_sharding_state.cpp index 0419fb1e895..6fd4ce5fc4f 100644 --- a/src/mongo/db/s/operation_sharding_state.cpp +++ b/src/mongo/db/s/operation_sharding_state.cpp @@ -61,13 +61,14 @@ void OperationShardingState::setShardRole(OperationContext* opCtx, auto& oss = OperationShardingState::get(opCtx); if (shardVersion) { - auto emplaceResult = oss._shardVersions.try_emplace(nss.ns(), *shardVersion); + ShardVersion fullShardVersion(*shardVersion); + auto emplaceResult = oss._shardVersions.try_emplace(nss.ns(), fullShardVersion); auto& tracker = emplaceResult.first->second; if (!emplaceResult.second) { uassert(640570, str::stream() << "Illegal attempt to change the expected shard version for " - << nss << " from " << tracker.v << " to " << *shardVersion, - tracker.v == *shardVersion); + << nss << " from " << tracker.v << " to " << fullShardVersion, + tracker.v == fullShardVersion); } invariant(++tracker.recursion > 0); } @@ -86,7 +87,7 @@ void OperationShardingState::setShardRole(OperationContext* opCtx, } } -boost::optional<ChunkVersion> OperationShardingState::getShardVersion(const NamespaceString& nss) { +boost::optional<ShardVersion> OperationShardingState::getShardVersion(const NamespaceString& nss) { const auto it = _shardVersions.find(nss.ns()); if (it != _shardVersions.end()) { return it->second.v; diff --git a/src/mongo/db/s/operation_sharding_state.h b/src/mongo/db/s/operation_sharding_state.h index 99bd516295e..dff0c8df630 100644 --- a/src/mongo/db/s/operation_sharding_state.h +++ b/src/mongo/db/s/operation_sharding_state.h @@ -33,8 +33,8 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" -#include "mongo/s/chunk_version.h" #include "mongo/s/database_version.h" +#include "mongo/s/shard_version.h" #include "mongo/util/future.h" #include "mongo/util/string_map.h" @@ -121,7 +121,7 @@ public: * operation. Documents in chunks which did not belong on this shard at this shard version * will be filtered out. */ - boost::optional<ChunkVersion> getShardVersion(const NamespaceString& nss); + boost::optional<ShardVersion> getShardVersion(const NamespaceString& nss); /** * Returns true if the client sent a databaseVersion for any namespace. @@ -170,11 +170,11 @@ private: // Stores the shard version expected for each collection that will be accessed struct ShardVersionTracker { - ShardVersionTracker(ChunkVersion v) : v(v) {} + ShardVersionTracker(ShardVersion v) : v(v) {} ShardVersionTracker(ShardVersionTracker&&) = default; ShardVersionTracker(const ShardVersionTracker&) = delete; ShardVersionTracker& operator=(const ShardVersionTracker&) = delete; - ChunkVersion v; + ShardVersion v; int recursion{0}; }; StringMap<ShardVersionTracker> _shardVersions; diff --git a/src/mongo/db/s/shardsvr_merge_chunks_command.cpp b/src/mongo/db/s/shardsvr_merge_chunks_command.cpp index 8b3892a907b..160f4014ec0 100644 --- a/src/mongo/db/s/shardsvr_merge_chunks_command.cpp +++ b/src/mongo/db/s/shardsvr_merge_chunks_command.cpp @@ -148,8 +148,8 @@ void mergeChunks(OperationContext* opCtx, auto shardVersionReceived = [&]() -> boost::optional<ChunkVersion> { // Old versions might not have the shardVersion field - if (cmdResponse.response[ChunkVersion::kShardVersionField]) { - return ChunkVersion::parse(cmdResponse.response[ChunkVersion::kShardVersionField]); + if (cmdResponse.response[ChunkVersion::kChunkVersionField]) { + return ChunkVersion::parse(cmdResponse.response[ChunkVersion::kChunkVersionField]); } return boost::none; }(); diff --git a/src/mongo/db/s/split_chunk.cpp b/src/mongo/db/s/split_chunk.cpp index 7b9067e7902..f76ae40c9fc 100644 --- a/src/mongo/db/s/split_chunk.cpp +++ b/src/mongo/db/s/split_chunk.cpp @@ -254,8 +254,8 @@ StatusWith<boost::optional<ChunkRange>> splitChunk( boost::optional<ChunkVersion> shardVersionReceived = [&]() -> boost::optional<ChunkVersion> { // old versions might not have the shardVersion field - if (cmdResponse.response[ChunkVersion::kShardVersionField]) { - return ChunkVersion::parse(cmdResponse.response[ChunkVersion::kShardVersionField]); + if (cmdResponse.response[ChunkVersion::kChunkVersionField]) { + return ChunkVersion::parse(cmdResponse.response[ChunkVersion::kChunkVersionField]); } return boost::none; }(); diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 3bc08313324..b0a79bfde84 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -1679,8 +1679,8 @@ void ExecCommandDatabase::_initiateCommand() { : _invocation->ns(); boost::optional<ChunkVersion> shardVersion; - if (auto shardVersionElem = request.body[ChunkVersion::kShardVersionField]) { - shardVersion = ChunkVersion::parse(shardVersionElem); + if (auto shardVersionElem = request.body[ShardVersion::kShardVersionField]) { + shardVersion = ShardVersion::parse(shardVersionElem); } boost::optional<DatabaseVersion> databaseVersion; |