summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorAllison Easton <allison.easton@mongodb.com>2022-07-29 10:34:03 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-29 11:43:25 +0000
commit87df071285348663b750172dc6979f4cb28b5508 (patch)
tree1851129a78484d0b545b2bc86c626e19b9701331 /src/mongo/db/s
parentfc07225f8eb33456bbb67842db7d7112a0ee683b (diff)
downloadmongo-87df071285348663b750172dc6979f4cb28b5508.tar.gz
SERVER-67400 Create ShardVersion type
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/balancer/balancer_commands_scheduler_impl.h4
-rw-r--r--src/mongo/db/s/balancer/migration_test_fixture.cpp2
-rw-r--r--src/mongo/db/s/balancer/type_migration.cpp2
-rw-r--r--src/mongo/db/s/balancer/type_migration_test.cpp14
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.cpp9
-rw-r--r--src/mongo/db/s/commit_chunk_migration.idl6
-rw-r--r--src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp2
-rw-r--r--src/mongo/db/s/config/configsvr_merge_chunks_command.cpp2
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp32
-rw-r--r--src/mongo/db/s/migration_coordinator_document.idl3
-rw-r--r--src/mongo/db/s/operation_sharding_state.cpp9
-rw-r--r--src/mongo/db/s/operation_sharding_state.h8
-rw-r--r--src/mongo/db/s/shardsvr_merge_chunks_command.cpp4
-rw-r--r--src/mongo/db/s/split_chunk.cpp4
14 files changed, 52 insertions, 49 deletions
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;
}();