summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2021-06-27 15:52:22 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-29 09:12:20 +0000
commit5dbf53cee78762abf139fe837caa896b019d2c44 (patch)
tree2f879cd5d8296d859879ad111e1fa5e12598b73b
parent09ccd55b9805b42e26228f2170670f071083e583 (diff)
downloadmongo-5dbf53cee78762abf139fe837caa896b019d2c44.tar.gz
SERVER-58109 Make shardChunksInRangeQuery satisfiable from the index only
(cherry picked from commit eb23662b184243252347fabf99d7b1b9924743d0)
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp26
1 files changed, 11 insertions, 15 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 e3526fb3607..c5e703e8129 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
@@ -484,16 +484,11 @@ 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());
}
@@ -526,7 +521,7 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkSplit(
Grid::get(opCtx)
->catalogClient()
->logChange(opCtx, "split", nss.ns(), logDetail.obj(), WriteConcernOptions())
- .transitional_ignore();
+ .ignore();
} else {
BSONObj beforeDetailObj = logDetail.obj();
BSONObj firstDetailObj = beforeDetailObj.getOwned();
@@ -543,7 +538,7 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkSplit(
->catalogClient()
->logChange(
opCtx, "multi-split", nss.ns(), chunkDetail.obj(), WriteConcernOptions())
- .transitional_ignore();
+ .ignore();
}
}
@@ -562,6 +557,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/
@@ -577,7 +574,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,
@@ -602,7 +599,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,
@@ -711,7 +708,6 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunksMerge(
const ChunkRange& chunkRange,
const ShardId& shardId,
const boost::optional<Timestamp>& validAfter) {
-
const auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
// Take _kChunkOpLock in exclusive mode to prevent concurrent chunk splits, merges, and
@@ -795,10 +791,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();
}();