Files
mongo/jstests/sharding/dump_coll_metadata.js
Kaloian Manassiev 9ca37ee188 SERVER-19319 Send setShardVersion command after sharding a collection
The shard collection operation needs to inform the former primary shard
for the database containing this collection that the collection is being
sharded. That way, unsharded operations will be rejected when they come
from mongos instances, which are not yet aware the collection became
sharded.

Also reverts commit 280b8e6c83
("SERVER-19319 Temporarily update some tests to run a query after sharding
a collection to force the version to be set")
2015-07-31 14:33:42 -04:00

55 lines
2.1 KiB
JavaScript

//
// Tests that we can dump collection metadata via getShardVersion()
//
var st = new ShardingTest({ shards : 2, mongos : 1 });
st.stopBalancer();
var mongos = st.s0;
var coll = mongos.getCollection( "foo.bar" );
var admin = mongos.getDB( "admin" );
var shards = mongos.getCollection( "config.shards" ).find().toArray();
var shardAdmin = st.shard0.getDB( "admin" );
assert( admin.runCommand({ enableSharding : coll.getDB() + "" }).ok );
printjson( admin.runCommand({ movePrimary : coll.getDB() + "", to : shards[0]._id }) );
assert( admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } }).ok );
assert( shardAdmin.runCommand({ getShardVersion : coll + "" }).ok );
printjson( shardAdmin.runCommand({ getShardVersion : coll + "", fullMetadata : true }) );
// Make sure we have chunks info
var result =
shardAdmin.runCommand({ getShardVersion : coll + "", fullMetadata : true });
var metadata = result.metadata;
assert.eq( metadata.chunks.length, 1 );
assert.eq( metadata.pending.length, 0 );
assert( metadata.chunks[0][0]._id + "" == MinKey + "" );
assert( metadata.chunks[0][1]._id + "" == MaxKey + "" );
assert( metadata.shardVersion + "" == result.global + "" );
// Make sure a collection with no metadata still returns the metadata field
assert( shardAdmin.runCommand({ getShardVersion : coll + "xyz", fullMetadata : true })
.metadata != undefined );
// Make sure we get multiple chunks after a split
assert( admin.runCommand({ split : coll + "", middle : { _id : 0 } }).ok );
assert( shardAdmin.runCommand({ getShardVersion : coll + "" }).ok );
printjson( shardAdmin.runCommand({ getShardVersion : coll + "", fullMetadata : true }) );
// Make sure we have chunks info
result = shardAdmin.runCommand({ getShardVersion : coll + "", fullMetadata : true });
metadata = result.metadata;
assert.eq( metadata.chunks.length, 2 );
assert.eq( metadata.pending.length, 0 );
assert( metadata.chunks[0][0]._id + "" == MinKey + "" );
assert( metadata.chunks[0][1]._id == 0 );
assert( metadata.chunks[1][0]._id == 0 );
assert( metadata.chunks[1][1]._id + "" == MaxKey + "" );
assert( metadata.shardVersion + "" == result.global + "" );
st.stop();