summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2021-05-07 15:47:23 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-13 06:17:18 +0000
commit3cca88dff1b3ec2eb3dcda6eb8a4627c76566850 (patch)
tree202d2230db3d37383934125122bfccee5f0b8eab
parenta696566eae01ed989738f36e396ef2ec3949728c (diff)
downloadmongo-3cca88dff1b3ec2eb3dcda6eb8a4627c76566850.tar.gz
SERVER-56515 Make mergeChunks consider the 'incrementChunkMajorVersionOnChunkSplits' parameter
(cherry picked from commit 9261befabc2f3e922eec0f15e091e9881deb1960)
-rw-r--r--jstests/sharding/major_version_check.js13
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp46
2 files changed, 49 insertions, 10 deletions
diff --git a/jstests/sharding/major_version_check.js b/jstests/sharding/major_version_check.js
index 0a55fdc8702..549b92ea47f 100644
--- a/jstests/sharding/major_version_check.js
+++ b/jstests/sharding/major_version_check.js
@@ -4,8 +4,7 @@
(function() {
'use strict';
-// Test with default value of incrementChunkMajorVersionOnChunkSplits, which is
-// false>
+// Test with default value of incrementChunkMajorVersionOnChunkSplits, which is false
(() => {
var st = new ShardingTest({shards: 1, mongos: 2});
@@ -51,6 +50,11 @@
assert.eq(Timestamp(1, 0),
staleMongos.getDB("admin").runCommand({getShardVersion: coll + ""}).version);
+ // Merge the just-split chunks and ensure the major version didn't go up
+ assert.commandWorked(
+ admin.runCommand({mergeChunks: coll + "", bounds: [{_id: MinKey}, {_id: MaxKey}]}));
+ assert.eq(Timestamp(1, 3), admin.runCommand({getShardVersion: coll + ""}).version);
+
st.stop();
})();
@@ -124,6 +128,11 @@
assert.eq(Timestamp(2, 2),
staleMongos.getDB("admin").runCommand({getShardVersion: coll + ""}).version);
+ // Merge the just-split chunks and ensure the major version went up
+ assert.commandWorked(
+ admin.runCommand({mergeChunks: coll + "", bounds: [{_id: MinKey}, {_id: MaxKey}]}));
+ assert.eq(Timestamp(3, 0), admin.runCommand({getShardVersion: coll + ""}).version);
+
st.stop();
})();
})();
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 83d3eafb10f..f07c54d6341 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
@@ -357,12 +357,12 @@ Status ShardingCatalogManager::commitChunkSplit(OperationContext* opCtx,
ChunkVersion currentMaxVersion = collVersion;
- // If the incrementChunkMajorVersionOnChunkSplits flag is set, increment
- // the major version only if the shard that owns the chunk being split has
- // version == collection version. See SERVER-41480 for details.
+ // If the incrementChunkMajorVersionOnChunkSplits flag is set, increment the major version only
+ // if the shard that owns the chunk being split has shardVersion == collectionVersion. See
+ // SERVER-41480 for details.
//
- // This flag is only useful if there are some 4.0 routers still in the
- // cluster, so we only use it if FCV is not fully upgraded.
+ // This flag is only useful if there are some 4.0 routers still in the cluster, so we only use
+ // it if FCV is not fully upgraded.
const auto currentFCV = serverGlobalParams.featureCompatibility.getVersion();
if (currentFCV != ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42 &&
incrementChunkMajorVersionOnChunkSplits.load() && shardVersion == collVersion) {
@@ -558,8 +558,7 @@ Status ShardingCatalogManager::commitChunkMerge(OperationContext* opCtx,
1)); // Limit 1.
if (!swCollVersion.isOK()) {
- return swCollVersion.getStatus().withContext(str::stream()
- << "mergeChunk cannot merge chunks.");
+ return swCollVersion.getStatus().withContext("mergeChunk cannot merge chunks.");
}
auto collVersion = swCollVersion.getValue();
@@ -571,6 +570,25 @@ Status ShardingCatalogManager::commitChunkMerge(OperationContext* opCtx,
"that the collection was dropped and re-created."};
}
+ // Get the shard version (max chunk version) for the shard requesting the merge.
+ auto swShardVersion = getMaxChunkVersionFromQueryResponse(
+ nss,
+ Grid::get(opCtx)->shardRegistry()->getConfigShard()->exhaustiveFindOnConfig(
+ opCtx,
+ ReadPreferenceSetting{ReadPreference::PrimaryOnly},
+ repl::ReadConcernLevel::kLocalReadConcern,
+ ChunkType::ConfigNS,
+ BSON("ns" << nss.ns() << "shard"
+ << shardName), // Query all chunks for this namespace and shard.
+ BSON(ChunkType::lastmod << -1), // Sort by version.
+ 1)); // Limit 1.
+
+ if (!swShardVersion.isOK()) {
+ return swShardVersion.getStatus().withContext("mergeChunk cannot merge chunks.");
+ }
+
+ auto shardVersion = swShardVersion.getValue();
+
// Build chunks to be merged
std::vector<ChunkType> chunksToMerge;
@@ -608,7 +626,19 @@ Status ShardingCatalogManager::commitChunkMerge(OperationContext* opCtx,
}
ChunkVersion mergeVersion = collVersion;
- mergeVersion.incMinor();
+ // If the incrementChunkMajorVersionOnChunkSplits flag is set, increment the major version only
+ // if the shard that owns the chunks being merged has shardVersion == collectionVersion. See
+ // SERVER-41480 for details.
+ //
+ // This flag is only useful if there are some 4.0 routers still in the cluster, so we only use
+ // it if FCV is not fully upgraded.
+ const auto currentFCV = serverGlobalParams.featureCompatibility.getVersion();
+ if (currentFCV != ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42 &&
+ incrementChunkMajorVersionOnChunkSplits.load() && shardVersion == collVersion) {
+ mergeVersion.incMajor();
+ } else {
+ mergeVersion.incMinor();
+ }
auto updates = buildMergeChunksTransactionUpdates(chunksToMerge, mergeVersion, validAfter);
auto preCond = buildMergeChunksTransactionPrecond(chunksToMerge, collVersion);