diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-01-06 15:43:57 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-01-07 14:41:20 -0500 |
commit | 7f6f5f4248e22857749382b72527581346d6b6fc (patch) | |
tree | 4fc95b073c42800a66bba7a7172345e6eb6651d9 | |
parent | eb140e730ffdcf99f26d9f215dd4391b8978acc9 (diff) | |
download | mongo-7f6f5f4248e22857749382b72527581346d6b6fc.tar.gz |
SERVER-22079 Make sharding_rs1.js more compact
-rw-r--r-- | jstests/noPassthroughWithMongod/sharding_rs1.js | 90 | ||||
-rw-r--r-- | jstests/sharding/listDatabases.js | 4 | ||||
-rw-r--r-- | jstests/sharding/sharding_rs1.js | 60 |
3 files changed, 64 insertions, 90 deletions
diff --git a/jstests/noPassthroughWithMongod/sharding_rs1.js b/jstests/noPassthroughWithMongod/sharding_rs1.js deleted file mode 100644 index c85fa2a8e54..00000000000 --- a/jstests/noPassthroughWithMongod/sharding_rs1.js +++ /dev/null @@ -1,90 +0,0 @@ -// tests sharding with replica sets - -var s = new ShardingTest({ shards: 3, - other: { rs: true , chunkSize: 1, enableBalancer: true }}); - -s.adminCommand( { enablesharding : "test" } ); -s.ensurePrimaryShard('test', 'test-rs0'); -s.config.settings.update( { _id: "balancer" }, { $set : { _waitForDelete : true } } , true ); - -s.config.settings.find().forEach( printjson ) - -db = s.getDB( "test" ); - -bigString = "" -while ( bigString.length < 10000 ) - bigString += "asdasdasdasdadasdasdasdasdasdasdasdasda"; - -inserted = 0; -num = 0; - -while ( inserted < ( 20 * 1024 * 1024 ) ){ - var bulk = db.foo.initializeUnorderedBulkOp(); - for (var i = 0; i < 100; i ++) { - bulk.insert({ _id: num++, s: bigString, x: Math.random() }); - inserted += bigString.length; - } - assert.writeOK(bulk.execute({w: 3})); -} - -s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } ); -assert.lt( 20 , s.config.chunks.count() , "setup2" ); - -function diff1(){ - var x = s.chunkCounts( "foo" ); - var total = 0; - var min = 1000000000; - var max = 0; - for ( var sn in x ){ - total += x[sn]; - if ( x[sn] < min ) - min = x[sn]; - if ( x[sn] > max ) - max = x[sn]; - } - - print( tojson(x) + " total: " + total + " min: " + min + " max: " + max ) - return max - min; -} - -assert.lt( 20 , diff1() , "big differential here" ); -print( diff1() ) - -{ - // quick test for SERVER-2686 - var mydbs = db.getMongo().getDBs().databases; - for ( var i=0; i<mydbs.length; i++ ) { - assert( mydbs[i].name != "local" , "mongos listDatabases can't return local" ); - } -} - - -assert.soon( function(){ - var d = diff1(); - return d < 5; -} , "balance didn't happen" , 1000 * 60 * 6 , 5000 ); - -jsTest.log("Stopping balancer"); -s.stopBalancer(); - -jsTest.log("Balancer stopped, checking dbhashes"); -for ( i=0; i<s._rs.length; i++ ){ - r = s._rs[i]; - r.test.awaitReplication(); - x = r.test.getHashes( "test" ); - print( r.url + "\t" + tojson( x ) ) - for ( j=0; j<x.slaves.length; j++ ) - assert.eq( x.master.md5 , x.slaves[j].md5 , "hashes not same for: " + r.url + " slave: " + j ); -} - - -assert.eq( num , db.foo.find().count() , "C1" ) -assert.eq( num , db.foo.find().itcount() , "C2" ) -assert.eq( num , db.foo.find().sort( { _id : 1 } ).itcount() , "C3" ) -assert.eq( num , db.foo.find().sort( { _id : -1 } ).itcount() , "C4" ) -db.foo.ensureIndex( { x : 1 } ) -assert.eq( num , db.foo.find().sort( { x : 1 } ).itcount() , "C5" ) -assert.eq( num , db.foo.find().sort( { x : -1 } ).itcount() , "C6" ) - - -s.stop() diff --git a/jstests/sharding/listDatabases.js b/jstests/sharding/listDatabases.js index f0c23fd8ef7..998791acbd0 100644 --- a/jstests/sharding/listDatabases.js +++ b/jstests/sharding/listDatabases.js @@ -34,6 +34,10 @@ dbInConfigEntryCheck(getDBSection(dbArray, "config")); var adminSection = getDBSection(dbArray, 'admin'); assert(!adminSection); +// Local database should never be returned +var localSection = getDBSection(dbArray, 'local'); +assert(!localSection); + // add doc in admin db on the config server. mongos.getDB('admin').test.insert({ _id: 1 }); res = mongos.adminCommand("listDatabases"); diff --git a/jstests/sharding/sharding_rs1.js b/jstests/sharding/sharding_rs1.js new file mode 100644 index 00000000000..353f9c532cc --- /dev/null +++ b/jstests/sharding/sharding_rs1.js @@ -0,0 +1,60 @@ +// tests sharding with replica sets +(function() { +'use strict'; + +var s = new ShardingTest({ shards: 3, + other: { rs: true, chunkSize: 1, enableBalancer: true }}); + +s.adminCommand( { enablesharding : "test" } ); +s.ensurePrimaryShard('test', 'test-rs0'); +s.config.settings.update( { _id: "balancer" }, { $set : { _waitForDelete : true } } , true ); + +var db = s.getDB("test"); + +var bigString = "X".repeat(256 * 1024); + +var insertedBytes = 0; +var num = 0; + +// Insert 10 MB of data to result in 10+ chunks +var bulk = db.foo.initializeUnorderedBulkOp(); +while (insertedBytes < (10 * 1024 * 1024)) { + bulk.insert({ _id: num++, s: bigString, x: Math.random() }); + insertedBytes += bigString.length; +} +assert.writeOK(bulk.execute({w: 3})); + +assert.commandWorked(s.s.adminCommand({ shardcollection: "test.foo" , key: { _id: 1 } })); + +jsTest.log("Waiting for balance to complete"); +s.awaitBalance('foo', 'test', 2 * 60 * 1000); + +jsTest.log("Stopping balancer"); +s.stopBalancer(); + +jsTest.log("Balancer stopped, checking dbhashes"); +s._rs.forEach(function(rsNode) { + rsNode.test.awaitReplication(); + + var dbHashes = rsNode.test.getHashes("test"); + print(rsNode.url + ': ' + tojson(dbHashes)); + + for (var j = 0; j < dbHashes.slaves.length; j++) { + assert.eq(dbHashes.master.md5, + dbHashes.slaves[j].md5, + "hashes not same for: " + rsNode.url + " slave: " + j); + } +}); + +assert.eq( num , db.foo.find().count() , "C1" ) +assert.eq( num , db.foo.find().itcount() , "C2" ) +assert.eq( num , db.foo.find().sort( { _id : 1 } ).itcount() , "C3" ) +assert.eq( num , db.foo.find().sort( { _id : -1 } ).itcount() , "C4" ) + +db.foo.ensureIndex( { x : 1 } ); +assert.eq( num , db.foo.find().sort( { x : 1 } ).itcount() , "C5" ) +assert.eq( num , db.foo.find().sort( { x : -1 } ).itcount() , "C6" ) + +s.stop(); + +})(); |