diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-09-23 15:12:57 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-09-26 12:20:52 -0400 |
commit | e2b8d3da53a06617fa9c0251070bfc31fe38f154 (patch) | |
tree | 94f74a6a70590e5860bea68c28ca9e04b7fade02 /jstests/sharding/bulk_shard_insert.js | |
parent | 9dda827a3ae58beef36d53da1b55554cbd8744c4 (diff) | |
download | mongo-e2b8d3da53a06617fa9c0251070bfc31fe38f154.tar.gz |
SERVER-26327 Extend diagnostics in bulk_shard_insert.js
Diffstat (limited to 'jstests/sharding/bulk_shard_insert.js')
-rw-r--r-- | jstests/sharding/bulk_shard_insert.js | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/jstests/sharding/bulk_shard_insert.js b/jstests/sharding/bulk_shard_insert.js index ae4626b8fdb..81c9fa25dd1 100644 --- a/jstests/sharding/bulk_shard_insert.js +++ b/jstests/sharding/bulk_shard_insert.js @@ -3,20 +3,15 @@ (function() { 'use strict'; - // Setup randomized test - var seed = new Date().getTime(); - // seed = 0 - - Random.srand(seed); - print("Seeded with " + seed); - var st = new ShardingTest({shards: 4, chunkSize: 1}); - // Setup sharded collection - var mongos = st.s0; - var db = mongos.getDB(jsTestName()); - var coll = db.coll; - st.shardColl(coll, {_id: 1}, false); + 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; // Insert lots of bulk documents var numDocs = 1000000; @@ -35,38 +30,63 @@ var docsInserted = 0; var balancerOn = false; + /** + * Ensures that the just inserted documents can be found. + */ + function checkDocuments() { + var count = coll.find().count(); + var itcount = coll.find().itcount(); + + if (itcount != docsInserted) { + print("Inserted " + docsInserted + " count : " + count + " itcount : " + itcount); + + var allFoundDocs = coll.find({}, {_id: 0, Counter: 1}).toArray().sort(function(a, b) { + return a.Counter - b.Counter; + }); + + var missingValueInfo; + + for (var i = 0; i < docsInserted; i++) { + if (i != allFoundDocs[i].Counter) { + missingValueInfo = {expected: i, actual: allFoundDocs[i].Counter}; + break; + } + } + + st.printShardingStatus(); + + assert(false, + 'Inserted number of documents does not match the actual: ' + + tojson(missingValueInfo)); + } + } + while (docsInserted < numDocs) { var currBulkSize = (numDocs - docsInserted > bulkSize) ? bulkSize : (numDocs - docsInserted); var bulk = []; for (var i = 0; i < currBulkSize; i++) { - bulk.push({hi: "there", at: docsInserted, i: i, x: data}); + bulk.push({Counter: docsInserted, hi: "there", i: i, x: data}); + docsInserted++; } assert.writeOK(coll.insert(bulk)); - if (Math.floor(docsInserted / 10000) != Math.floor((docsInserted + currBulkSize) / 10000)) { - print("Inserted " + (docsInserted + currBulkSize) + " documents."); + if (docsInserted % 10000 == 0) { + print("Inserted " + docsInserted + " documents."); + checkDocuments(); st.printShardingStatus(); } - docsInserted += currBulkSize; - - if (docsInserted > numDocs / 2 && !balancerOn) { - print("Turning on balancer after half documents inserted."); + if (docsInserted > numDocs / 3 && !balancerOn) { + print('Turning on balancer after ' + docsInserted + ' documents inserted.'); st.startBalancer(); balancerOn = true; } } - // Check we inserted all the documents - st.printShardingStatus(); - - var count = coll.find().count(); - var itcount = coll.find().itcount(); - print("Inserted " + docsInserted + " count : " + count + " itcount : " + itcount); - assert.eq(docsInserted, itcount); + checkDocuments(); st.stop(); })(); |