From 4e9556f41551a5f46b4cca21952b2e092c9a3404 Mon Sep 17 00:00:00 2001 From: Allison Easton Date: Fri, 25 Feb 2022 08:53:17 +0000 Subject: SERVER-63726 Defragmentation should be tested on a single collection as well as on multiple collections --- jstests/sharding/defragment_large_collection.js | 88 +++++++++++++------------ 1 file 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(); })(); -- cgit v1.2.1