summaryrefslogtreecommitdiff
path: root/jstests/sharding/libs/defragmentation_util.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/sharding/libs/defragmentation_util.js')
-rw-r--r--jstests/sharding/libs/defragmentation_util.js26
1 files changed, 9 insertions, 17 deletions
diff --git a/jstests/sharding/libs/defragmentation_util.js b/jstests/sharding/libs/defragmentation_util.js
index 943f2eb462d..52ac1333ef7 100644
--- a/jstests/sharding/libs/defragmentation_util.js
+++ b/jstests/sharding/libs/defragmentation_util.js
@@ -21,9 +21,7 @@ var defragmentationUtil = (function() {
}
createAndDistributeChunks(mongos, ns, numChunks, chunkSpacing);
- // Created zones will line up exactly with existing chunks so as not to trigger zone
- // violations in the balancer.
- createRandomZones(mongos, ns, numZones);
+ createRandomZones(mongos, ns, numZones, chunkSpacing);
fillChunksToRandomSize(mongos, ns, docSizeBytes, maxChunkFillMB);
const beginningNumberChunks = findChunksUtil.countChunksForNs(mongos.getDB('config'), ns);
@@ -51,18 +49,19 @@ var defragmentationUtil = (function() {
}
};
- let createRandomZones = function(mongos, ns, numZones) {
- let existingChunks = findChunksUtil.findChunksByNs(mongos.getDB('config'), ns);
- existingChunks = Array.shuffle(existingChunks.toArray());
- for (let i = 0; i < numZones; i++) {
+ let createRandomZones = function(mongos, ns, numZones, chunkSpacing) {
+ for (let i = -Math.floor(numZones / 2); i < Math.ceil(numZones / 2); i++) {
let zoneName = "Zone" + i;
- let shardForZone = existingChunks[i].shard;
+ let shardForZone =
+ findChunksUtil
+ .findOneChunkByNs(mongos.getDB('config'), ns, {min: {key: i * chunkSpacing}})
+ .shard;
assert.commandWorked(
mongos.adminCommand({addShardToZone: shardForZone, zone: zoneName}));
assert.commandWorked(mongos.adminCommand({
updateZoneKeyRange: ns,
- min: existingChunks[i].min,
- max: existingChunks[i].max,
+ min: {key: i * chunkSpacing},
+ max: {key: i * chunkSpacing + chunkSpacing},
zone: zoneName
}));
}
@@ -203,13 +202,6 @@ var defragmentationUtil = (function() {
assert.soon(function() {
let balancerStatus =
assert.commandWorked(mongos.adminCommand({balancerCollectionStatus: ns}));
-
- if (balancerStatus.balancerCompliant) {
- // As we can't rely on `balancerCompliant` due to orphan counter non atomic update,
- // we need to ensure the collection is balanced by some extra checks
- sh.awaitCollectionBalance(mongos.getCollection(ns));
- }
-
return balancerStatus.balancerCompliant ||
balancerStatus.firstComplianceViolation !== 'defragmentingChunks';
});