summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2022-04-13 06:48:14 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-13 07:36:12 +0000
commit9a41daf3be5ac63a7a5d5c9dde1f71f5cd01152b (patch)
treee035f78b65983c4527d235a2d26d31665c5b451b
parentd43fcc40638718961c8e01ffb2eb5ce2c525c742 (diff)
downloadmongo-9a41daf3be5ac63a7a5d5c9dde1f71f5cd01152b.tar.gz
SERVER-65438 Use the new ChunkVersion format in appendLegacyWithField
-rw-r--r--src/mongo/db/s/chunk_splitter.cpp32
-rw-r--r--src/mongo/db/s/collection_metadata.cpp17
-rw-r--r--src/mongo/db/s/collection_metadata.h11
-rw-r--r--src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp1
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager.h1
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp11
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_commit_chunk_migration_test.cpp11
-rw-r--r--src/mongo/db/s/get_shard_version_command.cpp17
-rw-r--r--src/mongo/db/s/shard_metadata_util_test.cpp4
-rw-r--r--src/mongo/s/chunk_version.cpp13
-rw-r--r--src/mongo/s/chunk_version.h4
-rw-r--r--src/mongo/s/commands/cluster_get_shard_version_cmd.cpp7
-rw-r--r--src/mongo/s/request_types/balance_chunk_request_test.cpp24
-rw-r--r--src/mongo/s/request_types/balance_chunk_request_type.cpp18
-rw-r--r--src/mongo/s/request_types/balance_chunk_request_type.h6
-rw-r--r--src/mongo/s/request_types/commit_chunk_migration_request_type.cpp14
-rw-r--r--src/mongo/s/request_types/commit_chunk_migration_request_type.h10
-rw-r--r--src/mongo/s/request_types/set_shard_version_request_test.cpp86
18 files changed, 135 insertions, 152 deletions
diff --git a/src/mongo/db/s/chunk_splitter.cpp b/src/mongo/db/s/chunk_splitter.cpp
index d27798fdd44..f61abc59eaf 100644
--- a/src/mongo/db/s/chunk_splitter.cpp
+++ b/src/mongo/db/s/chunk_splitter.cpp
@@ -108,18 +108,6 @@ Status splitChunkAtMultiplePoints(OperationContext* opCtx,
.withContext("split failed");
}
-void rebalanceChunk(OperationContext* opCtx, const NamespaceString& nss, const ChunkType& chunk) {
- auto shardRegistry = Grid::get(opCtx)->shardRegistry();
- auto shard = shardRegistry->getConfigShard();
- auto response = uassertStatusOK(shard->runCommandWithFixedRetryAttempts(
- opCtx,
- ReadPreferenceSetting{ReadPreference::PrimaryOnly},
- "admin",
- BalanceChunkRequest::serializeToRebalanceCommandForConfig(nss, chunk),
- Shard::RetryPolicy::kNotIdempotent));
- uassertStatusOK(response.commandStatus);
-}
-
/**
* Attempts to move the chunk specified by minKey away from its current shard.
*/
@@ -134,14 +122,18 @@ void moveChunk(OperationContext* opCtx, const NamespaceString& nss, const BSONOb
const auto suggestedChunk = cm.findIntersectingChunkWithSimpleCollation(minKey);
- ChunkType chunkToMove;
- chunkToMove.setCollectionUUID(cm.getUUID());
- chunkToMove.setShard(suggestedChunk.getShardId());
- chunkToMove.setMin(suggestedChunk.getMin());
- chunkToMove.setMax(suggestedChunk.getMax());
- chunkToMove.setVersion(suggestedChunk.getLastmod());
-
- rebalanceChunk(opCtx, nss, chunkToMove);
+ auto shard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
+ auto response = uassertStatusOK(shard->runCommandWithFixedRetryAttempts(
+ opCtx,
+ ReadPreferenceSetting{ReadPreference::PrimaryOnly},
+ "admin",
+ BalanceChunkRequest::serializeToRebalanceCommandForConfig(nss,
+ suggestedChunk.getRange(),
+ cm.getUUID(),
+ suggestedChunk.getShardId(),
+ suggestedChunk.getLastmod()),
+ Shard::RetryPolicy::kNotIdempotent));
+ uassertStatusOK(response.commandStatus);
}
/**
diff --git a/src/mongo/db/s/collection_metadata.cpp b/src/mongo/db/s/collection_metadata.cpp
index f68c39ef0ce..ea9f6f0c7c1 100644
--- a/src/mongo/db/s/collection_metadata.cpp
+++ b/src/mongo/db/s/collection_metadata.cpp
@@ -127,23 +127,6 @@ BSONObj CollectionMetadata::extractDocumentKey(const BSONObj& doc) const {
return doc;
}
-void CollectionMetadata::toBSONBasic(BSONObjBuilder& bb) const {
- if (isSharded()) {
- _cm->getVersion().appendLegacyWithField(&bb, "collVersion");
- getShardVersionForLogging().appendLegacyWithField(&bb, "shardVersion");
- bb.append("keyPattern", _cm->getShardKeyPattern().toBSON());
- } else {
- ChunkVersion::UNSHARDED().appendLegacyWithField(&bb, "collVersion");
- ChunkVersion::UNSHARDED().appendLegacyWithField(&bb, "shardVersion");
- }
-}
-
-BSONObj CollectionMetadata::toBSON() const {
- BSONObjBuilder builder;
- toBSONBasic(builder);
- return builder.obj();
-}
-
std::string CollectionMetadata::toStringBasic() const {
if (isSharded()) {
return str::stream() << "collection version: " << _cm->getVersion().toString()
diff --git a/src/mongo/db/s/collection_metadata.h b/src/mongo/db/s/collection_metadata.h
index 84ff44a6c90..b691f94ebe5 100644
--- a/src/mongo/db/s/collection_metadata.h
+++ b/src/mongo/db/s/collection_metadata.h
@@ -162,21 +162,10 @@ public:
BSONObj extractDocumentKey(const BSONObj& doc) const;
/**
- * BSON output of the basic metadata information (chunk and shard version).
- */
- void toBSONBasic(BSONObjBuilder& bb) const;
-
- BSONObj toBSON() const;
-
- /**
* String output of the collection and shard versions.
*/
std::string toStringBasic() const;
- std::string toString() const {
- return toStringBasic();
- }
-
//
// Methods used for orphan filtering and general introspection of the chunks owned by the 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 be58bd4c9b6..baebf46dd24 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
@@ -135,6 +135,7 @@ public:
nss,
commitRequest.getMigratedChunk(),
commitRequest.getCollectionEpoch(),
+ commitRequest.getCollectionTimestamp(),
commitRequest.getFromShard(),
commitRequest.getToShard(),
commitRequest.getValidAfter());
diff --git a/src/mongo/db/s/config/sharding_catalog_manager.h b/src/mongo/db/s/config/sharding_catalog_manager.h
index b51d982ac31..8621ffb153a 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager.h
+++ b/src/mongo/db/s/config/sharding_catalog_manager.h
@@ -287,6 +287,7 @@ public:
const NamespaceString& nss,
const ChunkType& migratedChunk,
const OID& collectionEpoch,
+ const Timestamp& collectionTimestamp,
const ShardId& fromShard,
const ShardId& toShard,
const boost::optional<Timestamp>& validAfter);
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 779b0c29e8c..172729b575b 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
@@ -943,6 +943,7 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration(
const NamespaceString& nss,
const ChunkType& migratedChunk,
const OID& collectionEpoch,
+ const Timestamp& collectionTimestamp,
const ShardId& fromShard,
const ShardId& toShard,
const boost::optional<Timestamp>& validAfter) {
@@ -1022,7 +1023,8 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration(
// failed to recover the migration. Check that the collection has not been dropped and recreated
// or had its shard key refined since the migration began, unbeknown to the shard when the
// command was sent.
- if (currentCollectionVersion.epoch() != collectionEpoch) {
+ if (currentCollectionVersion.epoch() != collectionEpoch ||
+ currentCollectionVersion.getTimestamp() != collectionTimestamp) {
return {ErrorCodes::StaleEpoch,
str::stream() << "The epoch of collection '" << nss.ns()
<< "' has changed since the migration began. The config server's "
@@ -1077,9 +1079,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration(
return {ErrorCodes::ConflictingOperationInProgress,
str::stream()
<< "Rejecting migration request because the version of the requested chunk "
- << migratedChunk.toConfigBSON()
- << " is older than the version of the current chunk "
- << currentChunk.toConfigBSON() << " on the shard " << fromShard.toString()};
+ << migratedChunk.toConfigBSON() << "(" << migratedChunk.getVersion().toString()
+ << ") is older than the version of the current chunk "
+ << currentChunk.toConfigBSON() << "(" << currentChunk.getVersion().toString()
+ << ") on shard " << fromShard.toString()};
}
// Generate the new versions of migratedChunk and controlChunk. Migrating chunk's minor version
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_commit_chunk_migration_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_commit_chunk_migration_test.cpp
index 100f72ca450..32cf2b1b189 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_commit_chunk_migration_test.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_commit_chunk_migration_test.cpp
@@ -98,6 +98,7 @@ TEST_F(CommitChunkMigrate, ChunksUpdatedCorrectly) {
kNamespace,
migratedChunk,
migratedChunk.getVersion().epoch(),
+ collTimestamp,
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter));
@@ -176,6 +177,7 @@ TEST_F(CommitChunkMigrate, ChunksUpdatedCorrectlyWithoutControlChunk) {
kNamespace,
chunk0,
origVersion.epoch(),
+ collTimestamp,
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter);
@@ -241,6 +243,7 @@ TEST_F(CommitChunkMigrate, CheckCorrectOpsCommandNoCtlTrimHistory) {
kNamespace,
chunk0,
origVersion.epoch(),
+ collTimestamp,
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter);
@@ -302,6 +305,7 @@ TEST_F(CommitChunkMigrate, RejectOutOfOrderHistory) {
kNamespace,
chunk0,
origVersion.epoch(),
+ origVersion.getTimestamp(),
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter);
@@ -357,6 +361,7 @@ TEST_F(CommitChunkMigrate, RejectWrongCollectionEpoch0) {
kNamespace,
chunk0,
OID::gen(),
+ Timestamp(52),
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter);
@@ -415,6 +420,7 @@ TEST_F(CommitChunkMigrate, RejectWrongCollectionEpoch1) {
kNamespace,
chunk0,
origVersion.epoch(),
+ origVersion.getTimestamp(),
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter);
@@ -474,6 +480,7 @@ TEST_F(CommitChunkMigrate, CommitWithLastChunkOnShardShouldNotAffectOtherChunks)
kNamespace,
chunk0,
origVersion.epoch(),
+ origVersion.getTimestamp(),
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter);
@@ -545,6 +552,7 @@ TEST_F(CommitChunkMigrate, RejectMissingChunkVersion) {
kNamespace,
migratedChunk,
origVersion.epoch(),
+ origVersion.getTimestamp(),
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter),
@@ -596,6 +604,7 @@ TEST_F(CommitChunkMigrate, RejectOlderChunkVersion) {
kNamespace,
migratedChunk,
origVersion.epoch(),
+ origVersion.getTimestamp(),
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter);
@@ -647,6 +656,7 @@ TEST_F(CommitChunkMigrate, RejectMismatchedEpoch) {
kNamespace,
migratedChunk,
origVersion.epoch(),
+ origVersion.getTimestamp(),
ShardId(shard0.getName()),
ShardId(shard1.getName()),
validAfter);
@@ -745,6 +755,7 @@ public:
kNamespace,
migratedChunk,
migratedChunk.getVersion().epoch(),
+ migratedChunk.getVersion().getTimestamp(),
donor,
recipient,
validAfter));
diff --git a/src/mongo/db/s/get_shard_version_command.cpp b/src/mongo/db/s/get_shard_version_command.cpp
index ceb80ea28e0..95c3aa71739 100644
--- a/src/mongo/db/s/get_shard_version_command.cpp
+++ b/src/mongo/db/s/get_shard_version_command.cpp
@@ -29,8 +29,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-#include "mongo/platform/basic.h"
-
#include "mongo/db/auth/action_set.h"
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/authorization_session.h"
@@ -109,7 +107,20 @@ public:
if (cmdObj["fullMetadata"].trueValue()) {
BSONObjBuilder metadataBuilder(result.subobjStart("metadata"));
if (metadata.isSharded()) {
- metadata.toBSONBasic(metadataBuilder);
+ metadataBuilder.appendTimestamp("collVersion",
+ metadata.getCollVersion().toLong());
+ metadataBuilder.append("collVersionEpoch", metadata.getCollVersion().epoch());
+ metadataBuilder.append("collVersionTimestamp",
+ metadata.getCollVersion().getTimestamp());
+
+ metadataBuilder.appendTimestamp("shardVersion",
+ metadata.getShardVersionForLogging().toLong());
+ metadataBuilder.append("shardVersionEpoch",
+ metadata.getShardVersionForLogging().epoch());
+ metadataBuilder.append("shardVersionTimestamp",
+ metadata.getShardVersionForLogging().getTimestamp());
+
+ metadataBuilder.append("keyPattern", metadata.getShardKeyPattern().toBSON());
BSONArrayBuilder chunksArr(metadataBuilder.subarrayStart("chunks"));
metadata.toBSONChunks(&chunksArr);
diff --git a/src/mongo/db/s/shard_metadata_util_test.cpp b/src/mongo/db/s/shard_metadata_util_test.cpp
index 090b9a43843..e81dc5d0f56 100644
--- a/src/mongo/db/s/shard_metadata_util_test.cpp
+++ b/src/mongo/db/s/shard_metadata_util_test.cpp
@@ -286,7 +286,7 @@ TEST_F(ShardMetadataUtilTest, UpdateWithWriteNewChunks) {
subMax.append("a", 10000);
}
splitChunkOneBuilder.append(ChunkType::shard(), lastChunk.getShard().toString());
- collVersion.appendLegacyWithField(&splitChunkOneBuilder, ChunkType::lastmod());
+ splitChunkOneBuilder.appendTimestamp(ChunkType::lastmod(), collVersion.toLong());
ChunkType splitChunkOne = assertGet(ChunkType::parseFromShardBSON(
splitChunkOneBuilder.obj(), collVersion.epoch(), collVersion.getTimestamp()));
newChunks.push_back(splitChunkOne);
@@ -300,7 +300,7 @@ TEST_F(ShardMetadataUtilTest, UpdateWithWriteNewChunks) {
}
splitChunkTwoMovedBuilder.append(ChunkType::max(), lastChunk.getMax());
splitChunkTwoMovedBuilder.append(ChunkType::shard(), "altShard");
- collVersion.appendLegacyWithField(&splitChunkTwoMovedBuilder, ChunkType::lastmod());
+ splitChunkTwoMovedBuilder.appendTimestamp(ChunkType::lastmod(), collVersion.toLong());
ChunkType splitChunkTwoMoved = assertGet(ChunkType::parseFromShardBSON(
splitChunkTwoMovedBuilder.obj(), collVersion.epoch(), collVersion.getTimestamp()));
newChunks.push_back(splitChunkTwoMoved);
diff --git a/src/mongo/s/chunk_version.cpp b/src/mongo/s/chunk_version.cpp
index b94d7a8f0b5..380d9834723 100644
--- a/src/mongo/s/chunk_version.cpp
+++ b/src/mongo/s/chunk_version.cpp
@@ -229,9 +229,16 @@ void ChunkVersion::serializeToPositionalFormatWronglyEncodedAsBSON(StringData fi
}
void ChunkVersion::appendLegacyWithField(BSONObjBuilder* out, StringData field) const {
- out->appendTimestamp(field, _combined);
- out->append(field + "Epoch", _epoch);
- out->append(field + "Timestamp", _timestamp);
+ if (feature_flags::gFeatureFlagNewPersistedChunkVersionFormat.isEnabled(
+ serverGlobalParams.featureCompatibility)) {
+ ChunkVersion60Format chunkVersion(
+ _timestamp, _epoch, Timestamp(majorVersion(), minorVersion()));
+ out->append(field, chunkVersion.toBSON());
+ } else {
+ out->appendTimestamp(field, _combined);
+ out->append(field + "Epoch", _epoch);
+ out->append(field + "Timestamp", _timestamp);
+ }
}
std::string ChunkVersion::toString() const {
diff --git a/src/mongo/s/chunk_version.h b/src/mongo/s/chunk_version.h
index 5aca379983e..ecc26431496 100644
--- a/src/mongo/s/chunk_version.h
+++ b/src/mongo/s/chunk_version.h
@@ -223,6 +223,10 @@ public:
* { ..., <field>: [ <combined major/minor> ],
* <field>Epoch: [ <OID epoch> ],
* <field>Timestamp: [ <Timestamp> ] ... }
+ * or
+ * { ..., <field> : {t: <Timestamp>, e: <OID>, v: <major/minor>}}.
+ *
+ * Depending on the FCV version
*/
void appendLegacyWithField(BSONObjBuilder* out, StringData field) const;
diff --git a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp
index fdaf4fd1447..ac404436772 100644
--- a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp
+++ b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp
@@ -29,8 +29,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-#include "mongo/platform/basic.h"
-
#include "mongo/db/auth/action_set.h"
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/authorization_session.h"
@@ -105,7 +103,10 @@ public:
uassert(ErrorCodes::NamespaceNotSharded,
str::stream() << "Collection " << nss.ns() << " is not sharded.",
cm.isSharded());
- cm.getVersion().appendLegacyWithField(&result, "version");
+
+ result.appendTimestamp("version", cm.getVersion().toLong());
+ result.append("versionEpoch", cm.getVersion().epoch());
+ result.append("versionTimestamp", cm.getVersion().getTimestamp());
if (cmdObj["fullMetadata"].trueValue()) {
BSONArrayBuilder chunksArrBuilder;
diff --git a/src/mongo/s/request_types/balance_chunk_request_test.cpp b/src/mongo/s/request_types/balance_chunk_request_test.cpp
index a9e3d133519..82a938dc1ae 100644
--- a/src/mongo/s/request_types/balance_chunk_request_test.cpp
+++ b/src/mongo/s/request_types/balance_chunk_request_test.cpp
@@ -27,14 +27,11 @@
* it in the license file.
*/
-#include "mongo/platform/basic.h"
-
-#include "mongo/s/request_types/balance_chunk_request_type.h"
-
#include "mongo/bson/bsonmisc.h"
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/write_concern_options.h"
+#include "mongo/s/request_types/balance_chunk_request_type.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
@@ -42,6 +39,25 @@ namespace {
using unittest::assertGet;
+TEST(BalanceChunkRequest, RoundTrip) {
+ UUID uuid{UUID::gen()};
+ ChunkVersion version(30, 1, OID::gen(), Timestamp{2, 0});
+ auto obj = BalanceChunkRequest::serializeToRebalanceCommandForConfig(
+ NamespaceString("DB.Test"),
+ ChunkRange(BSON("A" << 100), BSON("A" << 200)),
+ uuid,
+ ShardId("TestShard"),
+ version);
+
+ auto request =
+ assertGet(BalanceChunkRequest::parseFromConfigCommand(obj, false /* requireUUID */));
+ ASSERT_EQ(NamespaceString("DB.Test"), request.getNss());
+ ASSERT_BSONOBJ_EQ(ChunkRange(BSON("A" << 100), BSON("A" << 200)).toBSON(),
+ request.getChunk().getRange().toBSON());
+ ASSERT_EQ(uuid, request.getChunk().getCollectionUUID());
+ ASSERT_EQ(version, request.getChunk().getVersion());
+}
+
TEST(BalanceChunkRequest, ParseFromConfigCommandNoSecondaryThrottle) {
const ChunkVersion version(1, 0, OID::gen(), Timestamp(1, 1));
auto request = assertGet(BalanceChunkRequest::parseFromConfigCommand(
diff --git a/src/mongo/s/request_types/balance_chunk_request_type.cpp b/src/mongo/s/request_types/balance_chunk_request_type.cpp
index 278947708d3..c69291300fc 100644
--- a/src/mongo/s/request_types/balance_chunk_request_type.cpp
+++ b/src/mongo/s/request_types/balance_chunk_request_type.cpp
@@ -142,17 +142,19 @@ StatusWith<BalanceChunkRequest> BalanceChunkRequest::parseFromConfigCommand(cons
return request;
}
-BSONObj BalanceChunkRequest::serializeToRebalanceCommandForConfig(const NamespaceString& nss,
- const ChunkType& chunk) {
- invariant(chunk.validate());
-
+BSONObj BalanceChunkRequest::serializeToRebalanceCommandForConfig(
+ const NamespaceString& nss,
+ const ChunkRange& range,
+ const UUID& collectionUUID,
+ const ShardId& owningShard,
+ const ChunkVersion& expectedChunkVersion) {
BSONObjBuilder cmdBuilder;
cmdBuilder.append(kConfigSvrMoveChunk, 1);
cmdBuilder.append(kNS, nss.ns());
- cmdBuilder.appendElements(chunk.toConfigBSON());
- // ChunkType::toConfigBSON() no longer returns the epoch
- cmdBuilder.append(ChunkType::lastmod() + "Epoch", chunk.getVersion().epoch());
- cmdBuilder.append(ChunkType::lastmod() + "Timestamp", chunk.getVersion().getTimestamp());
+ range.append(&cmdBuilder);
+ cmdBuilder.append(ChunkType::shard(), owningShard);
+ collectionUUID.appendToBuilder(&cmdBuilder, ChunkType::collectionUUID());
+ expectedChunkVersion.appendLegacyWithField(&cmdBuilder, ChunkType::lastmod());
cmdBuilder.append(WriteConcernOptions::kWriteConcernField,
kMajorityWriteConcernNoTimeout.toBSON());
diff --git a/src/mongo/s/request_types/balance_chunk_request_type.h b/src/mongo/s/request_types/balance_chunk_request_type.h
index 0a139219441..d7397585d5c 100644
--- a/src/mongo/s/request_types/balance_chunk_request_type.h
+++ b/src/mongo/s/request_types/balance_chunk_request_type.h
@@ -62,8 +62,10 @@ public:
* better location for a chunk.
*/
static BSONObj serializeToRebalanceCommandForConfig(const NamespaceString& nss,
- const ChunkType& chunk);
-
+ const ChunkRange& range,
+ const UUID& collectionUUID,
+ const ShardId& owningShard,
+ const ChunkVersion& expectedChunkVersion);
const NamespaceString& getNss() const {
return _nss;
diff --git a/src/mongo/s/request_types/commit_chunk_migration_request_type.cpp b/src/mongo/s/request_types/commit_chunk_migration_request_type.cpp
index ee74cb2e95e..48ade6db9e8 100644
--- a/src/mongo/s/request_types/commit_chunk_migration_request_type.cpp
+++ b/src/mongo/s/request_types/commit_chunk_migration_request_type.cpp
@@ -61,6 +61,7 @@ StatusWith<ChunkType> extractChunk(const BSONObj& source, StringData field) {
ChunkVersion version;
try {
version = ChunkVersion::fromBSONLegacyOrNewerFormat(fieldObj, ChunkType::lastmod());
+ uassert(644490, "Version must be set", version.isSet());
} catch (const DBException& ex) {
return ex.toStatus();
}
@@ -68,9 +69,7 @@ StatusWith<ChunkType> extractChunk(const BSONObj& source, StringData field) {
ChunkType chunk;
chunk.setMin(rangeWith.getValue().getMin());
chunk.setMax(rangeWith.getValue().getMax());
- if (version.isSet()) {
- chunk.setVersion(version);
- }
+ chunk.setVersion(version);
return chunk;
}
@@ -127,6 +126,7 @@ StatusWith<CommitChunkMigrationRequest> CommitChunkMigrationRequest::createFromC
auto fromShardVersion =
ChunkVersion::fromBSONPositionalOrNewerFormat(obj[kFromShardCollectionVersion]);
request._collectionEpoch = fromShardVersion.epoch();
+ request._collectionTimestamp = fromShardVersion.getTimestamp();
} catch (const DBException& ex) {
return ex.toStatus();
}
@@ -163,14 +163,10 @@ void CommitChunkMigrationRequest::appendAsCommand(BSONObjBuilder* builder,
builder->append(kToShard, toShard.toString());
{
BSONObjBuilder migrateChunk(builder->subobjStart(kMigratedChunk));
- migrateChunk.appendElements(migratedChunk.toConfigBSON());
- // ChunkType::toConfigBSON() no longer adds the epoch
- migrateChunk.append(ChunkType::lastmod() + "Epoch", migratedChunk.getVersion().epoch());
- migrateChunk.append(ChunkType::lastmod() + "Timestamp",
- migratedChunk.getVersion().getTimestamp());
+ migratedChunk.getRange().append(&migrateChunk);
+ migratedChunk.getVersion().appendLegacyWithField(&migrateChunk, ChunkType::lastmod());
}
fromShardCollectionVersion.serializeToBSON(kFromShardCollectionVersion, builder);
-
builder->append(kValidAfter, validAfter);
}
diff --git a/src/mongo/s/request_types/commit_chunk_migration_request_type.h b/src/mongo/s/request_types/commit_chunk_migration_request_type.h
index f331677a931..16d5f0ef8ce 100644
--- a/src/mongo/s/request_types/commit_chunk_migration_request_type.h
+++ b/src/mongo/s/request_types/commit_chunk_migration_request_type.h
@@ -39,8 +39,8 @@ namespace mongo {
/**
* Creates and parses commit chunk migration command BSON objects.
*/
-struct CommitChunkMigrationRequest {
-
+class CommitChunkMigrationRequest {
+public:
CommitChunkMigrationRequest(const NamespaceString& nss, const ChunkType& chunk)
: _nss(nss), _migratedChunk(chunk) {}
@@ -78,10 +78,14 @@ struct CommitChunkMigrationRequest {
const OID& getCollectionEpoch() {
return _collectionEpoch;
}
+ const Timestamp& getCollectionTimestamp() {
+ return _collectionTimestamp;
+ }
const boost::optional<Timestamp>& getValidAfter() {
return _validAfter;
}
+private:
// The collection for which this request applies.
NamespaceString _nss;
@@ -94,7 +98,9 @@ struct CommitChunkMigrationRequest {
// The chunk being moved.
ChunkType _migratedChunk;
+ // Epoch/Timestamp of the collection, matches the ones set in `_migratedChunk`.
OID _collectionEpoch;
+ Timestamp _collectionTimestamp;
// The time of the move
boost::optional<Timestamp> _validAfter;
diff --git a/src/mongo/s/request_types/set_shard_version_request_test.cpp b/src/mongo/s/request_types/set_shard_version_request_test.cpp
index 9704d185785..a689e804001 100644
--- a/src/mongo/s/request_types/set_shard_version_request_test.cpp
+++ b/src/mongo/s/request_types/set_shard_version_request_test.cpp
@@ -39,7 +39,7 @@ namespace {
using unittest::assertGet;
-TEST(SetShardVersionRequest, ParseFull) {
+TEST(SetShardVersionRequestTest, ParseFull) {
const ChunkVersion chunkVersion(1, 2, OID::gen(), Timestamp(1, 1));
SetShardVersionRequest request =
@@ -57,7 +57,25 @@ TEST(SetShardVersionRequest, ParseFull) {
ASSERT_EQ(request.getNSVersion().epoch(), chunkVersion.epoch());
}
-TEST(SetShardVersionRequest, ParseFullWithAuthoritative) {
+TEST(SetShardVersionRequestTest, ParseFullNewFormat) {
+ const ChunkVersion chunkVersion(1, 2, OID::gen(), Timestamp(1, 1));
+
+ SetShardVersionRequest request = assertGet(SetShardVersionRequest::parseFromBSON([&] {
+ BSONObjBuilder builder(BSON("setShardVersion"
+ << "db.coll"));
+ chunkVersion.appendLegacyWithField(&builder, "version");
+ return builder.obj();
+ }()));
+
+ ASSERT(!request.shouldForceRefresh());
+ ASSERT(!request.isAuthoritative());
+ ASSERT_EQ(request.getNS().toString(), "db.coll");
+ ASSERT_EQ(request.getNSVersion().majorVersion(), chunkVersion.majorVersion());
+ ASSERT_EQ(request.getNSVersion().minorVersion(), chunkVersion.minorVersion());
+ ASSERT_EQ(request.getNSVersion().epoch(), chunkVersion.epoch());
+}
+
+TEST(SetShardVersionRequestTest, ParseFullWithAuthoritative) {
const ChunkVersion chunkVersion(1, 2, OID::gen(), Timestamp(1, 1));
SetShardVersionRequest request =
@@ -76,7 +94,7 @@ TEST(SetShardVersionRequest, ParseFullWithAuthoritative) {
ASSERT_EQ(request.getNSVersion().epoch(), chunkVersion.epoch());
}
-TEST(SetShardVersionRequest, ParseFullNoNS) {
+TEST(SetShardVersionRequestTest, ParseFullNoNS) {
const ChunkVersion chunkVersion(1, 2, OID::gen(), Timestamp(1, 1));
auto ssvStatus =
@@ -88,7 +106,7 @@ TEST(SetShardVersionRequest, ParseFullNoNS) {
ASSERT_EQ(ErrorCodes::InvalidNamespace, ssvStatus.getStatus().code());
}
-TEST(SetShardVersionRequest, ParseFullNSContainsDBOnly) {
+TEST(SetShardVersionRequestTest, ParseFullNSContainsDBOnly) {
const ChunkVersion chunkVersion(1, 2, OID::gen(), Timestamp(1, 1));
auto ssvStatus =
@@ -100,65 +118,5 @@ TEST(SetShardVersionRequest, ParseFullNSContainsDBOnly) {
ASSERT_EQ(ErrorCodes::InvalidNamespace, ssvStatus.getStatus().code());
}
-TEST(SetShardVersionRequest, ToSSVCommandFull) {
- const ChunkVersion chunkVersion(1, 2, OID::gen(), Timestamp(1, 1));
-
- SetShardVersionRequest ssv(NamespaceString("db.coll"), chunkVersion, false);
-
- ASSERT(!ssv.shouldForceRefresh());
- ASSERT(!ssv.isAuthoritative());
- ASSERT_EQ(ssv.getNS().ns(), "db.coll");
- ASSERT_EQ(ssv.getNSVersion().toString(), chunkVersion.toString());
-
- ASSERT_BSONOBJ_EQ(ssv.toBSON(),
- BSON("setShardVersion"
- << "db.coll"
- << "forceRefresh" << false << "authoritative" << false
- << "noConnectionVersioning" << true << "version"
- << Timestamp(chunkVersion.toLong()) << "versionEpoch"
- << chunkVersion.epoch() << "versionTimestamp"
- << chunkVersion.getTimestamp()));
-}
-
-TEST(SetShardVersionRequest, ToSSVCommandFullAuthoritative) {
- const ChunkVersion chunkVersion(1, 2, OID::gen(), Timestamp(1, 1));
-
- SetShardVersionRequest ssv(NamespaceString("db.coll"), chunkVersion, true);
-
- ASSERT(!ssv.shouldForceRefresh());
- ASSERT(ssv.isAuthoritative());
- ASSERT_EQ(ssv.getNS().ns(), "db.coll");
- ASSERT_EQ(ssv.getNSVersion().toString(), chunkVersion.toString());
-
- ASSERT_BSONOBJ_EQ(ssv.toBSON(),
- BSON("setShardVersion"
- << "db.coll"
- << "forceRefresh" << false << "authoritative" << true
- << "noConnectionVersioning" << true << "version"
- << Timestamp(chunkVersion.toLong()) << "versionEpoch"
- << chunkVersion.epoch() << "versionTimestamp"
- << chunkVersion.getTimestamp()));
-}
-
-TEST(SetShardVersionRequest, ToSSVCommandFullForceRefresh) {
- const ChunkVersion chunkVersion(1, 2, OID::gen(), Timestamp(1, 1));
-
- SetShardVersionRequest ssv(NamespaceString("db.coll"), chunkVersion, false, true);
-
- ASSERT(ssv.shouldForceRefresh());
- ASSERT(!ssv.isAuthoritative());
- ASSERT_EQ(ssv.getNS().ns(), "db.coll");
- ASSERT_EQ(ssv.getNSVersion().toString(), chunkVersion.toString());
-
- ASSERT_BSONOBJ_EQ(ssv.toBSON(),
- BSON("setShardVersion"
- << "db.coll"
- << "forceRefresh" << true << "authoritative" << false
- << "noConnectionVersioning" << true << "version"
- << Timestamp(chunkVersion.toLong()) << "versionEpoch"
- << chunkVersion.epoch() << "versionTimestamp"
- << chunkVersion.getTimestamp()));
-}
-
} // namespace
} // namespace mongo