Files
mongo/jstests/sharding/resharding_large_number_of_initial_chunks.js

79 lines
2.6 KiB
JavaScript

/**
* Tests that resharding can complete successfully when the original collection has a large number
* of chunks.
*
* @tags: [
* uses_atclustertime,
* resource_intensive,
* exclude_from_large_txns
* ]
*/
(function() {
"use strict";
load("jstests/sharding/libs/find_chunks_util.js");
const st = new ShardingTest({
mongos: 1,
shards: 2,
config: 1,
other: {
configOptions: {
setParameter:
{reshardingCriticalSectionTimeoutMillis: 24 * 60 * 60 * 1000 /* 1 day */}
}
}
});
const kDbName = 'db';
const collName = 'foo';
const ns = kDbName + '.' + collName;
const mongos = st.s;
assert.commandWorked(mongos.adminCommand({enableSharding: kDbName}));
assert.commandWorked(mongos.adminCommand({shardCollection: ns, key: {oldKey: 1}}));
let nZones = 175000;
let zones = [];
let shard0Zones = [];
let shard1Zones = [];
for (let i = 0; i < nZones; i++) {
let zoneName = "zone" + i;
zones.push({zone: zoneName, min: {"newKey": i}, max: {"newKey": i + 1}});
if (i % 2 == 0) {
shard0Zones.push(zoneName);
} else {
shard1Zones.push(zoneName);
}
}
jsTestLog("Updating First Zone");
assert.commandWorked(
mongos.getDB("config").shards.update({_id: st.shard0.shardName}, {$set: {tags: shard0Zones}}));
jsTestLog("Updating First Zone");
assert.commandWorked(
mongos.getDB("config").shards.update({_id: st.shard1.shardName}, {$set: {tags: shard1Zones}}));
jsTestLog("Resharding Collection");
assert.commandWorked(mongos.adminCommand({reshardCollection: ns, key: {newKey: 1}, zones: zones}));
// Assert that the correct number of zones and chunks documents exist after resharding 'db.foo'.
// There should be two more chunks docs than zones docs created to cover the ranges
// {newKey: minKey -> newKey : 0} and {newKey: nZones -> newKey : maxKey} which are not associated
// with a zone.
assert.eq(mongos.getDB("config").tags.find({ns: ns}).itcount(), nZones);
assert.eq(findChunksUtil.countChunksForNs(mongos.getDB("config"), ns), nZones + 2);
// check_orphans_are_deleted.js is skipped because it takes 1 minute to run on an optimized build
// and this test doesn't insert any data for there to be unowned documents anyway.
TestData.skipCheckOrphans = true;
// check_uuids_consistent_across_cluster.js is skipped because it takes nearly 1 minute to run on an
// optimized build.
TestData.skipCheckingUUIDsConsistentAcrossCluster = true;
// check_routing_table_consistency.js is skipped because its $group + $lookup aggregation over the
// config.chunks documents exceeds 100MB and fails.
TestData.skipCheckRoutingTableConsistency = true;
st.stop();
})();