diff options
author | Pierlauro Sciarelli <pierlauro.sciarelli@mongodb.com> | 2022-11-30 14:10:41 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-30 22:15:28 +0000 |
commit | 63d6350c8a31bc8a317f936ae39f617919d63c2f (patch) | |
tree | 430ecb86405871b99a7d076cf45e03af8b0b439c | |
parent | e62af19b574822b1f0b379b4b6e0653765f7f765 (diff) | |
download | mongo-63d6350c8a31bc8a317f936ae39f617919d63c2f.tar.gz |
SERVER-71666 Reduce number of scanned index entries on chunk migration commit
(cherry picked from commit 591bce59840c8f6e1926b2d5a324eeefbf750336)
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
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 027ca3b5b1d..7722448f02a 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 @@ -94,13 +94,11 @@ StatusWith<ChunkType> findChunkContainingRange(OperationContext* opCtx, const UUID& uuid, const OID& epoch, const Timestamp& timestamp, - const BSONObj& min, - const BSONObj& max) { + const ChunkRange& range) { const auto chunkQuery = [&]() { BSONObjBuilder queryBuilder; queryBuilder << ChunkType::collectionUUID << uuid; - queryBuilder << ChunkType::min(BSON("$lte" << min)); - queryBuilder << ChunkType::max(BSON("$gte" << max)); + queryBuilder << ChunkType::min(BSON("$lte" << range.getMin())); return queryBuilder.obj(); }(); @@ -112,21 +110,26 @@ StatusWith<ChunkType> findChunkContainingRange(OperationContext* opCtx, repl::ReadConcernLevel::kLocalReadConcern, ChunkType::ConfigNS, chunkQuery, - BSONObj(), - 2 /* limit */); + BSON(ChunkType::min << -1), + 1 /* limit */); if (!findResponseWith.isOK()) { return findResponseWith.getStatus(); } - if (findResponseWith.getValue().docs.size() != 1) { - return {ErrorCodes::Error(40165), - str::stream() << "Could not find a chunk including bounds [" << min << ", " << max - << "). Cannot execute the migration commit with invalid chunks."}; + if (!findResponseWith.getValue().docs.empty()) { + const auto containingChunk = uassertStatusOK(ChunkType::parseFromConfigBSON( + findResponseWith.getValue().docs.front(), epoch, timestamp)); + + if (containingChunk.getRange().covers(range)) { + return containingChunk; + } } - return uassertStatusOK( - ChunkType::parseFromConfigBSON(findResponseWith.getValue().docs.front(), epoch, timestamp)); + return {ErrorCodes::Error(40165), + str::stream() << "Could not find a chunk including bounds [" << range.getMin() << ", " + << range.getMax() + << "). Cannot execute the migration commit with invalid chunks."}; } BSONObj buildCountChunksInRangeCommand(const UUID& collectionUUID, @@ -1101,12 +1104,8 @@ ShardingCatalogManager::commitChunkMigration(OperationContext* opCtx, migratedChunk.isVersionSet() && migratedChunk.getVersion().isSet()); // Check if range still exists and which shard owns it - auto swCurrentChunk = findChunkContainingRange(opCtx, - coll.getUuid(), - coll.getEpoch(), - coll.getTimestamp(), - migratedChunk.getMin(), - migratedChunk.getMax()); + auto swCurrentChunk = findChunkContainingRange( + opCtx, coll.getUuid(), coll.getEpoch(), coll.getTimestamp(), migratedChunk.getRange()); if (!swCurrentChunk.isOK()) { return swCurrentChunk.getStatus(); |