diff options
Diffstat (limited to 'jstests/sharding/coll_epoch_test2.js')
-rw-r--r-- | jstests/sharding/coll_epoch_test2.js | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/jstests/sharding/coll_epoch_test2.js b/jstests/sharding/coll_epoch_test2.js index c76cf51266f..09109ebce43 100644 --- a/jstests/sharding/coll_epoch_test2.js +++ b/jstests/sharding/coll_epoch_test2.js @@ -4,61 +4,61 @@ // operation on a mongos may be active when it happens. All operations should handle gracefully. // -var st = new ShardingTest({ shards : 2, mongos : 5, verbose : 1 }) +var st = new ShardingTest({ shards : 2, mongos : 5, verbose : 1 }); // Balancer is by default stopped, thus it will not interfere // Use separate mongos for reading, updating, inserting, removing data -var readMongos = st.s1 -var updateMongos = st.s2 -var insertMongos = st.s3 -var removeMongos = st.s4 +var readMongos = st.s1; +var updateMongos = st.s2; +var insertMongos = st.s3; +var removeMongos = st.s4; -var config = st.s.getDB( "config" ) -var admin = st.s.getDB( "admin" ) -var coll = st.s.getCollection( "foo.bar" ) +var config = st.s.getDB( "config" ); +var admin = st.s.getDB( "admin" ); +var coll = st.s.getCollection( "foo.bar" ); -insertMongos.getDB( "admin" ).runCommand({ setParameter : 1, traceExceptions : true }) +insertMongos.getDB( "admin" ).runCommand({ setParameter : 1, traceExceptions : true }); -var shards = {} +var shards = {}; config.shards.find().forEach( function( doc ){ - shards[ doc._id ] = new Mongo( doc.host ) -}) + shards[ doc._id ] = new Mongo( doc.host ); +}); // // Set up a sharded collection // -jsTest.log( "Enabling sharding for the first time..." ) +jsTest.log( "Enabling sharding for the first time..." ); -admin.runCommand({ enableSharding : coll.getDB() + "" }) +admin.runCommand({ enableSharding : coll.getDB() + "" }); st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001'); -admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } }) +admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } }); assert.writeOK(coll.insert({ hello : "world" })); -jsTest.log( "Sharding collection across multiple shards..." ) +jsTest.log( "Sharding collection across multiple shards..." ); var getOtherShard = function( shard ){ for( id in shards ){ - if( id != shard ) return id + if( id != shard ) return id; } -} +}; -printjson( admin.runCommand({ split : coll + "", middle : { _id : 0 } }) ) +printjson( admin.runCommand({ split : coll + "", middle : { _id : 0 } }) ); printjson( admin.runCommand({ moveChunk : coll + "", find : { _id : 0 }, - to : getOtherShard( config.databases.findOne({ _id : coll.getDB() + "" }).primary ) }) ) + to : getOtherShard( config.databases.findOne({ _id : coll.getDB() + "" }).primary ) }) ); -st.printShardingStatus() +st.printShardingStatus(); // // Force all mongoses to load the current status of the cluster // -jsTest.log( "Loading this status in all mongoses..." ) +jsTest.log( "Loading this status in all mongoses..." ); for( var i = 0; i < st._mongos.length; i++ ){ - printjson( st._mongos[i].getDB( "admin" ).runCommand({ flushRouterConfig : 1 }) ) - assert.neq( null, st._mongos[i].getCollection( coll + "" ).findOne() ) + printjson( st._mongos[i].getDB( "admin" ).runCommand({ flushRouterConfig : 1 }) ); + assert.neq( null, st._mongos[i].getCollection( coll + "" ).findOne() ); } // @@ -66,9 +66,9 @@ for( var i = 0; i < st._mongos.length; i++ ){ // versions are the same, but the split is at a different point. // -jsTest.log( "Rebuilding sharded collection with different split..." ) +jsTest.log( "Rebuilding sharded collection with different split..." ); -coll.drop() +coll.drop(); var droppedCollDoc = config.collections.findOne({ _id: coll.getFullName() }); assert(droppedCollDoc != null); @@ -77,46 +77,46 @@ assert(droppedCollDoc.lastmodEpoch != null); assert(droppedCollDoc.lastmodEpoch.equals(new ObjectId("000000000000000000000000")), "epoch not zero: " + droppedCollDoc.lastmodEpoch); -admin.runCommand({ enableSharding : coll.getDB() + "" }) +admin.runCommand({ enableSharding : coll.getDB() + "" }); st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001'); -admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } }) +admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } }); var bulk = coll.initializeUnorderedBulkOp(); for( var i = 0; i < 100; i++ ) bulk.insert({ _id : i }); assert.writeOK(bulk.execute()); -printjson( admin.runCommand({ split : coll + "", middle : { _id : 200 } }) ) +printjson( admin.runCommand({ split : coll + "", middle : { _id : 200 } }) ); printjson( admin.runCommand({ moveChunk : coll + "", find : { _id : 200 }, - to : getOtherShard( config.databases.findOne({ _id : coll.getDB() + "" }).primary ) }) ) + to : getOtherShard( config.databases.findOne({ _id : coll.getDB() + "" }).primary ) }) ); // // Make sure all operations on mongoses aren't tricked by the change // -jsTest.log( "Checking other mongoses for detection of change..." ) +jsTest.log( "Checking other mongoses for detection of change..." ); -jsTest.log( "Checking find..." ) +jsTest.log( "Checking find..." ); // Ensure that finding an element works when resharding -assert.neq( null, readMongos.getCollection( coll + "" ).findOne({ _id : 1 }) ) +assert.neq( null, readMongos.getCollection( coll + "" ).findOne({ _id : 1 }) ); -jsTest.log( "Checking update...") +jsTest.log( "Checking update..."); // Ensure that updating an element finds the right location assert.writeOK(updateMongos.getCollection( coll + "" ).update({ _id : 1 }, { $set : { updated : true } })); -assert.neq( null, coll.findOne({ updated : true }) ) +assert.neq( null, coll.findOne({ updated : true }) ); -jsTest.log( "Checking insert..." ) +jsTest.log( "Checking insert..." ); // Ensure that inserting an element finds the right shard assert.writeOK(insertMongos.getCollection( coll + "" ).insert({ _id : 101 })); -assert.neq( null, coll.findOne({ _id : 101 }) ) +assert.neq( null, coll.findOne({ _id : 101 }) ); -jsTest.log( "Checking remove..." ) +jsTest.log( "Checking remove..." ); // Ensure that removing an element finds the right shard, verified by the mongos doing the sharding assert.writeOK(removeMongos.getCollection( coll + "" ).remove({ _id : 2 })); -assert.eq( null, coll.findOne({ _id : 2 }) ) +assert.eq( null, coll.findOne({ _id : 2 }) ); -coll.drop() +coll.drop(); -jsTest.log( "Done!" ) +jsTest.log( "Done!" ); -st.stop() +st.stop(); |