summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllison Easton <allison.easton@mongodb.com>2022-02-25 08:53:17 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-25 09:20:25 +0000
commit4e9556f41551a5f46b4cca21952b2e092c9a3404 (patch)
treeef121ffec26c6717db6edb61e02ce74e988b30e2
parent1284ff6c5580d59423ccc59a4f33f172d604bbc4 (diff)
downloadmongo-4e9556f41551a5f46b4cca21952b2e092c9a3404.tar.gz
SERVER-63726 Defragmentation should be tested on a single collection as well as on multiple collections
-rw-r--r--jstests/sharding/defragment_large_collection.js88
1 files changed, 45 insertions, 43 deletions
diff --git a/jstests/sharding/defragment_large_collection.js b/jstests/sharding/defragment_large_collection.js
index 12ce30040c4..b14539a70b7 100644
--- a/jstests/sharding/defragment_large_collection.js
+++ b/jstests/sharding/defragment_large_collection.js
@@ -16,73 +16,75 @@ Random.setRandomSeed();
// Test parameters
const numShards = Random.randInt(7) + 1;
-const numCollections = 3;
const maxChunkFillMB = 20;
const maxChunkSizeMB = 30;
const chunkSpacing = 1000;
-jsTest.log("Creating new test with " + numCollections + " collections over " + numShards +
- " shards.");
+jsTest.log("Creating new sharding test with " + numShards + " shards.");
const st = new ShardingTest({
mongos: 1,
shards: numShards,
other: {
- enableBalancer: false,
+ enableBalancer: true,
configOptions: {setParameter: {logComponentVerbosity: tojson({sharding: {verbosity: 3}})}},
}
});
-// setup the database for the test
-assert.commandWorked(st.s.adminCommand({enableSharding: 'db'}));
-const db = st.getDB('db');
-const coll_prefix = "testColl_";
+let runTest = function(numCollections, dbName) {
+ jsTest.log("Running test with " + numCollections + " collections.");
+ // setup the database for the test
+ assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
+ const db = st.getDB(dbName);
+ const coll_prefix = "testColl_";
-let collections = [];
+ let collections = [];
-for (let i = 0; i < numCollections; ++i) {
- const numChunks = Random.randInt(28) + 2;
- const numZones = Random.randInt(numChunks / 2);
- const docSizeBytes = Random.randInt(1024 * 1024) + 50;
+ for (let i = 0; i < numCollections; ++i) {
+ const numChunks = Random.randInt(28) + 2;
+ const numZones = Random.randInt(numChunks / 2);
+ const docSizeBytes = Random.randInt(1024 * 1024) + 50;
- const coll = db[coll_prefix + i];
+ const coll = db[coll_prefix + i];
- defragmentationUtil.createFragmentedCollection(st.s,
- coll.getFullName(),
- numChunks,
- maxChunkFillMB,
- numZones,
- docSizeBytes,
- chunkSpacing,
- true);
+ defragmentationUtil.createFragmentedCollection(st.s,
+ coll.getFullName(),
+ numChunks,
+ maxChunkFillMB,
+ numZones,
+ docSizeBytes,
+ chunkSpacing,
+ true);
- collections.push(coll);
-}
+ collections.push(coll);
+ }
-st.printShardingStatus();
+ st.printShardingStatus();
-collections.forEach((coll) => {
- assert.commandWorked(st.s.adminCommand({
- configureCollectionBalancing: coll.getFullName(),
- defragmentCollection: true,
- chunkSize: maxChunkSizeMB,
- }));
-});
+ collections.forEach((coll) => {
+ assert.commandWorked(st.s.adminCommand({
+ configureCollectionBalancing: coll.getFullName(),
+ defragmentCollection: true,
+ chunkSize: maxChunkSizeMB,
+ }));
+ });
-st.startBalancer();
+ collections.forEach((coll) => {
+ const ns = coll.getFullName();
-collections.forEach((coll) => {
- const ns = coll.getFullName();
+ // Wait for defragmentation to end and check collection final state
+ defragmentationUtil.waitForEndOfDefragmentation(st.s, ns);
+ const finalNumberChunks = findChunksUtil.countChunksForNs(st.s.getDB('config'), ns);
+ jsTest.log("Finished defragmentation of collection " + coll + " with " + finalNumberChunks +
+ " chunks.");
+ defragmentationUtil.checkPostDefragmentationState(st.s, ns, maxChunkSizeMB, "key");
+ });
- // Wait for defragmentation to end and check collection final state
- defragmentationUtil.waitForEndOfDefragmentation(st.s, ns);
- const finalNumberChunks = findChunksUtil.countChunksForNs(st.s.getDB('config'), ns);
- jsTest.log("Finished defragmentation of collection " + coll + " with " + finalNumberChunks +
- " chunks.");
- defragmentationUtil.checkPostDefragmentationState(st.s, ns, maxChunkSizeMB, "key");
-});
+ st.printShardingStatus();
+};
-st.printShardingStatus();
+runTest(1, "singleCollection");
+runTest(3, "threeCollections");
st.stop();
})();