diff options
author | Pierlauro Sciarelli <pierlauro.sciarelli@mongodb.com> | 2022-04-14 08:08:19 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-15 08:17:25 +0000 |
commit | 2fd48fab86439f6e29dedd6042cab1a6e7f3a1ff (patch) | |
tree | 4628a7aec5dd33daf8968952669dba7637a5c5cd | |
parent | ad3b2e8eca1595d94fb096c4348f61b320ea4716 (diff) | |
download | mongo-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.cpp | 34 |
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 */, |