0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/sharding/version2.js
Randolph Tan 7915e212dc SERVER-11256 improve handling of empty vs nonexistent CollectionMetadata
Remove long constructor for ChunkVersion
2014-06-06 10:31:49 -04:00

65 lines
2.7 KiB
JavaScript

// version2.js
s = new ShardingTest( "version2" , 1 , 2 )
s.adminCommand( { enablesharding : "alleyinsider" } );
s.adminCommand( { shardcollection : "alleyinsider.foo" , key : { num : 1 } } );
s.adminCommand( { shardcollection : "alleyinsider.bar" , key : { num : 1 } } );
a = s._connections[0].getDB( "admin" );
// setup from one client
assert.eq( a.runCommand( { "getShardVersion" : "alleyinsider.foo" , configdb : s._configDB } ).mine.i, 0 );
assert.eq( a.runCommand( { "getShardVersion" : "alleyinsider.foo" , configdb : s._configDB } ).global.i, 0 );
var fooEpoch = s.getDB('config').chunks.findOne({ ns: 'alleyinsider.foo' }).lastmodEpoch;
assert( a.runCommand({ setShardVersion: "alleyinsider.foo",
configdb: s._configDB,
authoritative: true,
version: new Timestamp(1, 0),
versionEpoch: fooEpoch,
shard: "shard0000",
shardHost: "localhost:30000" }).ok == 1 );
printjson( s.config.chunks.findOne() );
assert.eq( a.runCommand( { "getShardVersion" : "alleyinsider.foo" , configdb : s._configDB } ).mine.t, 1 );
assert.eq( a.runCommand( { "getShardVersion" : "alleyinsider.foo" , configdb : s._configDB } ).global.t, 1 );
// from another client
a2 = connect( s._connections[0].name + "/admin" );
assert.eq( a2.runCommand( { "getShardVersion" : "alleyinsider.foo" , configdb : s._configDB } ).global.t , 1 , "a2 global 1" );
assert.eq( a2.runCommand( { "getShardVersion" : "alleyinsider.foo" , configdb : s._configDB } ).mine.i , 0 , "a2 mine 1" );
function simpleFindOne(){
return a2.getMongo().getDB( "alleyinsider" ).foo.findOne();
}
var barEpoch = s.getDB('config').chunks.findOne({ ns: 'alleyinsider.bar' }).lastmodEpoch;
assert.commandWorked( a2.runCommand({ setShardVersion: "alleyinsider.bar",
configdb: s._configDB,
version: new Timestamp(1, 0),
versionEpoch: barEpoch,
authoritative: true }),
"setShardVersion bar temp" );
assert.throws( simpleFindOne , [] , "should complain about not in sharded mode 1" );
// the only way that setSharVersion passes is if the shard agrees with the version
// the shard takes its version from config directly
// TODO bump timestamps in config
// assert( a2.runCommand( { "setShardVersion" : "alleyinsider.foo" , configdb : s._configDB , version : 2 } ).ok == 1 , "setShardVersion a2-1");
// simpleFindOne(); // now should run ok
// assert( a2.runCommand( { "setShardVersion" : "alleyinsider.foo" , configdb : s._configDB , version : 3 } ).ok == 1 , "setShardVersion a2-2");
// simpleFindOne(); // newer version is ok
s.stop();