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:19:11 +0000 |
commit | 91e38b0d70a70ad770393c8565d75c5f561de7a7 (patch) | |
tree | b6e6247035fd978c579d354d3896ff9ddf152f14 | |
parent | 0784db07f2675986be279504d493d9969b1311c0 (diff) | |
download | mongo-91e38b0d70a70ad770393c8565d75c5f561de7a7.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 9857a8aaf3a..5b4d1dcc59d 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 @@ -166,13 +166,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(); }(); @@ -184,21 +182,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 makeCommitChunkTransactionCommand(const NamespaceString& nss, @@ -1054,12 +1057,8 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration( 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(); |