summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2022-04-14 08:08:19 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-15 08:17:25 +0000
commit2fd48fab86439f6e29dedd6042cab1a6e7f3a1ff (patch)
tree4628a7aec5dd33daf8968952669dba7637a5c5cd
parentad3b2e8eca1595d94fb096c4348f61b320ea4716 (diff)
downloadmongo-2fd48fab86439f6e29dedd6042cab1a6e7f3a1ff.tar.gz
SERVER-65328 MigrationSourceManager must reject bounds with outdated shard key patterns
(cherry picked from commit 1d3a714051b9e50fe48bf6e53ed9d063ee13caed)
-rw-r--r--src/mongo/db/s/migration_source_manager.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp
index 147e29284ef..72791d7d7a0 100644
--- a/src/mongo/db/s/migration_source_manager.cpp
+++ b/src/mongo/db/s/migration_source_manager.cpp
@@ -254,6 +254,39 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* opCtx,
<< " because the shard doesn't contain any chunks",
shardVersion.majorVersion() > 0);
+ const auto& keyPattern = collectionMetadata.getKeyPattern();
+ const bool validBounds = [&]() {
+ // Return true if provided bounds are respecting the shard key format, false otherwise
+ const auto nFields = keyPattern.nFields();
+ if (nFields != _args.getMinKey().nFields() || nFields != _args.getMaxKey().nFields()) {
+ return false;
+ }
+
+ BSONObjIterator keyPatternIt(keyPattern), minIt(_args.getMinKey()),
+ maxIt(_args.getMaxKey());
+
+ while (keyPatternIt.more()) {
+ const auto keyPatternField = keyPatternIt.next().fieldNameStringData();
+ const auto minField = minIt.next().fieldNameStringData();
+ const auto maxField = maxIt.next().fieldNameStringData();
+
+ if (keyPatternField != minField || keyPatternField != maxField) {
+ return false;
+ }
+ }
+
+ return true;
+ }();
+ uassert(StaleConfigInfo(_args.getNss(),
+ ChunkVersion::IGNORED() /* receivedVersion */,
+ shardVersion /* wantedVersion */,
+ shardId,
+ boost::none),
+ str::stream() << "Range bounds do not match the shard key pattern. KeyPattern: "
+ << keyPattern.toString() << " - Bounds: "
+ << ChunkRange(_args.getMinKey(), _args.getMaxKey()).toString() << ".",
+ validBounds);
+
ChunkType existingChunk;
uassert(StaleConfigInfo(_args.getNss(),
ChunkVersion::IGNORED() /* receivedVersion */,
@@ -264,6 +297,7 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* opCtx,
<< ChunkRange(_args.getMinKey(), _args.getMaxKey()).toString()
<< " is not owned by this shard.",
collectionMetadata.getNextChunk(_args.getMinKey(), &existingChunk));
+
uassert(StaleConfigInfo(_args.getNss(),
ChunkVersion::IGNORED() /* receivedVersion */,
shardVersion /* wantedVersion */,