diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2021-06-27 16:11:50 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-29 08:49:59 +0000 |
commit | eb23662b184243252347fabf99d7b1b9924743d0 (patch) | |
tree | e980940b9e4a13de2561fb0540157aa4054c19b2 /src | |
parent | 7f79e08ee7a6184d6367730f93345c14c4cff1a3 (diff) | |
download | mongo-eb23662b184243252347fabf99d7b1b9924743d0.tar.gz |
SERVER-58109 Make shardChunksInRangeQuery satisfiable from the index only
(cherry picked from commit ab8a0797f06940df4240a39f05e0bfdcc4c59481)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp | 20 |
1 files changed, 9 insertions, 11 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 eb24df90173..4da04122002 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 @@ -468,14 +468,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkSplit( BSONObjBuilder b; b.append("ns", ChunkType::ConfigNS.ns()); b.append("q", - BSON("query" << BSON(ChunkType::ns(nss.ns()) << ChunkType::min() << range.getMin() - << ChunkType::max() << range.getMax()) + BSON("query" << BSON(ChunkType::ns(nss.ns()) << ChunkType::min(range.getMin()) + << ChunkType::max(range.getMax())) << "orderby" << BSON(ChunkType::lastmod() << -1))); - { - BSONObjBuilder bb(b.subobjStart("res")); - bb.append(ChunkType::epoch(), requestEpoch); - bb.append(ChunkType::shard(), shardName); - } + b.append("res", BSON(ChunkType::epoch(requestEpoch) << ChunkType::shard(shardName))); preCond.append(b.obj()); } @@ -540,6 +536,8 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMerge( // This method must never be called with empty chunks to merge invariant(!chunkBoundaries.empty()); + const auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard(); + // Take _kChunkOpLock in exclusive mode to prevent concurrent chunk splits, merges, and // migrations // TODO(SERVER-25359): Replace with a collection-specific lock map to allow splits/merges/ @@ -553,7 +551,7 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMerge( // Get the max chunk version for this namespace. auto swCollVersion = getMaxChunkVersionFromQueryResponse( nss, - Grid::get(opCtx)->shardRegistry()->getConfigShard()->exhaustiveFindOnConfig( + configShard->exhaustiveFindOnConfig( opCtx, ReadPreferenceSetting{ReadPreference::PrimaryOnly}, repl::ReadConcernLevel::kLocalReadConcern, @@ -578,7 +576,7 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMerge( // Get the shard version (max chunk version) for the shard requesting the merge. auto swShardVersion = getMaxChunkVersionFromQueryResponse( nss, - Grid::get(opCtx)->shardRegistry()->getConfigShard()->exhaustiveFindOnConfig( + configShard->exhaustiveFindOnConfig( opCtx, ReadPreferenceSetting{ReadPreference::PrimaryOnly}, repl::ReadConcernLevel::kLocalReadConcern, @@ -767,10 +765,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunksMerge( // 2. Retrieve the list of chunks belonging to the requested shard + key range. const auto shardChunksInRangeQuery = [&]() { BSONObjBuilder queryBuilder; - queryBuilder << ChunkType::epoch(coll.getEpoch()); + queryBuilder << ChunkType::ns(coll.getNs().ns()); queryBuilder << ChunkType::shard(shardId.toString()); queryBuilder << ChunkType::min(BSON("$gte" << chunkRange.getMin())); - queryBuilder << ChunkType::max(BSON("$lte" << chunkRange.getMax())); + queryBuilder << ChunkType::min(BSON("$lt" << chunkRange.getMax())); return queryBuilder.obj(); }(); |