diff options
Diffstat (limited to 'jstests/sharding/bulk_shard_insert.js')
-rw-r--r-- | jstests/sharding/bulk_shard_insert.js | 128 |
1 files changed, 63 insertions, 65 deletions
diff --git a/jstests/sharding/bulk_shard_insert.js b/jstests/sharding/bulk_shard_insert.js index 6db6a62c998..4f3a4626818 100644 --- a/jstests/sharding/bulk_shard_insert.js +++ b/jstests/sharding/bulk_shard_insert.js @@ -7,94 +7,92 @@ * @tags: [resource_intensive] */ (function() { - 'use strict'; +'use strict'; - var st = new ShardingTest({shards: 4, chunkSize: 1}); +var st = new ShardingTest({shards: 4, chunkSize: 1}); - assert.commandWorked(st.s0.adminCommand({enableSharding: 'TestDB'})); - st.ensurePrimaryShard('TestDB', st.shard0.shardName); - assert.commandWorked( - st.s0.adminCommand({shardCollection: 'TestDB.TestColl', key: {Counter: 1}})); +assert.commandWorked(st.s0.adminCommand({enableSharding: 'TestDB'})); +st.ensurePrimaryShard('TestDB', st.shard0.shardName); +assert.commandWorked(st.s0.adminCommand({shardCollection: 'TestDB.TestColl', key: {Counter: 1}})); - var db = st.s0.getDB('TestDB'); - var coll = db.TestColl; +var db = st.s0.getDB('TestDB'); +var coll = db.TestColl; - // Insert lots of bulk documents - var numDocs = 1000000; +// Insert lots of bulk documents +var numDocs = 1000000; - var bulkSize = 4000; - var docSize = 128; /* bytes */ - print("\n\n\nBulk size is " + bulkSize); +var bulkSize = 4000; +var docSize = 128; /* bytes */ +print("\n\n\nBulk size is " + bulkSize); - var data = "x"; - while (Object.bsonsize({x: data}) < docSize) { - data += data; - } +var data = "x"; +while (Object.bsonsize({x: data}) < docSize) { + data += data; +} - print("\n\n\nDocument size is " + Object.bsonsize({x: data})); +print("\n\n\nDocument size is " + Object.bsonsize({x: data})); - var docsInserted = 0; - var balancerOn = false; +var docsInserted = 0; +var balancerOn = false; - /** - * Ensures that the just inserted documents can be found. - */ - function checkDocuments() { - var docsFound = coll.find({}, {_id: 0, Counter: 1}).toArray(); - var count = coll.find().count(); +/** + * Ensures that the just inserted documents can be found. + */ +function checkDocuments() { + var docsFound = coll.find({}, {_id: 0, Counter: 1}).toArray(); + var count = coll.find().count(); - if (docsFound.length != docsInserted) { - print("Inserted " + docsInserted + " count : " + count + " doc count : " + - docsFound.length); + if (docsFound.length != docsInserted) { + print("Inserted " + docsInserted + " count : " + count + + " doc count : " + docsFound.length); - var allFoundDocsSorted = docsFound.sort(function(a, b) { - return a.Counter - b.Counter; - }); + var allFoundDocsSorted = docsFound.sort(function(a, b) { + return a.Counter - b.Counter; + }); - var missingValueInfo; + var missingValueInfo; - for (var i = 0; i < docsInserted; i++) { - if (i != allFoundDocsSorted[i].Counter) { - missingValueInfo = {expected: i, actual: allFoundDocsSorted[i].Counter}; - break; - } + for (var i = 0; i < docsInserted; i++) { + if (i != allFoundDocsSorted[i].Counter) { + missingValueInfo = {expected: i, actual: allFoundDocsSorted[i].Counter}; + break; } + } - st.printShardingStatus(); + st.printShardingStatus(); - assert(false, - 'Inserted number of documents does not match the actual: ' + - tojson(missingValueInfo)); - } + assert( + false, + 'Inserted number of documents does not match the actual: ' + tojson(missingValueInfo)); } +} - while (docsInserted < numDocs) { - var currBulkSize = - (numDocs - docsInserted > bulkSize) ? bulkSize : (numDocs - docsInserted); +while (docsInserted < numDocs) { + var currBulkSize = (numDocs - docsInserted > bulkSize) ? bulkSize : (numDocs - docsInserted); - var bulk = []; - for (var i = 0; i < currBulkSize; i++) { - bulk.push({Counter: docsInserted, hi: "there", i: i, x: data}); - docsInserted++; - } + var bulk = []; + for (var i = 0; i < currBulkSize; i++) { + bulk.push({Counter: docsInserted, hi: "there", i: i, x: data}); + docsInserted++; + } - assert.writeOK(coll.insert(bulk)); + assert.writeOK(coll.insert(bulk)); - if (docsInserted % 10000 == 0) { - print("Inserted " + docsInserted + " documents."); - st.printShardingStatus(); - } + if (docsInserted % 10000 == 0) { + print("Inserted " + docsInserted + " documents."); + st.printShardingStatus(); + } - if (docsInserted > numDocs / 3 && !balancerOn) { - // Do one check before we turn balancer on - checkDocuments(); - print('Turning on balancer after ' + docsInserted + ' documents inserted.'); - st.startBalancer(); - balancerOn = true; - } + if (docsInserted > numDocs / 3 && !balancerOn) { + // Do one check before we turn balancer on + checkDocuments(); + print('Turning on balancer after ' + docsInserted + ' documents inserted.'); + st.startBalancer(); + balancerOn = true; } +} - checkDocuments(); +checkDocuments(); - st.stop(); +st.stop(); })(); |